question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Updating cached data from multiple parameterized queries after a mutation

See original GitHub issue

Appears 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:

  1. I have a mutation that creates/deletes nodes.
  2. I have multiple co-located, parameterized queries that need to re-run when a create/delete mutation happens.
  3. 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.
  4. 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:closed
  • Created 6 years ago
  • Reactions:24
  • Comments:12

github_iconTop GitHub Comments

16reactions
snaumovcommented, Apr 6, 2018

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 with readQuery and writeQuery 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?

10reactions
snaumovcommented, Sep 23, 2018

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found