Apollo GraphQl react. How to clear query cache for all variable combinations?

Andy Hansen picture Andy Hansen · May 20, 2017 · Viewed 11.7k times · Source

I am using apollo graphql in my react application. Say I have the following query:

query ListQuery($filter: String!) {
   items(filter: $filter) {
     id
     name
   }
}

This query lets me query a list of items using a filter. Say I used filter string A, and then used filter string B. The cache would now contain two entries: ListQuery(A) and ListQuery(B).

Now let's say I use a mutation to add a new item. How can I remove all the cached queries from the cache? So in this case, I want to remove both ListQuery(A) and ListQuery(B) from the cache.

How can I accomplish this?

Answer

Nitin picture Nitin · Apr 24, 2018

In your case, you can use the apollo's method client.resetStore();

It will clear the previous cache and then load the active queries.