`watchQuery` doesn't get the new result after a mutation
See original GitHub issueI’m experimenting a bit with mutations. I’ve noticed that in the React docs it’s mentioned that it’s a typical pattern to refetch()
data after a mutation succeeded.
However the docs for watchQuery
say that when a mutation happens, watchQuery
will return the updated result automatically.
I first tried this with the regular apollo-client and later with the React integration, but I couldn’t get the UI to update based on a mutation without calling refetch
.
Are there some boundaries for what can be automatically re-fetched based on mutations and what not? I’d also have a repo which shows the issue if that helps.
Issue Analytics
- State:
- Created 7 years ago
- Comments:16 (12 by maintainers)
Top Results From Across the Web
Refetching queries in Apollo Client
To selectively refetch queries outside of a mutation, you instead use the refetchQueries method of ApolloClient , which is documented here. client.
Read more >Apollo cache is not updating after the mutation - vue.js
Here is how I want things to work: After executing mutation I will call query to the server to get the fresh data...
Read more >How to update the Apollo Client's cache after a mutation
After the mutation succeeded, our cache gets updated automatically ... Basically, you should make your mutation results have all of the data ...
Read more >GraphQL Cache Updates Made Easy
A side-effect would be to clear the cache after a mutation, for example logging out of a system. We get a successful response...
Read more >Advanced Topics on Caching – Angular
The no-cache policy does not write to the cache with the response. ... fetchMore can be used to update the result of a...
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 Reddit Thread
No results found
Top 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
Yeah we have a lot of thoughts about how mutation results should work, but as you mentioned it can be quite complex. Hopefully in the next month or so we can provide some solutions.
Now that we can transform queries to add typenames (as of 0.3.12), we can solve this problem. To add the query transformation:
This adds the
__typename
field to every SelectionSet within each query and if we add anid
field to a query (e.g. when asking for a user’s first and last name, we also ask for anid
), the state change within Redux caused by the result of the mutation should lead to updated data.