Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/__tests__/__snapshots__/exports.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ Array [
"removeMaskedFragmentSpreads",
"resultKeyNameFromField",
"shouldInclude",
"skipToken",
"storeKeyNameFromField",
"stringifyForDisplay",
"toQueryResult",
Expand Down
8 changes: 8 additions & 0 deletions src/core/ObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
getOperationName,
getQueryDefinition,
preventUnhandledRejection,
skipToken,
toQueryResult,
} from "@apollo/client/utilities/internal";
import { invariant } from "@apollo/client/utilities/invariant";
Expand Down Expand Up @@ -1068,6 +1069,13 @@ Did you mean to call refetch(variables) instead of refetch({ variables })?`,
newOptions: Partial<ObservableQuery.Options<TData, TVariables>>
): void {
const mergedOptions = compact(this.options, newOptions || {});
if (skipToken in (newOptions.variables || {})) {
Object.assign(
mergedOptions.variables,
this.options.variables,
newOptions.variables
);
}
assign(this.options, mergedOptions);
this.updatePolling();
}
Expand Down
6 changes: 5 additions & 1 deletion src/core/QueryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import {
isNonNullObject,
makeUniqueId,
removeDirectivesFromDocument,
skipToken,
toQueryResult,
} from "@apollo/client/utilities/internal";
import {
Expand Down Expand Up @@ -1295,7 +1296,10 @@ export class QueryManager {

if (include) {
this.getObservableQueries(include).forEach((oq) => {
if (oq.options.fetchPolicy === "cache-only") {
if (
oq.options.fetchPolicy === "cache-only" ||
skipToken in oq.options.variables
) {
return;
}

Expand Down
5 changes: 3 additions & 2 deletions src/react/hooks/__tests__/useQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1749,7 +1749,7 @@ describe("useQuery Hook", () => {
});

await rerender(skipToken);

// !!! rerenders with `undefined` variables
await expect(renderStream).toRerenderWithSimilarSnapshot();

client.writeQuery({
Expand Down Expand Up @@ -1889,7 +1889,7 @@ describe("useQuery Hook", () => {
});

await rerender(skipToken);

// !!! rerenders with `undefined` variables
await expect(renderStream).toRerenderWithSimilarSnapshot();

client.writeQuery({
Expand Down Expand Up @@ -8702,6 +8702,7 @@ describe("useQuery Hook", () => {
const { fetchPolicy, initialFetchPolicy } = observable.options;

expect(fetchPolicy).toBe(expectedFetchPolicy);
// last failing test, should be "cache-and-network", but is "cache-first"
expect(initialFetchPolicy).toBe(expectedInitialFetchPolicy);
}

Expand Down
Loading
Loading