amplify-cli: Transform @searchable directive generate wrong VTL response template

Describe the bug

  • graphql sort variable does not work on autogenerated VTL response template
  • the template also return null for the nextToken field

To Reproduce Steps to reproduce the behavior:

  1. Make new graphql type with @model and @searchable directive
  2. amplify push it
  3. Add several records to your DynamoDB
  4. check VTL response mapping template for the search query
#set( $items = [] )
#foreach( $entry in $context.result.hits.hits )
  #if( !$foreach.hasNext )
    #set( $nextToken = "$entry.sort.get(0)" )
  #end
  $util.qr($items.add($entry.get("_source")))
#end
$util.toJson({
  "items": $items,
  "total": $ctx.result.hits.total,
  "nextToken": $nextToken
})

this value "$entry.sort.get(0)" will return as a string for the nextToken field

  1. try to use sort variable on the graphql query
{
  "filter": {
    "cleanedContent": {
      "regexp": "someText.*"
    }
  },
  "sort": {
    "field": "myField",
    "direction": "desc"
  }
}

you will get this error:

{
  "data": {
    "searchBookEntitys": null
  },
  "errors": [
    {
      "path": [
        "searchBookEntitys"
      ],
      "data": null,
      "errorType": "Elasticsearch:UserIllegalArgumentException",
      "errorInfo": null,
      "locations": [
        {
          "line": 2,
          "column": 3,
          "sourceName": null
        }
      ],
      "message": "Elasticsearch responded with an error: Bad Request"
    }
  ]
}

Expected behavior nextToken and sort variable to functiion properly

Desktop (please complete the following information):

  • macOS
  • amplify cli version multienv.39

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 2
  • Comments: 43 (16 by maintainers)

Commits related to this issue

Most upvoted comments

@SwaySway I’m still getting nextToken $entry.sort.get(0) - is that expected? Did this get merged yet? I am running latest amplify-cli and amplify-js.