Apollo-client: Refetching a no-cache query causes the response to be cached

Created on 10 Sep 2020  路  1Comment  路  Source: apollographql/apollo-client

Intended outcome:
Refetching a query with a fetchPolicy of no-cache and notifyOnNetworkStatusChange enabled should not result in the response being cached.

Actual outcome:
Refetching a query with fetchPolicy of no-cache and notifyOnNetworkStatusChange enabled causes the response to be cached.

This occurs when using the refetch function provided by the Query component (or output of useQuery hook) and also when using refetchQueries on a mutation.

How to reproduce the issue:
Reproduction is here. Use the Apollo dev tools to inspect the cache before and after clicking the refetch button and observe that after the refetch, the query response is now cached.

https://github.com/lee-borsboom/react-apollo-error-template/tree/refetch_noCache_query

Versions
npx envinfo@latest --preset apollo --clipboard isn't working for me, but I can replicate this on version 3.1.3 and 3.1.4 of Apollo client

Most helpful comment

Same problem here. It's because https://github.com/apollographql/apollo-client/blob/main/src/core/QueryManager.ts#L848
The 'no-cache' case should not be included in the mightUseNetwork boolean ?

>All comments

Same problem here. It's because https://github.com/apollographql/apollo-client/blob/main/src/core/QueryManager.ts#L848
The 'no-cache' case should not be included in the mightUseNetwork boolean ?

Was this page helpful?
0 / 5 - 0 ratings