A few InMemoryCache questions

Hey guys, I’m trying to to understand Apollo Client cache better and could really use your help.

As far as I know, after using useQuery and populating the cache, it gets saved in two ways:
-Inside of the normalized flattened table, in which all the entities are saved with refs from one to another
-As a query, inside the ROOT_QUERY object

With this knowledge, I want to make sure of some things:

  1. When running a query I haven’t run yet, will Apollo try to form this query using data from the normalized table, and only if he can’t manage that, fetch the query from the server?
    Or will it go straight to the server?
  2. After one happens, will Apollo insert the query to ROOT_QUERY and also update the normalized table?
    Are they always updated together?
  3. Are there any more advantages to saving the previously run queries, other then for the order of the data inside of them as it was when the query was first run?
  4. Supposing I returned all the proper fields while running a mutation, will both of the cache sources update? (normalized table and ROOT_QUERY)
  5. Are the active queries deleted when the component that requested them is unmounted?

Thanks in advance,
Ido (new apolloClient enthusiastic :smiley: )

Hey guys! hoping to get a response :slight_smile:

The ROOT_QUERY object references the normalized table, so when one gets updated the other is also automatically updated.

  1. It will try to answer from the cache if possible, but it knows nothing about your graphql API so in some cases it might not be able to piece together a result from the cache even though it looks like all the required data is in there. You can help it to return results from the cache using Cache Redirects
  2. Yeah they are generally always updated together
  3. i don’t understand the question
  4. yes
  5. no
1 Like