Skip to content

Commit

Permalink
keep options reference stable
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas committed Sep 21, 2023
1 parent b69d348 commit 018eaec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
17 changes: 7 additions & 10 deletions src/core/ObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -728,15 +728,17 @@ Did you mean to call refetch(variables) instead of refetch({ variables })?`,

private fetch(
options: WatchQueryOptions<TVariables, TData>,
newNetworkStatus?: NetworkStatus
newNetworkStatus?: NetworkStatus,
query?: DocumentNode
) {
// TODO Make sure we update the networkStatus (and infer fetchVariables)
// before actually committing to the fetch.
this.queryManager.setObservableQuery(this);
return this.queryManager["fetchConcastWithInfo"](
this.queryId,
options,
newNetworkStatus
newNetworkStatus,
query
);
}

Expand Down Expand Up @@ -883,20 +885,15 @@ Did you mean to call refetch(variables) instead of refetch({ variables })?`,
}
}

// If the transform doesn't change the document, leave `options` alone and
// use the original object.
const fetchOptions =
query === options.query ? options : { ...options, query };

this.waitForOwnResult &&= skipCacheDataFor(fetchOptions.fetchPolicy);
this.waitForOwnResult &&= skipCacheDataFor(options.fetchPolicy);
const finishWaitingForOwnResult = () => {
if (this.concast === concast) {
this.waitForOwnResult = false;
}
};

const variables = fetchOptions.variables && { ...fetchOptions.variables };
const { concast, fromLink } = this.fetch(fetchOptions, newNetworkStatus);
const variables = options.variables && { ...options.variables };
const { concast, fromLink } = this.fetch(options, newNetworkStatus, query);
const observer: Observer<ApolloQueryResult<TData>> = {
next: (result) => {
finishWaitingForOwnResult();
Expand Down
4 changes: 2 additions & 2 deletions src/core/QueryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1220,9 +1220,9 @@ export class QueryManager<TStore> {
// The initial networkStatus for this fetch, most often
// NetworkStatus.loading, but also possibly fetchMore, poll, refetch,
// or setVariables.
networkStatus = NetworkStatus.loading
networkStatus = NetworkStatus.loading,
query = options.query
): ConcastAndInfo<TData> {
const { query } = options;
const variables = this.getVariables(query, options.variables) as TVars;
const queryInfo = this.getQuery(queryId);

Expand Down

0 comments on commit 018eaec

Please sign in to comment.