-
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
Refactor useLazyQuery
to reuse useInternalState
and make execution function call reobserve
instead of refetch
#9564
Changes from 1 commit
7fc6c89
3546c9c
02a1e6d
a18e2e0
2302716
4e77bca
72a805d
f93e904
d26bdd4
52ba67e
6cb2cdb
ff0186d
4be1901
71d8df4
345a156
f164b1b
89af070
782642b
c3d1a83
da41ce8
c9a2c01
feb07db
ff43d78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -220,9 +220,7 @@ class InternalState<TData, TVariables> { | |
const watchQueryOptions: WatchQueryOptions<TVariables, TData> = | ||
Object.assign(merged, { query: this.query }); | ||
|
||
if (skip) { | ||
watchQueryOptions.fetchPolicy = 'standby'; | ||
} else if ( | ||
if ( | ||
this.renderPromises && | ||
( | ||
watchQueryOptions.fetchPolicy === 'network-only' || | ||
|
@@ -239,6 +237,24 @@ class InternalState<TData, TVariables> { | |
watchQueryOptions.fetchPolicy = 'cache-first'; | ||
} | ||
|
||
if (skip) { | ||
const { | ||
// The watchQueryOptions.initialFetchPolicy field usually defaults to | ||
// watchQueryOptions.fetchPolicy, which has now been properly | ||
// defaulted/initialized. However, watchQueryOptions.initialFetchPolicy | ||
// can be provided explicitly instead, if more control is desired. | ||
initialFetchPolicy = watchQueryOptions.fetchPolicy, | ||
} = watchQueryOptions; | ||
|
||
// When skipping, we set watchQueryOptions.fetchPolicy initially to | ||
// "standby", but we also need/want to preserve the initial non-standby | ||
// fetchPolicy that would have been used if not skipping. | ||
Object.assign(watchQueryOptions, { | ||
initialFetchPolicy, | ||
fetchPolicy: 'standby', | ||
}); | ||
Comment on lines
+249
to
+255
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is where the |
||
} | ||
|
||
if (!watchQueryOptions.variables) { | ||
watchQueryOptions.variables = {} as TVariables; | ||
} | ||
|
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.
I don't love adding another optional field to
WatchQueryOptions
, but I truly do not expect anyone to need to use this field directly, and it helps us maintain the promise thatskip: true
is (more or less) synonymous withfetchPolicy: "standby"
, because it gives us a way to passfetchPolicy: "standby"
whenskip: true
without ending up stuck withinitialFetchPolicy === "standby"
.