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.

[network-only] Unwanted query refetch after mutation breaks user experience

See original GitHub issue

To illustrate the problem, here is a very simple example : Using the network-only policy, I fire a todos query to get a list of Todos. Then, I make each item selectable via an update mutation that takes some arguments and returns the updated Todo.

Intended outcome: When firing the update mutation on an item and getting an updated response back, it should just quietly update the corresponding Todo in the cache, and trigger a rerender for the todos query. As it did in Apollo Client 2.

Actual outcome: It does rerender the list, yes. However, it also triggers a complete refetch of todos, which is totally unwanted and considerably damages the user experience.

This is actually a major issue in some of my projects that I have to update for my clients. I just cannot migrate to version 3 and after a bit of research, I found some seemingly related topics (revolving around cache-and-network though) but none of the proposed solutions worked in my case :

How to reproduce the issue:

  • CodeSandbox Link Click on one of the checkboxes, and watch as the first spinner activates under the updated item. This is the loading state of the update mutation. When it finishes, the global spinner on the list activates. This is the loading state of the todos query. Should not happen.

Versions @apollo/client: ^3.3.6 => 3.3.6

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:24
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
mlarchercommented, Feb 4, 2021

It seems indeed that many other issues are related to the one highlighted here. There is a deep issue affecting many users for version after 3.0.2, by triggering unwanted and counterproductive network requests. nextFetchPolicy is a quick patch that won’t cut it in the long run, as using it to set cache-first as recommended in many other issues prevents all future network requests for the query, even legit ones that we would want to have. Please @benjamn give this issue some love, it needs it badly !

1reaction
benjamncommented, Apr 5, 2022

@strblr Thanks to your reproduction, I’m fairly confident this issue can be resolved by updating to @apollo/client@3.6.0-beta.10 or later (for example), thanks to PR #9504 (which applies to all results broadcast from cache updates, not just fetchMore results). Please try running npm i @apollo/client@beta when you have a chance @hampusborgos @marwan38 @mlarcher @cgorrieri! 🙏

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tips and Tricks for working with Apollo Cache - Medium
Apollo provides us a way to latch onto the success of a mutation, so we can bypass refetching and write directly to the...
Read more >
Hooks - Apollo GraphQL Docs
An array (or a function that returns an array) that specifies which queries you want to refetch after the mutation occurs. Each array...
Read more >
@apollo/client | Yarn - Package Manager
Apollo Client is a fully-featured caching GraphQL client with integrations for React, Angular, and more. It allows you to easily build UI components...
Read more >
@apollo/client - Awesome JS
Make queries with a pollInterval respect the no-cache fetch policy, ... [Relevant if you use Apollo Client with React Native] Since Apollo Client...
Read more >
Glossary | Relay
Fragments can be spread into queries, mutations, subscriptions and other fragments. Fragments can be standalone (as in fragment Component_user on User { name...
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