diff --git a/.api-reports/api-report-core.api.md b/.api-reports/api-report-core.api.md index f1d74960f19..d1af05cfbc4 100644 --- a/.api-reports/api-report-core.api.md +++ b/.api-reports/api-report-core.api.md @@ -2473,6 +2473,8 @@ export type WatchQueryFetchPolicy = FetchPolicy | "cache-and-network"; // // @public export interface WatchQueryOptions extends SharedWatchQueryOptions { + // @internal (undocumented) + inactiveBeforeSubscription?: boolean; query: DocumentNode | TypedDocumentNode; } @@ -2518,7 +2520,7 @@ interface WriteContext extends ReadMergeModifyContext { // src/core/ObservableQuery.ts:121:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts // src/core/QueryManager.ts:159:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts // src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts -// src/core/watchQueryOptions.ts:277:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts +// src/core/watchQueryOptions.ts:279:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts // src/link/http/selectHttpOptionsAndBody.ts:128:32 - (ae-forgotten-export) The symbol "HttpQueryOptions" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) diff --git a/.api-reports/api-report-react.api.md b/.api-reports/api-report-react.api.md index 904d5977115..dcd8d0185a3 100644 --- a/.api-reports/api-report-react.api.md +++ b/.api-reports/api-report-react.api.md @@ -2513,6 +2513,8 @@ type WatchQueryFetchPolicy = FetchPolicy | "cache-and-network"; // @public interface WatchQueryOptions extends SharedWatchQueryOptions { + // @internal (undocumented) + inactiveBeforeSubscription?: boolean; query: DocumentNode | TypedDocumentNode; } @@ -2531,7 +2533,7 @@ interface WatchQueryOptions extends SharedWatchQueryOptions { + // @internal (undocumented) + inactiveBeforeSubscription?: boolean; query: DocumentNode | TypedDocumentNode; } @@ -2013,7 +2015,7 @@ interface WatchQueryOptions extends SharedWatchQueryOptions { + // @internal (undocumented) + inactiveBeforeSubscription?: boolean; query: DocumentNode | TypedDocumentNode; } @@ -1933,7 +1935,7 @@ interface WatchQueryOptions extends SharedWatchQueryOptions { + // @internal (undocumented) + inactiveBeforeSubscription?: boolean; query: DocumentNode | TypedDocumentNode; } @@ -1960,7 +1962,7 @@ export function withSubscription extends SharedWatchQueryOptions { + // @internal (undocumented) + inactiveBeforeSubscription?: boolean; query: DocumentNode | TypedDocumentNode; } @@ -2355,7 +2357,7 @@ interface WatchQueryOptions extends SharedWatchQueryOptions { + // @internal (undocumented) + inactiveBeforeSubscription?: boolean; query: DocumentNode | TypedDocumentNode; } @@ -2418,7 +2420,7 @@ export function wrapQueryRef(inter // src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts // src/core/types.ts:175:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts // src/core/types.ts:204:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts -// src/core/watchQueryOptions.ts:277:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts +// src/core/watchQueryOptions.ts:279:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts // src/react/hooks/useBackgroundQuery.ts:38:3 - (ae-forgotten-export) The symbol "SubscribeToMoreFunction" needs to be exported by the entry point index.d.ts // src/react/hooks/useBackgroundQuery.ts:54:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts // src/react/hooks/useBackgroundQuery.ts:78:4 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts diff --git a/.api-reports/api-report-react_ssr.api.md b/.api-reports/api-report-react_ssr.api.md index 83958f92452..fe347380142 100644 --- a/.api-reports/api-report-react_ssr.api.md +++ b/.api-reports/api-report-react_ssr.api.md @@ -1900,6 +1900,8 @@ type WatchQueryFetchPolicy = FetchPolicy | "cache-and-network"; // @public interface WatchQueryOptions extends SharedWatchQueryOptions { + // @internal (undocumented) + inactiveBeforeSubscription?: boolean; query: DocumentNode | TypedDocumentNode; } @@ -1918,7 +1920,7 @@ interface WatchQueryOptions extends SharedWatchQueryOptions { + // @internal (undocumented) + inactiveBeforeSubscription?: boolean; query: DocumentNode | TypedDocumentNode; } @@ -1986,7 +1988,7 @@ export function withWarningSpy(it: (...args: TArgs // src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts // src/core/types.ts:175:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts // src/core/types.ts:204:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts -// src/core/watchQueryOptions.ts:277:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts +// src/core/watchQueryOptions.ts:279:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) diff --git a/.api-reports/api-report-testing_core.api.md b/.api-reports/api-report-testing_core.api.md index 9b98b8e17de..078a162d9dd 100644 --- a/.api-reports/api-report-testing_core.api.md +++ b/.api-reports/api-report-testing_core.api.md @@ -1916,6 +1916,8 @@ type WatchQueryFetchPolicy = FetchPolicy | "cache-and-network"; // // @public interface WatchQueryOptions extends SharedWatchQueryOptions { + // @internal (undocumented) + inactiveBeforeSubscription?: boolean; query: DocumentNode | TypedDocumentNode; } @@ -1943,7 +1945,7 @@ export function withWarningSpy(it: (...args: TArgs // src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts // src/core/types.ts:175:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts // src/core/types.ts:204:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts -// src/core/watchQueryOptions.ts:277:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts +// src/core/watchQueryOptions.ts:279:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) diff --git a/.api-reports/api-report-utilities.api.md b/.api-reports/api-report-utilities.api.md index 6905e929046..f7be3962ba3 100644 --- a/.api-reports/api-report-utilities.api.md +++ b/.api-reports/api-report-utilities.api.md @@ -2837,6 +2837,8 @@ type WatchQueryFetchPolicy = FetchPolicy | "cache-and-network"; // // @public interface WatchQueryOptions extends SharedWatchQueryOptions { + // @internal (undocumented) + inactiveBeforeSubscription?: boolean; query: DocumentNode | TypedDocumentNode; } @@ -2890,7 +2892,7 @@ interface WriteContext extends ReadMergeModifyContext { // src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts // src/core/types.ts:175:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts // src/core/types.ts:204:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts -// src/core/watchQueryOptions.ts:277:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts +// src/core/watchQueryOptions.ts:279:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts // src/utilities/graphql/storeUtils.ts:226:12 - (ae-forgotten-export) The symbol "storeKeyNameStringify" needs to be exported by the entry point index.d.ts // src/utilities/policies/pagination.ts:76:3 - (ae-forgotten-export) The symbol "TRelayEdge" needs to be exported by the entry point index.d.ts // src/utilities/policies/pagination.ts:77:3 - (ae-forgotten-export) The symbol "TRelayPageInfo" needs to be exported by the entry point index.d.ts diff --git a/.api-reports/api-report.api.md b/.api-reports/api-report.api.md index 42e41d0e105..60e4c1ff3c5 100644 --- a/.api-reports/api-report.api.md +++ b/.api-reports/api-report.api.md @@ -3184,6 +3184,8 @@ export type WatchQueryFetchPolicy = FetchPolicy | "cache-and-network"; // @public export interface WatchQueryOptions extends SharedWatchQueryOptions { + // @internal (undocumented) + inactiveBeforeSubscription?: boolean; query: DocumentNode | TypedDocumentNode; } @@ -3229,7 +3231,7 @@ interface WriteContext extends ReadMergeModifyContext { // src/core/ObservableQuery.ts:121:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts // src/core/QueryManager.ts:159:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts // src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts -// src/core/watchQueryOptions.ts:277:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts +// src/core/watchQueryOptions.ts:279:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts // src/link/http/selectHttpOptionsAndBody.ts:128:32 - (ae-forgotten-export) The symbol "HttpQueryOptions" needs to be exported by the entry point index.d.ts // src/react/hooks/useBackgroundQuery.ts:38:3 - (ae-forgotten-export) The symbol "SubscribeToMoreFunction" needs to be exported by the entry point index.d.ts // src/react/hooks/useBackgroundQuery.ts:54:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts diff --git a/.size-limits.json b/.size-limits.json index 5790c408cde..42d16d0cb1f 100644 --- a/.size-limits.json +++ b/.size-limits.json @@ -1,4 +1,4 @@ { - "dist/apollo-client.min.cjs": 41640, - "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 34381 + "dist/apollo-client.min.cjs": 41719, + "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 34458 } diff --git a/src/core/ObservableQuery.ts b/src/core/ObservableQuery.ts index 2a70e6e9097..6daeb637389 100644 --- a/src/core/ObservableQuery.ts +++ b/src/core/ObservableQuery.ts @@ -121,7 +121,13 @@ export class ObservableQuery< queryInfo: QueryInfo; options: WatchQueryOptions; }) { + let startedInactive = options.inactiveBeforeSubscription; super((observer: Observer>>) => { + if (startedInactive && !queryManager["queries"].has(this.queryId)) { + queryManager["queries"].set(this.queryId, queryInfo); + startedInactive = false; + } + // Zen Observable has its own error function, so in order to log correctly // we need to provide a custom error callback. try { diff --git a/src/core/QueryManager.ts b/src/core/QueryManager.ts index 066dc137de9..bf550ddf13b 100644 --- a/src/core/QueryManager.ts +++ b/src/core/QueryManager.ts @@ -780,7 +780,9 @@ export class QueryManager { }); observable["lastQuery"] = query; - this.queries.set(observable.queryId, queryInfo); + if (!options.inactiveBeforeSubscription) { + this.queries.set(observable.queryId, queryInfo); + } // We give queryInfo the transformed query to ensure the first cache diff // uses the transformed query instead of the raw query diff --git a/src/core/watchQueryOptions.ts b/src/core/watchQueryOptions.ts index 1528b1d0330..d6cac6dca9a 100644 --- a/src/core/watchQueryOptions.ts +++ b/src/core/watchQueryOptions.ts @@ -94,6 +94,8 @@ export interface WatchQueryOptions< > extends SharedWatchQueryOptions { /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#query:member} */ query: DocumentNode | TypedDocumentNode; + /** @internal */ + inactiveBeforeSubscription?: boolean; } export interface SharedWatchQueryOptions< diff --git a/src/react/hooks/__tests__/useQuery.test.tsx b/src/react/hooks/__tests__/useQuery.test.tsx index 2edf19d2a36..1879438335c 100644 --- a/src/react/hooks/__tests__/useQuery.test.tsx +++ b/src/react/hooks/__tests__/useQuery.test.tsx @@ -1540,7 +1540,7 @@ describe("useQuery Hook", () => { function checkObservableQueries(expectedLinkCount: number) { const obsQueries = client.getObservableQueries("all"); - expect(obsQueries.size).toBe(2); + expect(obsQueries.size).toBe(1); const activeSet = new Set(); const inactiveSet = new Set(); diff --git a/src/react/hooks/useQuery.ts b/src/react/hooks/useQuery.ts index a1b83c3c68c..cfead25c9a8 100644 --- a/src/react/hooks/useQuery.ts +++ b/src/react/hooks/useQuery.ts @@ -614,6 +614,8 @@ export function createMakeWatchQueryOptions< getDefaultFetchPolicy(defaultOptions, client.defaultOptions); } + watchQueryOptions.inactiveBeforeSubscription = true; + return watchQueryOptions; }; }