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 11, 2022
1 parent 96d97e6 commit d5463be
Showing 1 changed file with 24 additions and 33 deletions.
57 changes: 24 additions & 33 deletions src/core/ObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,39 +410,30 @@ Did you mean to call refetch(variables) instead of refetch({ variables })?`);
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 d5463be

Please sign in to comment.