Amplify-cli: AppSync Resolver multiline string

Created on 18 Sep 2019  路  6Comments  路  Source: aws-amplify/amplify-cli

* Which Category is your question related to? *
API

* What AWS Services are you utilizing? *
AppSync

* Provide additional details e.g. code snippets *
I have a simple AppSync request resolver like this, I am finding it hard to maintain long MySQL queries in a single line. I wasn't able to find any solutions for a multiline string in VTL. Is there a standard for handling multiline strings in VTL?

{
  "version": "2018-05-29",
  "statements": ["SELECT this.Post as that, that.Post as this, this.Tag as thatTag, that.Tag as thisTag FROM POST JOIN TAG ON TAG.Post_id = POST.id"]
}
graphql-transformer question

Most helpful comment

Dellybro - this worked for me:

{
    "version": "2018-05-29",
    "statements": [
        $util.toJson($multiline_sql)
    ]
}

All 6 comments

@oste I think your best option is to move the select statement out to a variable, since with VTL you can have multiline strings in #set.

```

set ($statement = "

SELECT
this.Post as that
FROM
POST
")

and then reference the variable from your JSON construct at the second half of the template.

I'm closing the issue, but feel free to reopen it if something new comes up.

I tried that. I was missing $util.escapeJavascript.

This works:

#set ($statement = "
SELECT
    this.Post as that
FROM
    POST
")

{
  "version": "2018-05-29",
  "statements": ["$util.escapeJavaScript($statement)"]
}

Thanks.

This doesn't seem to work for me, even when i use escapeJavasScript any ideas? I get unrecognized escape character

Agreed, even with util.escapeJavaScript, I still get unrecognized escape character

Dellybro - this worked for me:

{
    "version": "2018-05-29",
    "statements": [
        $util.toJson($multiline_sql)
    ]
}

Dellybro - this worked for me:

{
    "version": "2018-05-29",
    "statements": [
        $util.toJson($multiline_sql)
    ]
}

Thank you thank you thank you

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davo301 picture davo301  路  3Comments

nicksmithr picture nicksmithr  路  3Comments

YikSanChan picture YikSanChan  路  3Comments

ReidWeb picture ReidWeb  路  3Comments

darrentarrant picture darrentarrant  路  3Comments