What are all the different ways of updating the Apollo InMemoryCache after a mutation? From the docs, I can see:
- Id-based updates which Apollo performs automatically
- Happens for single updates to existing objects only.
- Requires an
idfield which uniquely identifies each object, or the cache must be configured with adataIdFromObjectfunction which provides a unique identifier.
- "Manual" cache updates via update functions
- Required for object creation, deletion, or updates of multiple objects.
- Involves calling
cache.writeQuerywith details including which query should be affected and how the cache should be changed.
- Passing the
refetchQueriesoption to theuseMutationhook- The calling code says which queries should be re-fetched from the API, Apollo does the fetching, and the results replace whatever is in the cache for the given queries.
Are there other ways that I've missed, or have I misunderstood anything about the above methods?
I am confused because I've been reading the code of a project which uses Apollo for all kinds of mutations, including creations and deletions, but I don't see any calls to cache.writeQuery, nor any usage of refetchQueries. How does the cache get updated after creations and deletions without either of those?
In my own limited experience with Apollo, the cache is not automatically updated after an object creation or deletion, not even if I define dataIdFromObject. I have to update the cache myself by writing update functions.
So I'm wondering if there is some secret config I've missed to make Apollo handle it for me.
idor_idfield or you provide a customdataIdFromObjectimplementation. There are ways you can mess up your client configuration, but it's impossible to know exactly what's wrong without seeing the code. You should provide a minimal reproducible example of code where this is not happening, otherwise the answer to this question is simply "no." - Daniel Reardencache.writeQueryorrefetchQueries? - tuff