awslabs / aws-mobile-appsync-sdk-js

JavaScript library files for Offline, Sync, Sigv4. includes support for React Native
Apache License 2.0
921 stars 266 forks source link

without disableOffline:true graphql operations failing with error in readFromStore #343

Open attilah opened 5 years ago

attilah commented 5 years ago

I've an AppSync application which is configured to use Cognito.

When I'm configuring the AppSyncClient without the disableOffline: true option I am ending up with this error upon executing any query:

  graphQLErrors: [],
  networkError:
   Error: Can't find field listKiosks on object undefined.
       at /project/node_modules/aws-appsync/node_modules/apollo-cache-inmemory/src/readFromStore.ts:233:15
       at Array.forEach (<anonymous>)
       at StoreReader.diffQueryAgainstStore (/project/node_modules/aws-appsync/node_modules/apollo-cache-inmemory/src/readFromStore.ts:231:26)
       at StoreReader.readQueryFromStore (/project/node_modules/aws-appsync/node_modules/apollo-cache-inmemory/src/readFromStore.ts:178:17)
       at processOfflineQuery (/project/node_modules/aws-appsync/lib/link/offline-link.js:158:34)
       at /project/node_modules/aws-appsync/lib/link/offline-link.js:114:28
       at new Subscription (/project/node_modules/zen-observable/lib/Observable.js:183:34)
       at Observable.subscribe (/project/node_modules/zen-observable/lib/Observable.js:262:14)
       at /project/node_modules/aws-appsync/lib/client.js:175:67,

If was quite hard to figure out that disableOffline is needed to make this work.

I don't know what is the expected behavior:

  1. Shall it work with offline capabilities in a node application (not necessarily from Lambda only)?

or

  1. We could provide a better error message that under node this functionality is not available and if node environment detected, then bail out with a friendly error message during client initialization?
stephankaag commented 5 years ago

I ran into the same issue and came down to the same questions that you asked. Anyone here who can respond?

attilah commented 5 years ago

@stephankaag perhaps it was not clear, but specifying disableOffline: true works like a charm.

stephankaag commented 5 years ago

@stephankaag perhaps it was not clear, but specifying disableOffline: true works like a charm.

I know but I don't want disable offline functionalities.

manueliglesias commented 5 years ago

Hi @attilah , @stephankaag

Are you using the sdk in Node.js/lambda ?

stephankaag commented 5 years ago

In my case next.js

brandomorrill commented 5 years ago

This feels related to issue 102

mikeRChambers610 commented 4 years ago

@attilah this is a solution that works like a charm if you do not need offline capabilities...