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.

nextFetchPolicy doesn't work as expected.

See original GitHub issue

Preface: My understanding from the docs has been that while using useQuery, the first execution takes place as specified by fetch-policy. All subsequent executions of the query follow nextFetchPolicy(If Specified).

Intended outcome: I set the fetchPolicy to cache-first and nextFetchPolicy to network-only expecting that a network request will be made on every execution after the first.

Actual Outcome: But the same isn’t replicating. On subsequent executions, data is getting read from cache and no network-request is made.

How to reproduce the issue: Here is a codesandbox to check the same Link.

Versions version : 3.4.8

Am I misunderstanding nextFetchPolicy or is this a bug?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

11reactions
dylanwulfcommented, Aug 31, 2021

fetchPolicy is used every time the component mounts. nextFetchPolicy is used for every query execution after the component mounts. When you unmount and remount the component, it resets to fetchPolicy. Unfortunately it isn’t super clear in the docs exactly what “first execution” means.

0reactions
dylanwulfcommented, Aug 2, 2022

@santialbo “changing the variables” and “calling refetch” are not the only things that could cause a query execution. I believe if some related data in the cache gets updated, that is another scenario where the query would get re-executed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setting The Correct Fetch Policy - Help - Apollo Community
I'm close to finishing my product. Throughout the software I use a fetch policy of network-only and a nextFetchPolicy of cache-first based on ......
Read more >
React Apollo: Understanding Fetch Policy with useQuery
A cache-only query throws an error if the cache does not contain data for all requested fields. cache-and-network, Apollo Client executes the ...
Read more >
Pitfalls I fell into during Apollo Client 3.0 migration
Recently I worked on migrating Apollo Client to 3.0 from 2.6 in our ... On the other hand, we found cache updates do...
Read more >
graphql - 3 level type object does not return expected results
i am working with apollo graphql and i have a query with 3 nested type objects. as shown below
Read more >
Prevent an Unnecessary Refetch with nextFetchPolicy and ...
I recently figured out the cause of a strange issue due to a change in how the cache-and-network fetch policy works in Apollo...
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