Skip to content

Commit

Permalink
Remove cache.batch wrapping, since we no longer need onWatchUpdated.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Mar 10, 2022
1 parent 9c06299 commit e8d2536
Showing 1 changed file with 24 additions and 34 deletions.
58 changes: 24 additions & 34 deletions src/core/ObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,46 +405,36 @@ Did you mean to call refetch(variables) instead of refetch({ variables })?`);
combinedOptions,
NetworkStatus.fetchMore,
).then(fetchMoreResult => {

this.queryManager.removeQuery(qid);

if (queryInfo.networkStatus === NetworkStatus.fetchMore) {
queryInfo.networkStatus = originalNetworkStatus;
}

// Performing this cache update inside a cache.batch transaction ensures
// any affected cache.watch watchers are notified about the updates. Most
// watchers will be using the QueryInfo class, which responds to
// notifications by calling reobserveCacheFirst to deliver fetchMore cache
// results back to this ObservableQuery.
this.queryManager.cache.batch({
update: cache => {
const { updateQuery } = fetchMoreOptions;
if (updateQuery) {
cache.updateQuery({
query: this.options.query,
variables: this.variables,
returnPartialData: true,
optimistic: false,
}, previous => updateQuery(previous!, {
fetchMoreResult: fetchMoreResult.data,
variables: combinedOptions.variables as TFetchVars,
}));

} else {
// If we're using a field policy instead of updateQuery, the only
// thing we need to do is write the new data to the cache using
// combinedOptions.variables (instead of this.variables, which is
// what this.updateQuery uses, because it works by abusing the
// original field value, keyed by the original variables).
cache.writeQuery({
query: combinedOptions.query,
variables: combinedOptions.variables,
data: fetchMoreResult.data,
});
}
},
});
const { updateQuery } = fetchMoreOptions;
if (updateQuery) {
this.queryManager.cache.updateQuery({
query: this.options.query,
variables: this.variables,
returnPartialData: true,
optimistic: false,
}, previous => updateQuery(previous!, {
fetchMoreResult: fetchMoreResult.data,
variables: combinedOptions.variables as TFetchVars,
}));

} else {
// If we're using a field policy instead of updateQuery, the only
// thing we need to do is write the new data to the cache using
// combinedOptions.variables (instead of this.variables, which is
// what this.updateQuery uses, because it works by abusing the
// original field value, keyed by the original variables).
this.queryManager.cache.writeQuery({
query: combinedOptions.query,
variables: combinedOptions.variables,
data: fetchMoreResult.data,
});
}

return fetchMoreResult as ApolloQueryResult<TFetchData>;
});
Expand Down

0 comments on commit e8d2536

Please sign in to comment.