-
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
Fix defaultOptions.watchQuery.fetchPolicy
not being used by useQuery
#9210
Fix defaultOptions.watchQuery.fetchPolicy
not being used by useQuery
#9210
Conversation
@yasharzolmajdi: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/ |
@yasharzolmajdi Tested this locally and it fixed it for me. The defaultOptions is used on the react hooks from 3.0.1 but I think somewhere between then and 3.5.6 (the one I'm using right now) it stopped using the defaults. |
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.
Thanks for this @yasharzolmajdi! If you could add a test(s) to help verify this works as expected (and to help avoid regressions in the future), that would be helpful.
@hwillson Thanks, I have added a test which currently fails on the main branch but passes with my changes |
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.
Thanks for the test @yasharzolmajdi - this looks great to me. @brainkim @benjamn any objections to merging?
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.
Thank you for this!
defaultOptions
not being used by useQuery
d92041b
to
b5d1e28
Compare
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.
LGTM, and I can confirm the test fails when the changes are reverted. Thanks @yasharzolmajdi!
defaultOptions
not being used by useQuery
defaultOptions.watchQuery.fetchPolicy
not being used by useQuery
Follow-up/refinement to PR #9210. Now that the createWatchQueryOptions function no longer defaults watchQueryOptions.fetchPolicy to "cache-first" unconditionally (instead defaulting to defaultOptions.watchQuery.fetchPolicy if defined), we can let the merging of defaultOptions happen as it normally does, when client.watchQuery(watchQueryOptions) is called later.
This PR is intended to solve the issue of default options in client not setting the correct fetch policy in useQuery.
when user doesn't set a fetch policy option in useQuery, it is defaulted to
cache-first
before it attempts to use the default fetch policy that is set in by the client.the fetch policy hierarchy currently is:
cache-first
in useQueryit completely ignores default fetch policy from the client
with this PR it will be:
cache-first
in useQueryfixes #9105
fixes #2555