-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Preserve cache-and-network fetchPolicy when refetching. #4840
Preserve cache-and-network fetchPolicy when refetching. #4840
Conversation
@@ -1070,7 +1071,7 @@ describe('ObservableQuery', () => { | |||
const observable = queryManager.watchQuery({ | |||
query: firstRequest.query, | |||
variables: firstRequest.variables, | |||
fetchPolicy: 'cache-and-network', | |||
fetchPolicy: 'cache-first', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test was literally just checking that cache-and-network
gets overridden with network-only
when refetching, so I think it's safe to check cache-first
instead (if we accept the premise of this pull request).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great @benjamn, and I'm 👍 on getting this into 2.6.0. Thanks!
Should help with the problem reported by @supercranky in this comment: #4636 (comment) The apparent reasoning for preserving the no-cache and network-only fetch policies is that refetching requires a "network" fetch policy, but I believe cache-and-network should also count as a "network" fetch policy, since it always attempts to fetch from the network in addition to fetching from the cache. Even if that network request fails, it may be useful (e.g. for offline usage) to return data from the cache.
05c58f3
to
467146b
Compare
Hi @benjamn This change seems to be annoying for some of us (apollographql/react-apollo#3457 (comment)) Do you think it could be possible to pass a custom fetch policy to the "refetch" call? I want my query to have cache-and-network, but I want my refetch() promise to only resolve after the actual network refetch has been done, and this seems impossible currently |
Should help with the problem reported by @supercranky in this comment.
The apparent reasoning for preserving the
no-cache
andnetwork-only
fetch policies is that refetching requires a "network" fetch policy, but I believecache-and-network
should also count as a "network" fetch policy, since it always attempts to fetch from the network in addition to fetching from the cache. Even if that network request fails, it may be useful (e.g. for offline usage) to return partial data from the cache, which is currently not possible when refetching, given therefetch
method's behavior of overriding non-network/cache-friendlyfetchPolicy
s.