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 thenextToken
field
To Reproduce Steps to reproduce the behavior:
- Make new graphql type with
@model
and@searchable
directive amplify push
it- Add several records to your DynamoDB
- 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
- 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
- fix(graphql-elasticsearch-transformer): fixed es req template changed from to search_after to act as cursor when 'paginating' between results fix #800 — committed to SwaySway/amplify-cli by SwaySway 5 years ago
- fix(graphql-elasticsearch-transformer): changed stringtypes to numtypes Changed logic to not append '.keyword' if the scalar type is not serialized into a string #800 — committed to SwaySway/amplify-cli by SwaySway 5 years ago
- style(graphql-mapping-template): added comma added comma to search_after field if nextToken exists #800 — committed to SwaySway/amplify-cli by SwaySway 5 years ago
- test(graphql-transformers-e2e-tests): added nexttoken test added a test which appends keyword if the scalar type is serialized to a string and paginagates through results using search_after #800 — committed to SwaySway/amplify-cli by SwaySway 5 years ago
- refactor(graphql-elasticsearch-transformer): refactored resolver refactored resolver from numberfields to nonkeywordfields re #800 re #2080 — committed to SwaySway/amplify-cli by SwaySway 5 years ago
- fix(graphql-elasticsearch-transformer): changed nonKeyword types (#2090) * fix(graphql-elasticsearch-transformer): changed non keyword types change the numberTypes to nonKeyword type as there can ... — committed to aws-amplify/amplify-cli by SwaySway 5 years ago
@SwaySway I’m still getting nextToken
$entry.sort.get(0)
- is that expected? Did this get merged yet? I am running latestamplify-cli
andamplify-js
.