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.

useLazyQuery doesn't work with cache-and-network fetch policy

See original GitHub issue

Intended outcome: After the lazy query be triggered, it should behave correctly according to the fetch policy chosen

Actual outcome: The fetch policy cache-and-network isn’t working when using lazy queries. It should look on the server and update the cache with the most recent data.

How to reproduce the issue: Execute useLazyQuery hook using fetch-policy as cache-and-network on @apollo/client v3.1.3.

Also, I’m setting cache-and-network as the default fetch policy for all queries. Refer to the config:

const apolloClient = new ApolloClient({
  cache,
  link: ApolloLink.from([
    sentryErrorLink,
    authenticatedLink,
  ]),
  defaultOptions: {
    watchQuery: {
      fetchPolicy: "cache-and-network",
    },
  },
});

Versions

  System:
    OS: macOS 10.15.6
  Binaries:
    Node: 12.16.3 - ~/.nvm/versions/node/v12.16.3/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.4 - ~/.nvm/versions/node/v12.16.3/bin/npm
  Browsers:
    Chrome: 86.0.4240.80
    Safari: 14.0
  npmPackages:
    @apollo/client: 3.1.3 => 3.1.3 
    apollo-sentry-helper: ^2.0.3 => 2.0.3 
    apollo-utilities: ^1.3.4 => 1.3.4 

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:12
  • Comments:9

github_iconTop GitHub Comments

7reactions
pedro-lbcommented, Oct 16, 2020

Happening here too

5reactions
sajadghawamicommented, Nov 1, 2020

i can confirm that setting fetchPolicy: 'network-only', will make it work!

Read more comments on GitHub >

github_iconTop Results From Across the Web

"cache-and-network" fails silently on a query that works with ...
Even curiouser is that I can literally set the fetchPolicy to ANY random string and it doesn't error. Looks like it just falls...
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 >
useLazyQuery is not updating data on refetch - Stack Overflow
Had a Similar issue with my code base as well you can use {fetchPolicy: "network-only"}. inside your useLazyQuery(). It works cost network ...
Read more >
Tips and Tricks for working with Apollo Cache - Medium
The following are the list of fetch policies that you can specify for your query: cache-first; cache-and-network; network-only; no-cache ...
Read more >
Queries - Vue Apollo
Only fetch from network if cached result is not available. cache-and-network : return result from cache first (if it exists), then return 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