little-bear-labs / aws-utils

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue with VTL request template

EwanValentine opened this issue · comments

Hi there,

I'm getting the following error when making a GraphQL Query to the appsync emulator.

{ SyntaxError: JSON5: invalid character '$' at 6:17

I narrowed it down to the following request template:

{
    "version" : "2017-02-28",
    "operation": "Invoke",
    "payload": {
    	"body": $util.toJson($context.arguments),
        "tenant": $util.toJson($context.identity.claims['http://tenant'])
    }
}

Specifically, this line "tenant": $util.toJson($context.identity.claims['http://tenant']). This code currently works in production. I can't immediately see anything that might be causing this issue. Although the claims in production are from an OPENID integration with Auth0, could this be the cause?

My request looks like this:

curl -POST --header 'x-api-key: <valid jwt token>'  --url http://localhost:62222/graphql --data '{"operationName":"FetchFiles","variables":{},"query":"query FetchFiles {\n  fetchFiles {\n    name\n    path\n    savedAt\n    createdAt\n    __typename\n  }\n}\n"}' --header 'Content-Type: application/json' -v

Thanks in advance!

I think it's specifically the array-like syntax causing the error: ['http://tenant'], which is supported in AppSync.

Actually, on further inspection, even if I do, say... $util.toJson($context.identity.claims.tenant) - tenant wouldn't be defined in this case. So is the error I'm seeing just a symptom of something being undefined?

Figured this out, it was actually because the token I was using, didn't contain a required field. Sorry for the noise!