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.

`watchQuery` doesn't get the new result after a mutation

See original GitHub issue

I’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:closed
  • Created 7 years ago
  • Comments:16 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
stubailocommented, Jun 12, 2016

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.

1reaction
Poincarecommented, May 24, 2016

Now that we can transform queries to add typenames (as of 0.3.12), we can solve this problem. To add the query transformation:

import { addTypenameToSelectionSet } from 'apollo-client/queries/queryTransform';
const client = new ApolloClient({
  ...
  queryTransformer: addTypenameToSelectionSet,
  ...
});

This adds the __typename field to every SelectionSet within each query and if we add an id field to a query (e.g. when asking for a user’s first and last name, we also ask for an id), the state change within Redux caused by the result of the mutation should lead to updated data.

Read more comments on GitHub >

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

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 Reddit Thread

No results found

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