-
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
Leave fetchPolicy
unchanged when skip: true
(or in standby) and nextFetchPolicy
is available
#9823
Changes from all commits
d0c06fc
b81faa3
6b0b741
1d691f7
e6737c1
5377d2e
21b4f56
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 |
---|---|---|
|
@@ -21,7 +21,7 @@ import { | |
asyncMap, | ||
isNonEmptyArray, | ||
Concast, | ||
ConcastSourcesIterable, | ||
ConcastSourcesArray, | ||
makeUniqueId, | ||
isDocumentNode, | ||
isNonNullObject, | ||
|
@@ -1122,16 +1122,33 @@ export class QueryManager<TStore> { | |
// modify its properties here, rather than creating yet another new | ||
// WatchQueryOptions object. | ||
normalized.variables = variables; | ||
return this.fetchQueryByPolicy<TData, TVars>( | ||
|
||
const concastSources = this.fetchQueryByPolicy<TData, TVars>( | ||
queryInfo, | ||
normalized, | ||
networkStatus, | ||
); | ||
|
||
if ( | ||
// If we're in standby, postpone advancing options.fetchPolicy using | ||
// applyNextFetchPolicy. | ||
normalized.fetchPolicy !== "standby" && | ||
// The "standby" policy currently returns [] from fetchQueryByPolicy, so | ||
// this is another way to detect when nothing was done/fetched. | ||
concastSources.length > 0 && | ||
queryInfo.observableQuery | ||
) { | ||
queryInfo.observableQuery["applyNextFetchPolicy"]("after-fetch", options); | ||
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. The |
||
} | ||
|
||
return concastSources; | ||
}; | ||
|
||
// This cancel function needs to be set before the concast is created, | ||
// in case concast creation synchronously cancels the request. | ||
const cleanupCancelFn = () => this.fetchCancelFns.delete(queryId); | ||
this.fetchCancelFns.set(queryId, reason => { | ||
cleanupCancelFn(); | ||
// This delay ensures the concast variable has been initialized. | ||
setTimeout(() => concast.cancel(reason)); | ||
}); | ||
|
@@ -1156,13 +1173,7 @@ export class QueryManager<TStore> { | |
: fromVariables(normalized.variables!) | ||
); | ||
|
||
concast.cleanup(() => { | ||
this.fetchCancelFns.delete(queryId); | ||
|
||
if (queryInfo.observableQuery) { | ||
queryInfo.observableQuery["applyNextFetchPolicy"]("after-fetch", options); | ||
} | ||
}); | ||
concast.promise.then(cleanupCancelFn, cleanupCancelFn); | ||
Comment on lines
-1159
to
+1176
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. In PR #9718, which has only landed on the |
||
|
||
return concast; | ||
} | ||
|
@@ -1338,7 +1349,7 @@ export class QueryManager<TStore> { | |
// NetworkStatus.loading, but also possibly fetchMore, poll, refetch, | ||
// or setVariables. | ||
networkStatus: NetworkStatus, | ||
): ConcastSourcesIterable<ApolloQueryResult<TData>> { | ||
): ConcastSourcesArray<ApolloQueryResult<TData>> { | ||
const oldNetworkStatus = queryInfo.networkStatus; | ||
|
||
queryInfo.init({ | ||
|
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.
Not only do we avoid calling
applyNextFetchPolicy
whenoptions.fetchPolicy === "standby"
, but this empty conditional block ensuresapplyNextFetchPolicy
has no effect in that case. Defense in depth!