Updating cached data from multiple parameterized queries after a mutation
See original GitHub issueAppears that the 2 related issues https://github.com/apollographql/react-apollo/issues/708 and https://github.com/apollographql/apollo-client/issues/1697 were closed without an efficient solution - so re-opening here as I am having the same issue.
The crux of the problem is this:
- I have a mutation that creates/deletes nodes.
- I have multiple co-located, parameterized queries that need to re-run when a create/delete mutation happens.
- Updating the store manually inside
update
is non-trivial given that all co-located and parameterized queries that were affected by the create/delete mutation need to be re-run. - The variables applied to each parameterized query are applied dynamically and are not easily discoverable or in scope at the
update
call site.
Interested to hear thoughts from the apollo team on an update pattern that fits here.
Thanks!
Issue Analytics
- State:
- Created 6 years ago
- Reactions:24
- Comments:12
Top Results From Across the Web
Mutations in Apollo Client - Apollo GraphQL Docs
Any changes you make to cached data inside of an update function are automatically broadcast to queries that are listening for changes to...
Read more >How to handle cache update after mutation in multiple views?
Let's say I have 3 distinct views in my app all using similar (but not the same) data. All of them are using...
Read more >How to update the Apollo Client's cache after a mutation
The Apollo Client is used to fetch data from any GraphQL server. The client is small, ... Updating more than one query after...
Read more >Update Apollo Cache after a mutation and get instant benefits ...
Write the data back to Apollo cache (also referring to the GET_ITEMS query). After this, Apollo Client will notice that the cache for...
Read more >How to Update the Apollo Cache After a Mutation - YouTube
In this video I discuss the 3 ways to update the Apollo Cache after a mutation.Code: https://github.com/benawad/apollo- cache - update ----If ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The solution with
refetchQueries
works, however, what if we are not to poll the data from a server, but instead write it to cache straight away. It can be done withreadQuery
andwriteQuery
but it’s tricky since you’ll need to provide the exact same variables to the query as in a cache.Is there any way round it?
@SachaG I was able to solve the mentioned problem of not knowing which arguments to use for a cached query here: https://www.apollographql.com/docs/react/advanced/caching.html#connection-directive so, essentially, if the query has
@connection
directive in it, in the cache it’ll be stored without extra arguments.