Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't read from cache with network-only and no-cache policy? #7219

Conversation

stoically
Copy link
Contributor

@stoically stoically commented Oct 23, 2020

While debugging #6941 I've stumbled over the fact that internally fetchQueryObservable overwrites the network-only and no-cache policies with cache-and-network. There's a comment explaining the why, and this was apparently intentional based on #6221 (comment) - however, I'm not sure why exactly this happens. Shouldn't the fact that the user said to not consult the cache be respected?

A side effect of this overwriting is that in case of refetching with network-only policy, useQuery returns an empty data object (from the cache) instead of undefined. Based on https://github.com/apollographql/apollo-client/pull/6566/files#r452533298 I believe the intention is to always return undefined if there are no results. Before v3 refetching in this case returned the old data while loading, which was changed in #6566.

I've included a test to reproduce the empty object, however, my fix currently breaks a lot of other tests. I'd be happy to get some feedback on what would be considered the right way to approach this. Thanks!

Related #7043
Fixes #6941
Fixes #6998

@stoically stoically force-pushed the fix/no-cache-policies-read-from-cache branch 4 times, most recently from a0f5282 to fb804de Compare October 23, 2020 09:07
@stoically stoically force-pushed the fix/no-cache-policies-read-from-cache branch from fb804de to 3789574 Compare October 23, 2020 09:09
@stoically stoically changed the title RFC: Don't read from cache with network-only and no-cache policy Don't read from cache with network-only and no-cache policy Oct 24, 2020
@stoically stoically changed the title Don't read from cache with network-only and no-cache policy Don't read from cache with network-only and no-cache policy? Oct 24, 2020
@stoically
Copy link
Contributor Author

Closing as this is hopelessly outdated.

@stoically stoically closed this Feb 21, 2022
@stoically stoically deleted the fix/no-cache-policies-read-from-cache branch February 21, 2022 07:44
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
1 participant