apollo-client
apollo-client copied to clipboard
Fetch policy of no-cache on polling useQuery is ignored, cache is updated
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
@jmtimko5 Just in case it helps, can you try npm i @apollo/client@next (to get version 3.6.3)?
@benjamn I am having this exact same issue on 3.6.9
I have extremely painfull errors happening that quite obviously are created because calling functions returning values leads to cache being changed in unexpected ways. When I run the functions using sql the correct values are returned. When running them using graphIQL previously used values are returned.
I have worked through multiple interations of trying to correct this error. Manipulating dataIdFromObject did not help. Setting fetchPolicy: 'no-cache' did not work.
This is awful. I now have to find a solution not using apollographql. Which forces me to implement two ways of connecting to the db, while authenticating correctly.
Yikes.
Would someone here be able to provide a small runnable reproduction that clearly demonstrates the issue?
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 :-)