DataStore generates invalid GQL: unrecognized token '$util' in `syncFoo` query
See original GitHub issueDescribe the bug
I have a number of models in my codebase, and I’m using DataStore
in a few places to enable offline editing etc. When my app starts up I see repeated requests to https://{redacted}.appsync-api.eu-west-2.amazonaws.com/graphql
with the following MappingTemplate
error due to a filter
that looks like it’s made it out of a template and into a GraphQL query:
{
"data": { "syncProducts": null },
"errors": [
{
"path": ["syncProducts"],
"data": null,
"errorType": "MappingTemplate",
"errorInfo": null,
"locations": [{ "line": 2, "column": 3, "sourceName": null }],
"message": "Unrecognized token '$util': was expecting ('true', 'false' or 'null')\n at [Source: (String)\"\n\n{\n \"version\": \"2018-05-29\",\n \"operation\": \"Sync\",\n \"limit\": 1000,\n \"nextToken\": null,\n \"lastSync\": 0,\n \"filter\": $util.transform.toDynamoDBFilterExpression($ctx.args.filter)\n }\n\"; line: 9, column: 26]"
}
]
}
The query itself looks like this (again, generated by DataStore as far as I can tell):
{
"query": "query operation($limit: Int, $nextToken: String, $lastSync: AWSTimestamp, $filter: ModelProductsFilterInput) {\n syncProducts(limit: $limit, nextToken: $nextToken, lastSync: $lastSync, filter: $filter) {\n items { REDACTED }\n nextToken\n startedAt\n }\n}\n",
"variables": {
"limit": 1000,
"nextToken": null,
"lastSync": 0,
"filter": null
}
}
To Reproduce
Create a couple of models. My Product
model looks something like this:
type Product
@model
@searchable
@auth(rules: [
{
allow: groups,
groups: ["admins"],
operations: [create, delete, read, update]
}
{
allow: groups,
groups: ["shoppers"],
operations: [read]
}
{
allow: private,
operations: [read]
}
])
@key(name: "productsByState", fields: ["state"], queryField: "productsByState")
{
id: ID!
name: String!
description: String
state: PRODUCT_STATE!
images: [ProductImage]
@connection(keyName: "byProduct", fields: ["id"])
}
All I need to do is configure Amplify to trigger repeated requests to AppSync. I’m not observing or subscribing at this point so it looks like something internal to DataStore.
Expected behavior
I would expect to see no errors in the response from Amplify. I’m not passing in any filters etc. This is some internal code in Amplify and DataStore as far as I can tell.
Code Snippet
Please let me know if this is required.
Screenshots
Chromium DevTools shows the repeated requests to sync two models.
I can see the initiator is some retry logic inside DataStore.
What is Configured?
I have API (GraphQL), Auth, and Analytics configured.
Environment
npm ERR! cb.apply is not a function
npm ERR! A complete log of this run can be found in:
npm ERR! /home/jcf/.npm/_logs/2020-11-12T16_09_12_945Z-debug.log
Install for [ 'envinfo@latest' ] failed with code 1
I have Amplify v3.3.1 in my package.json
. My dev dependencies contains @aws-amplify/cli
v4.29.3.
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (4 by maintainers)
Top GitHub Comments
It’s primarily incompatible because the Elasticsearch response template doesn’t return the
_version
,_lastChangedAt
, and_deleted
fields. You can use@connection
with DataStore, but not with@searchable
.Another thing to check is whether your data in DynamoDB contains any empty lists
[]
. There’s currently a bug in the AppSync service where enabling sync/conflict resolution on an API will cause AppSync to error out when encountering an empty list. The AppSync team is currently working on fixing that. In the meantime, a workaround would be to persist[null]
or['']
instead of[]
.This issue has been automatically locked since there hasn’t been any recent activity after it was closed. Please open a new issue for related bugs.
Looking for a help forum? We recommend joining the Amplify Community Discord server
*-help
channels or Discussions for those types of questions.