Skip to content

Commit cdc55ff

Browse files
keep ObservableQuery initiated from useQuery inactive before first subscription (#12285)
* experiment: keep ObservableQuery initiated from `useQuery` inactive before first subscription * changeset * different handling during SSR * adjust test * use a slot instead of a config option * chores * change to `private` property * remove unnecessary condition * appease linter * rename `getQuery` to `getOrCreateQuery`, call `this.queries.get` where not needed * adjust test * chores * remove unused import * Update src/react/hoc/__tests__/queries/lifecycle.test.tsx Co-authored-by: Jerel Miller <[email protected]> * Update src/core/__tests__/ApolloClient/general.test.ts Co-authored-by: Jerel Miller <[email protected]> --------- Co-authored-by: Jerel Miller <[email protected]>
1 parent 820f6e6 commit cdc55ff

20 files changed

+126
-100
lines changed

.api-reports/api-report-core.api.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1944,6 +1944,8 @@ class QueryManager<TStore> {
19441944
getLocalState(): LocalState<TStore>;
19451945
// (undocumented)
19461946
getObservableQueries(include?: InternalRefetchQueriesInclude): Map<string, ObservableQuery<any, OperationVariables>>;
1947+
// (undocumented)
1948+
getOrCreateQuery(queryId: string): QueryInfo;
19471949
// Warning: (ae-forgotten-export) The symbol "QueryStoreValue" needs to be exported by the entry point index.d.ts
19481950
//
19491951
// (undocumented)
@@ -2008,8 +2010,6 @@ class QueryManager<TStore> {
20082010
// (undocumented)
20092011
resetErrors(queryId: string): void;
20102012
// (undocumented)
2011-
setObservableQuery(observableQuery: ObservableQuery<any, any>): void;
2012-
// (undocumented)
20132013
readonly ssrMode: boolean;
20142014
// (undocumented)
20152015
startGraphQLSubscription<T = any>(options: SubscriptionOptions): Observable<FetchResult<T>>;
@@ -2533,8 +2533,8 @@ interface WriteContext extends ReadMergeModifyContext {
25332533
// src/cache/inmemory/policies.ts:162:3 - (ae-forgotten-export) The symbol "KeySpecifier" needs to be exported by the entry point index.d.ts
25342534
// src/cache/inmemory/policies.ts:162:3 - (ae-forgotten-export) The symbol "KeyArgsFunction" needs to be exported by the entry point index.d.ts
25352535
// src/cache/inmemory/types.ts:139:3 - (ae-forgotten-export) The symbol "KeyFieldsFunction" needs to be exported by the entry point index.d.ts
2536-
// src/core/ObservableQuery.ts:118:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
2537-
// src/core/ObservableQuery.ts:119:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts
2536+
// src/core/ObservableQuery.ts:128:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
2537+
// src/core/ObservableQuery.ts:129:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts
25382538
// src/core/QueryManager.ts:159:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
25392539
// src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
25402540
// src/link/http/selectHttpOptionsAndBody.ts:128:32 - (ae-forgotten-export) The symbol "HttpQueryOptions" needs to be exported by the entry point index.d.ts

.api-reports/api-report-react.api.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1717,6 +1717,8 @@ class QueryManager<TStore> {
17171717
getLocalState(): LocalState<TStore>;
17181718
// (undocumented)
17191719
getObservableQueries(include?: InternalRefetchQueriesInclude): Map<string, ObservableQuery<any, OperationVariables>>;
1720+
// (undocumented)
1721+
getOrCreateQuery(queryId: string): QueryInfo;
17201722
// Warning: (ae-forgotten-export) The symbol "QueryStoreValue" needs to be exported by the entry point index.d.ts
17211723
//
17221724
// (undocumented)
@@ -1784,8 +1786,6 @@ class QueryManager<TStore> {
17841786
// (undocumented)
17851787
resetErrors(queryId: string): void;
17861788
// (undocumented)
1787-
setObservableQuery(observableQuery: ObservableQuery<any, any>): void;
1788-
// (undocumented)
17891789
readonly ssrMode: boolean;
17901790
// (undocumented)
17911791
startGraphQLSubscription<T = any>(options: SubscriptionOptions): Observable<FetchResult<T>>;
@@ -2589,8 +2589,8 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
25892589
// src/cache/core/types/common.ts:104:3 - (ae-forgotten-export) The symbol "ToReferenceFunction" needs to be exported by the entry point index.d.ts
25902590
// src/cache/core/types/common.ts:105:3 - (ae-forgotten-export) The symbol "StorageType" needs to be exported by the entry point index.d.ts
25912591
// src/core/LocalState.ts:46:5 - (ae-forgotten-export) The symbol "FragmentMap" needs to be exported by the entry point index.d.ts
2592-
// src/core/ObservableQuery.ts:118:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
2593-
// src/core/ObservableQuery.ts:119:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts
2592+
// src/core/ObservableQuery.ts:128:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
2593+
// src/core/ObservableQuery.ts:129:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts
25942594
// src/core/QueryManager.ts:159:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
25952595
// src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
25962596
// src/core/types.ts:175:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts

.api-reports/api-report-react_components.api.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1530,6 +1530,8 @@ class QueryManager<TStore> {
15301530
getLocalState(): LocalState<TStore>;
15311531
// (undocumented)
15321532
getObservableQueries(include?: InternalRefetchQueriesInclude): Map<string, ObservableQuery<any, OperationVariables>>;
1533+
// (undocumented)
1534+
getOrCreateQuery(queryId: string): QueryInfo;
15331535
// Warning: (ae-forgotten-export) The symbol "QueryStoreValue" needs to be exported by the entry point index.d.ts
15341536
//
15351537
// (undocumented)
@@ -1597,8 +1599,6 @@ class QueryManager<TStore> {
15971599
// (undocumented)
15981600
resetErrors(queryId: string): void;
15991601
// (undocumented)
1600-
setObservableQuery(observableQuery: ObservableQuery<any, any>): void;
1601-
// (undocumented)
16021602
readonly ssrMode: boolean;
16031603
// (undocumented)
16041604
startGraphQLSubscription<T = any>(options: SubscriptionOptions): Observable<FetchResult<T>>;
@@ -2039,8 +2039,8 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
20392039
// src/cache/core/types/common.ts:104:3 - (ae-forgotten-export) The symbol "ToReferenceFunction" needs to be exported by the entry point index.d.ts
20402040
// src/cache/core/types/common.ts:105:3 - (ae-forgotten-export) The symbol "StorageType" needs to be exported by the entry point index.d.ts
20412041
// src/core/LocalState.ts:46:5 - (ae-forgotten-export) The symbol "FragmentMap" needs to be exported by the entry point index.d.ts
2042-
// src/core/ObservableQuery.ts:118:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
2043-
// src/core/ObservableQuery.ts:119:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts
2042+
// src/core/ObservableQuery.ts:128:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
2043+
// src/core/ObservableQuery.ts:129:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts
20442044
// src/core/QueryManager.ts:159:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
20452045
// src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
20462046
// src/core/types.ts:175:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts

.api-reports/api-report-react_context.api.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,8 @@ class QueryManager<TStore> {
14571457
getLocalState(): LocalState<TStore>;
14581458
// (undocumented)
14591459
getObservableQueries(include?: InternalRefetchQueriesInclude): Map<string, ObservableQuery<any, OperationVariables>>;
1460+
// (undocumented)
1461+
getOrCreateQuery(queryId: string): QueryInfo;
14601462
// Warning: (ae-forgotten-export) The symbol "QueryStoreValue" needs to be exported by the entry point index.d.ts
14611463
//
14621464
// (undocumented)
@@ -1524,8 +1526,6 @@ class QueryManager<TStore> {
15241526
// (undocumented)
15251527
resetErrors(queryId: string): void;
15261528
// (undocumented)
1527-
setObservableQuery(observableQuery: ObservableQuery<any, any>): void;
1528-
// (undocumented)
15291529
readonly ssrMode: boolean;
15301530
// (undocumented)
15311531
startGraphQLSubscription<T = any>(options: SubscriptionOptions): Observable<FetchResult<T>>;
@@ -1958,8 +1958,8 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
19581958
// src/cache/core/types/common.ts:104:3 - (ae-forgotten-export) The symbol "ToReferenceFunction" needs to be exported by the entry point index.d.ts
19591959
// src/cache/core/types/common.ts:105:3 - (ae-forgotten-export) The symbol "StorageType" needs to be exported by the entry point index.d.ts
19601960
// src/core/LocalState.ts:46:5 - (ae-forgotten-export) The symbol "FragmentMap" needs to be exported by the entry point index.d.ts
1961-
// src/core/ObservableQuery.ts:118:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
1962-
// src/core/ObservableQuery.ts:119:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts
1961+
// src/core/ObservableQuery.ts:128:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
1962+
// src/core/ObservableQuery.ts:129:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts
19631963
// src/core/QueryManager.ts:159:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
19641964
// src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
19651965
// src/core/types.ts:175:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts

.api-reports/api-report-react_hoc.api.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1498,6 +1498,8 @@ class QueryManager<TStore> {
14981498
getLocalState(): LocalState<TStore>;
14991499
// (undocumented)
15001500
getObservableQueries(include?: InternalRefetchQueriesInclude): Map<string, ObservableQuery<any, OperationVariables>>;
1501+
// (undocumented)
1502+
getOrCreateQuery(queryId: string): QueryInfo;
15011503
// Warning: (ae-forgotten-export) The symbol "QueryStoreValue" needs to be exported by the entry point index.d.ts
15021504
//
15031505
// (undocumented)
@@ -1565,8 +1567,6 @@ class QueryManager<TStore> {
15651567
// (undocumented)
15661568
resetErrors(queryId: string): void;
15671569
// (undocumented)
1568-
setObservableQuery(observableQuery: ObservableQuery<any, any>): void;
1569-
// (undocumented)
15701570
readonly ssrMode: boolean;
15711571
// (undocumented)
15721572
startGraphQLSubscription<T = any>(options: SubscriptionOptions): Observable<FetchResult<T>>;
@@ -1969,8 +1969,8 @@ export function withSubscription<TProps extends TGraphQLVariables | {} = {}, TDa
19691969
// src/cache/core/types/common.ts:104:3 - (ae-forgotten-export) The symbol "ToReferenceFunction" needs to be exported by the entry point index.d.ts
19701970
// src/cache/core/types/common.ts:105:3 - (ae-forgotten-export) The symbol "StorageType" needs to be exported by the entry point index.d.ts
19711971
// src/core/LocalState.ts:46:5 - (ae-forgotten-export) The symbol "FragmentMap" needs to be exported by the entry point index.d.ts
1972-
// src/core/ObservableQuery.ts:118:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
1973-
// src/core/ObservableQuery.ts:119:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts
1972+
// src/core/ObservableQuery.ts:128:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
1973+
// src/core/ObservableQuery.ts:129:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts
19741974
// src/core/QueryManager.ts:159:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
19751975
// src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
19761976
// src/core/types.ts:175:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts

.api-reports/api-report-react_hooks.api.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1588,6 +1588,8 @@ class QueryManager<TStore> {
15881588
getLocalState(): LocalState<TStore>;
15891589
// (undocumented)
15901590
getObservableQueries(include?: InternalRefetchQueriesInclude): Map<string, ObservableQuery<any, OperationVariables>>;
1591+
// (undocumented)
1592+
getOrCreateQuery(queryId: string): QueryInfo;
15911593
// Warning: (ae-forgotten-export) The symbol "QueryStoreValue" needs to be exported by the entry point index.d.ts
15921594
//
15931595
// (undocumented)
@@ -1655,8 +1657,6 @@ class QueryManager<TStore> {
16551657
// (undocumented)
16561658
resetErrors(queryId: string): void;
16571659
// (undocumented)
1658-
setObservableQuery(observableQuery: ObservableQuery<any, any>): void;
1659-
// (undocumented)
16601660
readonly ssrMode: boolean;
16611661
// (undocumented)
16621662
startGraphQLSubscription<T = any>(options: SubscriptionOptions): Observable<FetchResult<T>>;
@@ -2428,8 +2428,8 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
24282428
// src/cache/core/types/common.ts:104:3 - (ae-forgotten-export) The symbol "ToReferenceFunction" needs to be exported by the entry point index.d.ts
24292429
// src/cache/core/types/common.ts:105:3 - (ae-forgotten-export) The symbol "StorageType" needs to be exported by the entry point index.d.ts
24302430
// src/core/LocalState.ts:46:5 - (ae-forgotten-export) The symbol "FragmentMap" needs to be exported by the entry point index.d.ts
2431-
// src/core/ObservableQuery.ts:118:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
2432-
// src/core/ObservableQuery.ts:119:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts
2431+
// src/core/ObservableQuery.ts:128:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
2432+
// src/core/ObservableQuery.ts:129:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts
24332433
// src/core/QueryManager.ts:159:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
24342434
// src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
24352435
// src/core/types.ts:175:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts

.api-reports/api-report-react_internal.api.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1689,6 +1689,8 @@ class QueryManager<TStore> {
16891689
getLocalState(): LocalState<TStore>;
16901690
// (undocumented)
16911691
getObservableQueries(include?: InternalRefetchQueriesInclude): Map<string, ObservableQuery<any, OperationVariables>>;
1692+
// (undocumented)
1693+
getOrCreateQuery(queryId: string): QueryInfo;
16921694
// Warning: (ae-forgotten-export) The symbol "QueryStoreValue" needs to be exported by the entry point index.d.ts
16931695
//
16941696
// (undocumented)
@@ -1756,8 +1758,6 @@ class QueryManager<TStore> {
17561758
// (undocumented)
17571759
resetErrors(queryId: string): void;
17581760
// (undocumented)
1759-
setObservableQuery(observableQuery: ObservableQuery<any, any>): void;
1760-
// (undocumented)
17611761
readonly ssrMode: boolean;
17621762
// (undocumented)
17631763
startGraphQLSubscription<T = any>(options: SubscriptionOptions): Observable<FetchResult<T>>;
@@ -2540,8 +2540,8 @@ export function wrapQueryRef<TData, TVariables extends OperationVariables>(inter
25402540
// src/cache/core/types/common.ts:104:3 - (ae-forgotten-export) The symbol "ToReferenceFunction" needs to be exported by the entry point index.d.ts
25412541
// src/cache/core/types/common.ts:105:3 - (ae-forgotten-export) The symbol "StorageType" needs to be exported by the entry point index.d.ts
25422542
// src/core/LocalState.ts:46:5 - (ae-forgotten-export) The symbol "FragmentMap" needs to be exported by the entry point index.d.ts
2543-
// src/core/ObservableQuery.ts:118:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
2544-
// src/core/ObservableQuery.ts:119:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts
2543+
// src/core/ObservableQuery.ts:128:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
2544+
// src/core/ObservableQuery.ts:129:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts
25452545
// src/core/QueryManager.ts:159:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
25462546
// src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
25472547
// src/core/types.ts:175:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts

.api-reports/api-report-react_ssr.api.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,8 @@ class QueryManager<TStore> {
14421442
getLocalState(): LocalState<TStore>;
14431443
// (undocumented)
14441444
getObservableQueries(include?: InternalRefetchQueriesInclude): Map<string, ObservableQuery<any, OperationVariables>>;
1445+
// (undocumented)
1446+
getOrCreateQuery(queryId: string): QueryInfo;
14451447
// Warning: (ae-forgotten-export) The symbol "QueryStoreValue" needs to be exported by the entry point index.d.ts
14461448
//
14471449
// (undocumented)
@@ -1509,8 +1511,6 @@ class QueryManager<TStore> {
15091511
// (undocumented)
15101512
resetErrors(queryId: string): void;
15111513
// (undocumented)
1512-
setObservableQuery(observableQuery: ObservableQuery<any, any>): void;
1513-
// (undocumented)
15141514
readonly ssrMode: boolean;
15151515
// (undocumented)
15161516
startGraphQLSubscription<T = any>(options: SubscriptionOptions): Observable<FetchResult<T>>;
@@ -1943,8 +1943,8 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
19431943
// src/cache/core/types/common.ts:104:3 - (ae-forgotten-export) The symbol "ToReferenceFunction" needs to be exported by the entry point index.d.ts
19441944
// src/cache/core/types/common.ts:105:3 - (ae-forgotten-export) The symbol "StorageType" needs to be exported by the entry point index.d.ts
19451945
// src/core/LocalState.ts:46:5 - (ae-forgotten-export) The symbol "FragmentMap" needs to be exported by the entry point index.d.ts
1946-
// src/core/ObservableQuery.ts:118:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
1947-
// src/core/ObservableQuery.ts:119:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts
1946+
// src/core/ObservableQuery.ts:128:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
1947+
// src/core/ObservableQuery.ts:129:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts
19481948
// src/core/QueryManager.ts:159:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
19491949
// src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
19501950
// src/core/types.ts:175:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts

0 commit comments

Comments
 (0)