Update Query after Mutation

Hello,

I have a Query and a Mutation after user click on an event the code execute the mutation and after that refetch the query. To the query I added :

notifyOnNetworkStatusChange: true,
fetchPolicy: 'cache-and-network', 
nextFetchPolicy: "cache-first" 

I have been noticing the refeth query is not refetching the nested list of objects for example:

customerCart {
      id
      prices {
        grand_total {
          value
          currency
        }
      }

Is refetching the id of the customerCart but not the value of the currency .

I am doing this on React Native. I read some docs here to add the update to the mutation. Also to merge the cache in InMemoryCache but I am not sure if that is the correct aproach.

Admin note: Edited codeblock formatting

You should be updating your local cache if you want speed. Otherwise, you could refetch your query or use a subscription.

Sounds like you got it to work, so to me you’re fine; I would update the local cache unless I for some reason didn’t trust the client to represent the data accurately.

For cached data like this, the client should not be considered authoritative; the server is the source of truth. Updating the cache just makes the UI show what should be in the server, because the client just got the current state from the mutation.

If you have a mutation like updateCart: Cart you should be fine to replace the existing cart, because the server just updated it. If you have something like updateCart: { success: boolean } then you might want to change your schema to instead give you the updated cart.

1 Like