question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DataStore generates invalid GQL: unrecognized token '$util' in `syncFoo` query

See original GitHub issue

Describe 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.

image

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:closed
  • Created 3 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
iartemievcommented, Nov 16, 2020

in what way is @searchable incompatible with DataStore?

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 [].

0reactions
github-actions[bot]commented, Nov 30, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to parse the JSON document: Unrecognized token '$util'
$util.dynamodb.toBinary(String data) takes a String as input, but you are passing a Boolean and this is why it fails evaluation.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found