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.

Mutation refetchQueries has only effect if useQuery is rendered at the same time

See original GitHub issue

Heyo, I’ve created a CodeSandbox to showcase this:

Edit react-apollo-hook-cache-bug-reproductoin

In this example, if you click on “both”, put something in the form and submit it, the list updates instantly. (As I would expect it to)

But if you click on the “form”-Button, so only the form, but not the list is rendered, then fill & submit the form and then go back to the “list” view, the list is still in the old state, which means the getList query seems not to have updated.

Funny enough, when using the evaluated graphql (passing the GET_LIST constant) instead of the string getList, it seems to update. But in that case, I have to provide all variables - and if the form does not know, which variables are used in a query in a different component, that means it is impossible to trigger the query from the form.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
phryneascommented, Apr 11, 2019

Seriously? This has three views, because two views are required to show off the bug and one is required to show that there are conditions the bug does not happen. It consists of two components (that could be straight out of the readme of this lib), a query, a mutation and one “App” to switch between the views.

What do you want to simplify there?

3reactions
SeanRobertscommented, Apr 4, 2019

Just ran into this same issue. Switched from using useMutation and useQuery to the <Mutation /> and <Query /> and it solved the problem, so I think @phryneas is correct that either the issue lies within react-apollo-hooks, or else react-apollo is doing its own work to paper over the issue in apollo-client.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mutations in Apollo Client - Apollo GraphQL Docs
Unlike useQuery , useMutation doesn't execute its operation automatically on render. Instead, you call this mutate function. An object with fields that ...
Read more >
Why react useQuery() doesnt fetch the newest data after a ...
Your mutation modifies data on the server side. Once your mutation is done, you should refetch your data in order to get the...
Read more >
Refetching Queries after Mutations - Thinkster.io
then() of a promise. The other way to update data after a mutation is using the Apollo cache, and we'll cover that in...
Read more >
React Query, Solid Query, Svelte Query, Vue Query - TanStack
It handles caching, background updates and stale data out of the box with ... up with dedicated devtools, infinite-loading APIs, and first class...
Read more >
@tannerlinsley/react-query-temp - npm
React Query contains a set of hooks that attempt to address these issues ... behavior of hooks like useQuery and useMutation used within...
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