AppSync VTL resolver - how to resolve parse error

122 Views Asked by At

I'm getting this error on my VTL response mapping and I'm not sure what it means

graphql: Encountered "}" at velocity[line 9, column 3]
                                Was expecting one of:
                                    "[" ...
                                    "{" ...
                                    <STRING_LITERAL> ...
                                    "true" ...
                                    "false" ...
                                    <INTEGER_LITERAL> ...
                                    <FLOATING_POINT_LITERAL> ...
                                    <IDENTIFIER> ...
                                    "{" ...
                                    "[" ...

For the following response mapping:

#set($isAdmin = $ctx.identity.resolverContext.is_admin)

#if(!$isAdmin)
  $util.toJson({
    "availability": {
      "startsAt": $ctx.result.availability.startsAt,
      "endsAt": $ctx.result.availability.endsAt,
    }
  })
#end

$util.toJson($ctx.result)
1

There are 1 best solutions below

0
cyberwombat On BEST ANSWER

Remove the end comma in your object:

#set($isAdmin = $ctx.identity.resolverContext.is_admin)

#if(!$isAdmin)
  $util.toJson({
    "availability": {
      "startsAt": $ctx.result.availability.startsAt,
      "endsAt": $ctx.result.availability.endsAt
    }
  })
#end

$util.toJson($ctx.result)

Here's a validator to help.