Having a model with a key as following:
@key(
name: "byOrganization"
fields: ["organizationID"]
queryField: "merchantsByOrganizationID"
)
has generated resource template as following:
## [Start] Set query expression for @key **
#set( $modelQueryExpression = {} )
#if( !$util.isNull($ctx.args.organizationID) )
#set( $modelQueryExpression.expression = "#organizationID = :organizationID" )
#set( $modelQueryExpression.expressionNames = {
"#organizationID": "organizationID"
} )
#set( $modelQueryExpression.expressionValues = {
":organizationID": {
"S": "$ctx.args.organizationID"
}
} )
#end
## [End] Set query expression for @key **
#set( $limit = $util.defaultIfNull($context.args.limit, 10) )
#set( $QueryRequest = {
"version": "2017-02-28",
"operation": "Query",
"limit": $limit,
"query": $modelQueryExpression,
"index": "byOrganization"
} )
#if( !$util.isNull($ctx.args.sortDirection)
&& $ctx.args.sortDirection == "DESC" )
#set( $QueryRequest.scanIndexForward = false )
#else
#set( $QueryRequest.scanIndexForward = true )
#end
#if( $context.args.nextToken ) #set( $QueryRequest.nextToken = $util.toJson($context.args.nextToken) ) #end
#if( $context.args.filter ) #set( $QueryRequest.filter = $util.parseJson("$util.transform.toDynamoDBFilterExpression($ctx.args.filter)") ) #end
$util.toJson($QueryRequest)
Do results in a error when applying a nextToken:
com.amazonaws.deepdish.common.pagination.InvalidPaginationTokenException: Invalid pagination token given.
Amplify CLI Version
4.13.4
Additional context
Applying the fix in #3452 on https://github.com/aws-amplify/amplify-cli/blob/master/packages/graphql-key-transformer/src/KeyTransformer.ts#L850 solves the issue.
I believe #3459 might be the same bug but was closed as fixed.
Count me in on this one, too. Yesh
It seems to work only when we use queries without any specific keys . For example
listJourneys (limit :5,nextToken :"sometoken")
However if we were to use a query such as:
listJourneys (journeyLong : true , limit:5 , nextToken :"sometoken)
then it throws this error . We had the same issue at version 4.13.3 . However, 4.13.4 the issue seems to come up when using list queries on GSI .
Please treat this as urgent as this is a blocker for us.
I updated to 4.13.4 and affirm that @slatemates is correct -- the issue still comes up when querying a @key directly
We released a fix for this with v4.14.1 today.
Seems to work fine after upgrading to v4.14.1. Thanks a lot .
Still getting this error with both v4.14.1 and v4.16.1.
Error message: com.amazonaws.deepdish.common.pagination.InvalidPaginationTokenException: Invalid pagination token given.
Query: queries.svpByDate, { nextToken: this.nextToken, limit: 20, state: 'PUBLIC', sortDirection: order}
Could it be the addition the addition of sortDirection? We're querying on the GSI "state" and the sort index "createdAt". Error message only comes when making a call with the nextToken, so the first query works and returns the first 20 items.
Thanks in advance!
I tried @slatemates solution by removing any specific keys but now I get
Expression block '$[query]' requires an expression, because I am creating a top level query for the secondaryindex using "queryField" which requires an expression (specific key)
Most helpful comment
It seems to work only when we use queries without any specific keys . For example
listJourneys (limit :5,nextToken :"sometoken")
However if we were to use a query such as:
listJourneys (journeyLong : true , limit:5 , nextToken :"sometoken)
then it throws this error . We had the same issue at version 4.13.3 . However, 4.13.4 the issue seems to come up when using list queries on GSI .
Please treat this as urgent as this is a blocker for us.