next-with-apollo: Can't find field X on object undefined

Hi all,

I’m getting this error when using next-with-apollo in this project here.

I’m using the Query component rather than the graphql function.

GraphQL error occurred [getDataFromTree] { Error: Network error: Can't find field getCategories on object undefined.
    at new ApolloError (/home/egidio/Workspace/youvector/website/node_modules/apollo-client/bundle.umd.js:85:32)
    at /home/egidio/Workspace/youvector/website/node_modules/apollo-client/bundle.umd.js:1039:45
    at /home/egidio/Workspace/youvector/website/node_modules/apollo-client/bundle.umd.js:1411:21
    at Array.forEach (<anonymous>)
    at /home/egidio/Workspace/youvector/website/node_modules/apollo-client/bundle.umd.js:1410:22
    at Map.forEach (<anonymous>)
    at QueryManager.broadcastQueries (/home/egidio/Workspace/youvector/website/node_modules/apollo-client/bundle.umd.js:1405:26)
    at /home/egidio/Workspace/youvector/website/node_modules/apollo-client/bundle.umd.js:988:35
  graphQLErrors: [],
  networkError:
   Error: Can't find field getCategories on object undefined.
       at /home/egidio/Workspace/youvector/website/node_modules/aws-appsync/node_modules/apollo-cache-inmemory/lib/bundle.umd.js:429:27
       at Array.forEach (<anonymous>)
       at StoreReader.diffQueryAgainstStore (/home/egidio/Workspace/youvector/website/node_modules/aws-appsync/node_modules/apollo-cache-inmemory/lib/bundle.umd.js:426:36)
       at StoreReader.readQueryFromStore (/home/egidio/Workspace/youvector/website/node_modules/aws-appsync/node_modules/apollo-cache-inmemory/lib/bundle.umd.js:401:25)
       at processOfflineQuery (/home/egidio/Workspace/youvector/website/node_modules/aws-appsync/lib/link/offline-link.js:158:34)
       at /home/egidio/Workspace/youvector/website/node_modules/aws-appsync/lib/link/offline-link.js:114:28
       at new Subscription (/home/egidio/Workspace/youvector/website/node_modules/zen-observable/lib/Observable.js:183:34)
       at Observable.subscribe (/home/egidio/Workspace/youvector/website/node_modules/zen-observable/lib/Observable.js:262:14)
       at /home/egidio/Workspace/youvector/website/node_modules/aws-appsync/lib/client.js:175:67,
  message:
   "Network error: Can't find field getCategories on object undefined.",
  extraInfo: undefined }

That error is server-side. Data is fetched correctly on client-side. Is that the expected behaviour?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (8 by maintainers)

Most upvoted comments

Yes, even so, don’t take the chance of having a memory leak.

Amazing, good work 👍 💃

Well, this is what you’re missing: https://github.com/dabit3/next-apollo-appsync/blob/master/src/initApollo.js#L16

I can make a example that works for you, let me finish my breakfast first

Is that everything you are able to see ? I think that the issue may be with trying to do the request in the server with aws-appsync, I don’t think that it just works out of the box without any special configuration for SSR, can you go to their docs and confirm that ?

because gql will transform the query into an AST, it’s not something to be done every render because it takes time, and it should be done once. If you do a console log of data in the query response, do you see undefined ?

Can you move the query out of the component and try again ? it should not be there btw