Reputation: 925
Hi im using amplify dynamodb table and at for client side using DataStore AppSync. After performing amplify push command, im getting this error in graphql SyncTable call of DataStore.
Value for field '$[lastSync]' must be a number
Upvotes: 2
Views: 418
Reputation: 1060
I encountered the same problem. After some investigation I found there is a bug in Amplify generated resolvers.
In line 103 of every "Query.syncXXXX.preAuth.1.req.vtl" generated by amplify (which you may find under /amplify/backend/api/[your project name]/build/resolvers)
## [Start] Set query expression for @key **
#if( !$scan )
#set( $limit = $util.defaultIfNull($context.args.limit, 100) )
#set( $QueryRequest = {
"version": "2018-05-29",
"operation": "Sync",
"limit": $limit,
"lastSync": $util.toJson($util.defaultIfNull($ctx.args.lastSync, null)),
"query": $modelQueryExpression
} )
The "lastSync" field is filled with string typed value because of the unnecessary call of "$util.toJson". This is the exact cause of your error message "$[lastSync] must be a number"
A workaround to the problem is to change:
"lastSync": $util.toJson($util.defaultIfNull($ctx.args.lastSync, null)),
into
"lastSync": $util.defaultIfNull($ctx.args.lastSync, null),
and then override the generated resolver
see Override Amplify-generated resolvers
Upvotes: 2