Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Network error: Error writing result to store for query (Apollo Client)

I am using Apollo Client to make an application to query my server using Graphql. I have a python server on which I execute my graphql queries which fetches data from the database and then returns it back to the client.

I have created a custom NetworkInterface for the client that helps me to make make customized server request (by default ApolloClient makes a POST call to the URL we specify). The network interface only has to have a query() method wherein we return the promise for the result of form Promise<ExecutionResult>.

I am able to make the server call and fetch the requested data but still getting the following error.

Error: Network error: Error writing result to store for query  {    query something{       row{          data       }    } } Cannot read property 'row' of undefined     at new ApolloError (ApolloError.js:32)     at ObservableQuery.currentResult (ObservableQuery.js:76)     at GraphQL.dataForChild (react-apollo.browser.umd.js:410)     at GraphQL.render (react-apollo.browser.umd.js:448)     at ReactCompositeComponent.js:796     at measureLifeCyclePerf (ReactCompositeComponent.js:75)     at ReactCompositeComponentWrapper._renderValidatedComponentWithoutOwnerOrContext (ReactCompositeComponent.js:795)     at ReactCompositeComponentWrapper._renderValidatedComponent (ReactCompositeComponent.js:822)     at ReactCompositeComponentWrapper._updateRenderedComponent (ReactCompositeComponent.js:746)     at ReactCompositeComponentWrapper._performComponentUpdate (ReactCompositeComponent.js:724)     at ReactCompositeComponentWrapper.updateComponent (ReactCompositeComponent.js:645)     at ReactCompositeComponentWrapper.performUpdateIfNecessary (ReactCompositeComponent.js:561)     at Object.performUpdateIfNecessary (ReactReconciler.js:157)     at runBatchedUpdates (ReactUpdates.js:150)     at ReactReconcileTransaction.perform (Transaction.js:140)     at ReactUpdatesFlushTransaction.perform (Transaction.js:140)     at ReactUpdatesFlushTransaction.perform (ReactUpdates.js:89)     at Object.flushBatchedUpdates (ReactUpdates.js:172)     at ReactDefaultBatchingStrategyTransaction.closeAll (Transaction.js:206)     at ReactDefaultBatchingStrategyTransaction.perform (Transaction.js:153)     at Object.batchedUpdates (ReactDefaultBatchingStrategy.js:62)     at Object.enqueueUpdate (ReactUpdates.js:200) 

I want to know the possible cause of the error and solution if possible.

like image 566
return007 Avatar asked Jun 07 '17 05:06

return007


People also ask

How do you handle errors in Apollo GraphQL?

By default, Apollo Client throws away partial data and populates the error. graphQLErrors array of your useQuery call (or whichever hook you're using). You can instead use these partial results by defining an error policy for your operation. If the response includes GraphQL errors, they are returned on error.

How do you send an error response in GraphQL?

To add errors to your data, you need to use the Union type (a.k.a. Result ) in your GraphQL schema. Also, the logic in the resolver is rewritten so that next to the result or error for the operation you also need to return a type for it.

How do I disable Apollo Client cache?

To disable normalization for a type, define a TypePolicy for the type (as shown in Customizing cache IDs) and set the policy's keyFields field to false . Objects that are not normalized are instead embedded within their parent object in the cache.

Does Apollo cache errors?

Apollo will pull data from the cache, but not errors. error ends up being undefined. Create a query that results in an error and data. Navigate away from component and then back and notice that the data will get pulled from cache, but errors will not.


2 Answers

I had a similar error. I worked it out by adding id to query. for example, my current query was

query  {   service:me {     productServices {       id       title     }   } } 

my new query was

query  {   service:me {     id // <-------     productServices {       id       title     }   } } 
like image 102
ibamboo Avatar answered Oct 08 '22 09:10

ibamboo


we need to include id, otherwise it will cause the mentioned error.

{    query something {       id       row {          id          data       }    } } 
like image 28
imdzeeshan Avatar answered Oct 08 '22 09:10

imdzeeshan