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.

Fetch policy of no-cache on polling useQuery is ignored, cache is updated

See original GitHub issue

Intended outcome: useQuery hook that is polling with a fetchPolicy: no-cache should not update the cache. Actual outcome: The cache is updated with the query results from polling.

How to reproduce the issue: I have the following simple query below which fetches ID and one field the SQN. Document

const LOAD_DASHBOARD = gql`
	query LoadDashboard($id: ID!) {
		dashboardById(id: $id) {
			id
			sqn
		}
	}
`;

Code

const { data, startPolling, stopPolling } = useQuery<Query>(gql, {
		fetchPolicy: "no-cache",
		variables: {
			id,
		},
	});

If I call startPolling the next time the query is run the cache is updated when the call issue from the polling is executed, despite the fetch policy of no-cache. Are fetch policies ignored when polling?

Versions System: OS: macOS 12.2.1 Binaries: Node: 14.18.1 - ~/.nvm/versions/node/v14.18.1/bin/node Yarn: 1.22.4 - /usr/local/bin/yarn npm: 6.14.15 - ~/.nvm/versions/node/v14.18.1/bin/npm Browsers: Chrome: 101.0.4951.54 Firefox: 94.0.2 Safari: 15.3 npmPackages: @apollo/client: ^3.5.10 => 3.5.10 @apollo/react-testing: ^4.0.0 => 4.0.0

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:5
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
MrDoomBringercommented, Aug 15, 2022

Here’s a super quick reproduction of what I believe @jmtimko5 is talking about: https://codesandbox.io/s/fetch-policy-cache-polling-xqzwdi?file=/src/index.jsx

Here’s a link to a similar open issue involving watchQuery: https://github.com/apollographql/apollo-client/issues/6187

1reaction
MrDoomBringercommented, Sep 2, 2022

Commenting to say this should be resolved in https://github.com/apollographql/apollo-client/pull/10020! Thanks for opening this issue

All the best, Emmanuel, Intern 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Queries - Apollo GraphQL Docs
Setting a fetch policy. By default, the useQuery hook checks the Apollo Client cache to see if all the data you requested is...
Read more >
fetchPolicy option: "no-cache" does not work in useQuery
After the query is initially fetched, it will only be fetched again if either 1) the options passed to the hook change or...
Read more >
Understanding Apollo Fetch Policies | by Galen Corey - Medium
The fetch policy tells Apollo whether to prioritize getting the most recent data from the server or getting a faster response from the...
Read more >
React Apollo: Understanding Fetch Policy with useQuery
I changed the fetch policy in the project to no-cache because I thought that would fit more to the project. After that I...
Read more >
Disabling/Pausing Queries | TanStack Query Docs
If the query has cached data, then the query will be initialized in the status ... from useQuery can be used to manually...
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