Don't read from cache with network-only and no-cache policy? #7219
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While debugging #6941 I've stumbled over the fact that internally
fetchQueryObservable
overwrites thenetwork-only
andno-cache
policies withcache-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
refetch
ing withnetwork-only
policy,useQuery
returns an empty data object (from the cache) instead ofundefined
. Based on https://github.com/apollographql/apollo-client/pull/6566/files#r452533298 I believe the intention is to always returnundefined
if there are no results. Before v3refetch
ing 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