Skip to content

Commit

Permalink
Pass queryInfo to fetchQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Jan 8, 2025
1 parent 971c45e commit abdc1e3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/core/ObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ Did you mean to call refetch(variables) instead of refetch({ variables })?`,
combinedOptions.query = this.transformDocument(combinedOptions.query);

const qid = this.queryManager.generateQueryId();
const fetchMoreQueryInfo = this.queryManager.getQuery(qid);

// If a temporary query is passed to `fetchMore`, we don't want to store
// it as the last query result since it may be an optimized query for
Expand Down Expand Up @@ -524,7 +525,7 @@ Did you mean to call refetch(variables) instead of refetch({ variables })?`,
}

return this.queryManager
.fetchQuery(qid, combinedOptions, NetworkStatus.fetchMore)
.fetchQuery(fetchMoreQueryInfo, combinedOptions, NetworkStatus.fetchMore)
.then((fetchMoreResult) => {
this.queryManager.removeQuery(qid);

Expand Down
12 changes: 5 additions & 7 deletions src/core/QueryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -656,15 +656,12 @@ export class QueryManager<TStore> {
}

public fetchQuery<TData, TVars extends OperationVariables>(
queryId: string,
queryInfo: QueryInfo,
options: WatchQueryOptions<TVars, TData>,
networkStatus?: NetworkStatus
): Promise<ApolloQueryResult<TData>> {
return this.fetchConcastWithInfo(
this.getQuery(queryId),
options,
networkStatus
).concast.promise as TODO;
return this.fetchConcastWithInfo(queryInfo, options, networkStatus).concast
.promise as TODO;
}

public getQueryStore() {
Expand Down Expand Up @@ -824,8 +821,9 @@ export class QueryManager<TStore> {
);

const query = this.transform(options.query);
const queryInfo = this.getQuery(queryId);

return this.fetchQuery<TData, TVars>(queryId, { ...options, query })
return this.fetchQuery<TData, TVars>(queryInfo, { ...options, query })
.then(
(result) =>
result && {
Expand Down
6 changes: 3 additions & 3 deletions src/core/__tests__/QueryManager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3810,7 +3810,7 @@ describe("QueryManager", () => {

const queryId = "1";
queryManager
.fetchQuery(queryId, { query })
.fetchQuery(queryManager.getQuery(queryId), { query })
.catch((e) => reject("Exception thrown for stopped query"));

queryManager.removeQuery(queryId);
Expand Down Expand Up @@ -3840,7 +3840,7 @@ describe("QueryManager", () => {
delay: 10000, //i.e. forever
});
queryManager
.fetchQuery("made up id", { query })
.fetchQuery(queryManager.getQuery("made up id"), { query })
.then(() => {
reject(new Error("Returned a result."));
})
Expand Down Expand Up @@ -4325,7 +4325,7 @@ describe("QueryManager", () => {
delay: 100,
});
queryManager
.fetchQuery("made up id", { query })
.fetchQuery(queryManager.getQuery("made up id"), { query })
.then(resolve)
.catch((error) => {
reject(new Error("Should not return an error"));
Expand Down

0 comments on commit abdc1e3

Please sign in to comment.