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

I've finally found out what is causing this issue after battling with it in various parts of our app for months. What helped to shed some light on it was switching from apollo-cache-inmemory to apollo-cache-hermes.

I experimented with Hermes hoping to mitigate this ussue, but unfortunately it fails to update the cache the same as apollo-cache-inmemory. What is curious though is that hermes shows a very nice user friendly message, unlike apollo-cache-inmemory. This lead me to a revelation that cache really hits this problem when it's trying to store an object type that is already in the cache with an ID, but the new object type is lacking it. So apollo-cache-inmemory should work fine if you are meticulously consistent when querying your fields. If you omit id field everywhere for a certain object type it will happily work. If you use id field everywhere it will work correctly. Once you mix queries with and without id that's when cache blows up with this horrible error message.

This is not a bug-it's working as intended, it's even documented here: https://www.apollographql.com/docs/react/caching/cache-configuration/#default-identifiers

2020 update: Apollo has since removed this "feature" from the cache, so this error should not be thrown anymore in apollo-client 3 and newer.


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
    }
  }
}

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

{
   query something {
      id
      row {
         id
         data
      }
   }
}