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.

fetchPolicy="network-only" still returns data from the cache

See original GitHub issue

It seems like even when I’m using network-only that data from the cache is being returned immediately. I would have expected that the rendering phases would be:

{ data: {},           loading: true }  // render 1
{ data: { foo: {…} }, loading: false } // render 2
// done

Instead what happens is that if data from the cache exists, at render 1 data will actually be populated with the cache data.

The React Apollo docs make it clear this should never happen:

network-only: This fetch policy will never return you initial data from the cache. Instead it will always make a request using your network interface to the server. This fetch policy optimizes for data consistency with the server, but at the cost of an instant response to the user when one is available.

For now I’m using a wrapper that returns {} when loading=true and fetchPolicy=no-cache or fetchPolicy=network-only.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
ziedHamdicommented, Nov 13, 2019

Who found a workaround for this?

0reactions
adrianescatcommented, Nov 20, 2019

I need a solution for this too. fetchPolicy: "network-only" is not working.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Queries - Apollo GraphQL Docs
If all data is available locally, useQuery returns that data and doesn't query your GraphQL server. This cache-first policy is Apollo Client's default...
Read more >
useQuery with fetchPolicy: 'network-only', returns stale cached ...
I'm using useQuery with fetchPolicy: 'network-only' . In certain cases, it does not make a network request, and returns not just cached ......
Read more >
Understanding Apollo Fetch Policies | by Galen Corey - Medium
Apollo makes a network request for your data without checking the cache. The server responds and the data is returned without updating the...
Read more >
React Apollo: Understanding Fetch Policy with useQuery
Apollo Client first executes the query against the cache. If all requested data is present in the cache, that data is returned. Otherwise, ......
Read more >
Apollo Cache is Your Friend, If You Get To Know It
The query above isn't returning the proper data for the metas. ... to the network first, going to the cache only or network...
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