@apollo/client InMemoryCache for React

Thanks for your comment.

I use mongodb for a datasource in my GraphQL server and cache some of the queries.
I clear them when a mutation occurs.
On the client side, I need to be able to know what to clear from the cache when that happens.

At first I thought that I could simply use cache.evict({ id: "" }) to clear a specific result and use cache.gc() but it didn’t seem to produce the result I needed.

So instead I followed this approach here that I mentioned that also allows me to scale.

On the client side, I listen on a socket connection for a list of queries to clear when a mutation is executed on GraphQL’s side.

// loop through queries and clear the cache for each
forEach(get(cacheEvict, "queries"), fieldName => {
	client.cache.evict({ id: "ROOT_QUERY", fieldName });
});

This is less specific than I want it to be but it works for my use case until I find an even more precise solution that would work better. Since I had no examples to rely upon for complex scenarios, this is the one I came up with.