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.

QueryResult.fetchMore() triggers unexpected refetch of indirectly related "cache-and-network" queries

See original GitHub issue

Intended outcome: When I call query.fetchMore() I expect this to never affect other queries or cause the other queries to be refetched.

Actual outcome:

When I call query.fetchMore() it sometimes causes a refetch of some “cache-and-network” query on the page.

It seems to happen when both queries (the one for which we call query.fetchMore() and the one that uses fetchPolicy: "cache-and-network") request data inside a common object type (e.g. __typename: "User").

How to reproduce the issue:

  1. Create or find an AC app where query.fetchMore() is used on a query that shares data with other queries shown on-screen
  2. Change the fetchPolicy for the other queries to “cache-and-network”
  3. Start the app, open it, open the network tab in Chrome devtools
  4. Trigger the query.fetchMore() in the app
  5. Observe that the other queries (which were set to “cache-and-network”) are refetched after first (expected) request

Versions @apollo/client v3.3.13

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
benjamncommented, Dec 1, 2021

This does sound like the same issue as #6916—see my thoughts in https://github.com/apollographql/apollo-client/issues/6916#issuecomment-901466918.

The central idea is that complete cache results (broadcast after a successful fetchMore, for example) should be delivered immediately, by themselves, without triggering a network request for fetch policies like cache-and-network or network-only. Setting nextFetchPolicy: "cache-first" is a good workaround in the meantime because cache-first similarly avoids the network given a complete cache result.

I am actively working on that issue for v3.6. Unfortunately there are a number of test differences to work through, and those disruptions (even if they’re ultimately improvements, like fewer network requests) needed more intensive beta testing than we thought we could get before v3.5 was released. I’m still hopeful it will be safe for a minor release (rather than AC4).

Closing this as a duplicate (please join the discussion in #6916), but happy to reopen if my planned changes don’t (seem like they will) solve the whole problem here as well.

1reaction
Akryumcommented, Apr 7, 2021

Maybe related to #6916

Read more comments on GitHub >

github_iconTop Results From Across the Web

Queries - Apollo GraphQL Docs
Fetch data with the useQuery hook. This article shows how to fetch GraphQL data in React with the useQuery hook and attach the...
Read more >
Advanced Topics on Caching – Angular
With refetchQueries you can specify one or more queries that you want to run after a mutation is completed in order to refetch...
Read more >
fetchMore causes page to re-render unexpectedly
extract the part of the page which needs to fetch data on scroll into a ... wrap your extracted component with React.memo() so...
Read more >
How to invalidate cached data in Apollo and handle updating ...
I'm particularly impressed by how graphQL queries empower front end developers to access the data they need across multiple related data ...
Read more >
Prevent an Unnecessary Refetch with nextFetchPolicy and ...
... how the cache-and-network fetch policy works in Apollo Client 3. ... if you're seeing an unexpected refetch of a query after an...
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