* 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"]
}
@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
.
```
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
Most helpful comment
Dellybro - this worked for me: