Fetch policy of no-cache on polling useQuery is ignored, cache is updated
See original GitHub issueIntended 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:
- Created a year ago
- Reactions:5
- Comments:6 (2 by maintainers)
Top GitHub Comments
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
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 😃