Handling Apollo Cache
Tools for handling Apollo Cache
evictRootQuery
An entire root query, such as customer or viewerCohortsConnection can be evicted using evictRootQuery. When any page using the cleared query is visited, Apollo will automatically refetch it.
Why use this over refetchQueries?
Using refetchQueries will immediately make a network call to refetch the given query. This is less effective since 1) the query may be used on a page the user is not currently on and 2) more data may yet be changed before the given query is needed, causing the query to be re-fetched multiple times and, pertaining to the first point, may not ever even get used.
evictObject
A particular GraphQL object can also be evicted. The benefit to using this over evictRootQuery, is that clearing a particular object in Apollo cache will effectively mark any query using that object to be re-fetched (next time the component containing the query is loaded).