useLazyQuery doesn't work with cache-and-network fetch policy
See original GitHub issueIntended 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:
- Created 3 years ago
- Reactions:12
- Comments:9
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Happening here too
i can confirm that setting
fetchPolicy: 'network-only',
will make it work!