Skip to content

Commit 0098932

Browse files
authored
refactor some code in QueryInfo (#12540)
* refactor: do away with `QueryInfo.listeners` * remove incorrect `info.reset` call, call `cache.diff` directly * remove obsolete `QueryListener` type * remove obsolete import * inline `shouldNotify` * move `cancelNotifyTimeout` onto `QueryInfo`, move methods together, create `scheduleNotify` method * move notify-related code from `QueryInfo` to `ObservableQuery` * move `reobserveCacheFirst` into a private method * changesets * chores, method visibility * size limits * type adjustment * PR feedback
1 parent 949bd14 commit 0098932

21 files changed

+214
-283
lines changed

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,6 +1692,8 @@ export class ObservableQuery<TData = any, TVariables extends OperationVariables
16921692
hasObservers(): boolean;
16931693
// (undocumented)
16941694
isDifferentFromLastResult(newResult: ApolloQueryResult<TData>, variables?: TVariables): boolean | undefined;
1695+
// @internal (undocumented)
1696+
protected notify(): void;
16951697
// (undocumented)
16961698
readonly options: WatchQueryOptions<TVariables, TData>;
16971699
// (undocumented)
@@ -1711,6 +1713,8 @@ export class ObservableQuery<TData = any, TVariables extends OperationVariables
17111713
resetDiff(): void;
17121714
// (undocumented)
17131715
resetLastResults(): void;
1716+
// @internal (undocumented)
1717+
protected resetNotifications(): void;
17141718
// (undocumented)
17151719
resetQueryStoreErrors(): void;
17161720
// (undocumented)
@@ -1719,6 +1723,8 @@ export class ObservableQuery<TData = any, TVariables extends OperationVariables
17191723
resubscribeAfterError(observer: Observer<ApolloQueryResult<TData>>): ObservableSubscription;
17201724
// (undocumented)
17211725
result(): Promise<ApolloQueryResult<MaybeMasked<TData>>>;
1726+
// @internal (undocumented)
1727+
protected scheduleNotify(): void;
17221728
// (undocumented)
17231729
setOptions(newOptions: Partial<WatchQueryOptions<TVariables, TData>>): Promise<ApolloQueryResult<MaybeMasked<TData>>>;
17241730
setVariables(variables: TVariables): Promise<ApolloQueryResult<MaybeMasked<TData>> | void>;
@@ -1864,8 +1870,6 @@ class QueryInfo {
18641870
// (undocumented)
18651871
lastRequestId: number;
18661872
// (undocumented)
1867-
listeners: Set<QueryListener>;
1868-
// (undocumented)
18691873
markError(error: ApolloError): ApolloError;
18701874
// (undocumented)
18711875
markReady(): NetworkStatus;
@@ -1878,14 +1882,10 @@ class QueryInfo {
18781882
// (undocumented)
18791883
networkStatus?: NetworkStatus;
18801884
// (undocumented)
1881-
notify(): void;
1882-
// (undocumented)
18831885
readonly observableQuery: ObservableQuery<any, any> | null;
18841886
// (undocumented)
18851887
readonly queryId: string;
18861888
// (undocumented)
1887-
reset(): void;
1888-
// (undocumented)
18891889
resetDiff(): void;
18901890
// (undocumented)
18911891
resetLastWrite(): void;
@@ -1901,9 +1901,6 @@ class QueryInfo {
19011901
variables?: Record<string, any>;
19021902
}
19031903

1904-
// @public (undocumented)
1905-
export type QueryListener = (queryInfo: QueryInfo) => void;
1906-
19071904
// @public (undocumented)
19081905
class QueryManager<TStore> {
19091906
// Warning: (ae-forgotten-export) The symbol "QueryManagerOptions" needs to be exported by the entry point index.d.ts

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,8 @@ class ObservableQuery<TData = any, TVariables extends OperationVariables = Opera
14011401
hasObservers(): boolean;
14021402
// (undocumented)
14031403
isDifferentFromLastResult(newResult: ApolloQueryResult<TData>, variables?: TVariables): boolean | undefined;
1404+
// @internal (undocumented)
1405+
protected notify(): void;
14041406
// (undocumented)
14051407
readonly options: WatchQueryOptions<TVariables, TData>;
14061408
// (undocumented)
@@ -1420,6 +1422,8 @@ class ObservableQuery<TData = any, TVariables extends OperationVariables = Opera
14201422
resetDiff(): void;
14211423
// (undocumented)
14221424
resetLastResults(): void;
1425+
// @internal (undocumented)
1426+
protected resetNotifications(): void;
14231427
// (undocumented)
14241428
resetQueryStoreErrors(): void;
14251429
// (undocumented)
@@ -1428,6 +1432,8 @@ class ObservableQuery<TData = any, TVariables extends OperationVariables = Opera
14281432
resubscribeAfterError(observer: Observer<ApolloQueryResult<TData>>): Subscription;
14291433
// (undocumented)
14301434
result(): Promise<ApolloQueryResult<MaybeMasked<TData>>>;
1435+
// @internal (undocumented)
1436+
protected scheduleNotify(): void;
14311437
// (undocumented)
14321438
setOptions(newOptions: Partial<WatchQueryOptions<TVariables, TData>>): Promise<ApolloQueryResult<MaybeMasked<TData>>>;
14331439
setVariables(variables: TVariables): Promise<ApolloQueryResult<MaybeMasked<TData>> | void>;
@@ -1626,10 +1632,6 @@ class QueryInfo {
16261632
}): this;
16271633
// (undocumented)
16281634
lastRequestId: number;
1629-
// Warning: (ae-forgotten-export) The symbol "QueryListener" needs to be exported by the entry point index.d.ts
1630-
//
1631-
// (undocumented)
1632-
listeners: Set<QueryListener>;
16331635
// (undocumented)
16341636
markError(error: ApolloError): ApolloError;
16351637
// (undocumented)
@@ -1643,14 +1645,10 @@ class QueryInfo {
16431645
// (undocumented)
16441646
networkStatus?: NetworkStatus;
16451647
// (undocumented)
1646-
notify(): void;
1647-
// (undocumented)
16481648
readonly observableQuery: ObservableQuery<any, any> | null;
16491649
// (undocumented)
16501650
readonly queryId: string;
16511651
// (undocumented)
1652-
reset(): void;
1653-
// (undocumented)
16541652
resetDiff(): void;
16551653
// (undocumented)
16561654
resetLastWrite(): void;
@@ -1672,9 +1670,6 @@ export interface QueryLazyOptions<TVariables> {
16721670
variables?: TVariables;
16731671
}
16741672

1675-
// @public (undocumented)
1676-
type QueryListener = (queryInfo: QueryInfo) => void;
1677-
16781673
// @public (undocumented)
16791674
class QueryManager<TStore> {
16801675
// Warning: (ae-forgotten-export) The symbol "QueryManagerOptions" needs to be exported by the entry point index.d.ts
@@ -2593,8 +2588,8 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
25932588
// src/core/ObservableQuery.ts:129:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts
25942589
// src/core/QueryManager.ts:159:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
25952590
// src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
2596-
// src/core/types.ts:175:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts
2597-
// src/core/types.ts:204:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts
2591+
// src/core/types.ts:172:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts
2592+
// src/core/types.ts:201:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts
25982593
// src/core/watchQueryOptions.ts:357:2 - (ae-forgotten-export) The symbol "UpdateQueryOptions" needs to be exported by the entry point index.d.ts
25992594
// src/react/hooks/useBackgroundQuery.ts:51:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts
26002595
// src/react/hooks/useBackgroundQuery.ts:75:4 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,8 @@ class ObservableQuery<TData = any, TVariables extends OperationVariables = Opera
12721272
hasObservers(): boolean;
12731273
// (undocumented)
12741274
isDifferentFromLastResult(newResult: ApolloQueryResult<TData>, variables?: TVariables): boolean | undefined;
1275+
// @internal (undocumented)
1276+
protected notify(): void;
12751277
// (undocumented)
12761278
readonly options: WatchQueryOptions<TVariables, TData>;
12771279
// (undocumented)
@@ -1291,6 +1293,8 @@ class ObservableQuery<TData = any, TVariables extends OperationVariables = Opera
12911293
resetDiff(): void;
12921294
// (undocumented)
12931295
resetLastResults(): void;
1296+
// @internal (undocumented)
1297+
protected resetNotifications(): void;
12941298
// (undocumented)
12951299
resetQueryStoreErrors(): void;
12961300
// (undocumented)
@@ -1299,6 +1303,8 @@ class ObservableQuery<TData = any, TVariables extends OperationVariables = Opera
12991303
resubscribeAfterError(observer: Observer<ApolloQueryResult<TData>>): Subscription_2;
13001304
// (undocumented)
13011305
result(): Promise<ApolloQueryResult<MaybeMasked<TData>>>;
1306+
// @internal (undocumented)
1307+
protected scheduleNotify(): void;
13021308
// (undocumented)
13031309
setOptions(newOptions: Partial<WatchQueryOptions<TVariables, TData>>): Promise<ApolloQueryResult<MaybeMasked<TData>>>;
13041310
setVariables(variables: TVariables): Promise<ApolloQueryResult<MaybeMasked<TData>> | void>;
@@ -1445,10 +1451,6 @@ class QueryInfo {
14451451
}): this;
14461452
// (undocumented)
14471453
lastRequestId: number;
1448-
// Warning: (ae-forgotten-export) The symbol "QueryListener" needs to be exported by the entry point index.d.ts
1449-
//
1450-
// (undocumented)
1451-
listeners: Set<QueryListener>;
14521454
// (undocumented)
14531455
markError(error: ApolloError): ApolloError;
14541456
// (undocumented)
@@ -1462,14 +1464,10 @@ class QueryInfo {
14621464
// (undocumented)
14631465
networkStatus?: NetworkStatus;
14641466
// (undocumented)
1465-
notify(): void;
1466-
// (undocumented)
14671467
readonly observableQuery: ObservableQuery<any, any> | null;
14681468
// (undocumented)
14691469
readonly queryId: string;
14701470
// (undocumented)
1471-
reset(): void;
1472-
// (undocumented)
14731471
resetDiff(): void;
14741472
// (undocumented)
14751473
resetLastWrite(): void;
@@ -1485,9 +1483,6 @@ class QueryInfo {
14851483
variables?: Record<string, any>;
14861484
}
14871485

1488-
// @public (undocumented)
1489-
type QueryListener = (queryInfo: QueryInfo) => void;
1490-
14911486
// @public (undocumented)
14921487
class QueryManager<TStore> {
14931488
// Warning: (ae-forgotten-export) The symbol "QueryManagerOptions" needs to be exported by the entry point index.d.ts
@@ -2043,8 +2038,8 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
20432038
// src/core/ObservableQuery.ts:129:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts
20442039
// src/core/QueryManager.ts:159:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
20452040
// src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
2046-
// src/core/types.ts:175:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts
2047-
// src/core/types.ts:204:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts
2041+
// src/core/types.ts:172:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts
2042+
// src/core/types.ts:201:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts
20482043
// src/core/watchQueryOptions.ts:357:2 - (ae-forgotten-export) The symbol "UpdateQueryOptions" needs to be exported by the entry point index.d.ts
20492044

20502045
// (No @packageDocumentation comment for this package)

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,8 @@ class ObservableQuery<TData = any, TVariables extends OperationVariables = Opera
12251225
hasObservers(): boolean;
12261226
// (undocumented)
12271227
isDifferentFromLastResult(newResult: ApolloQueryResult<TData>, variables?: TVariables): boolean | undefined;
1228+
// @internal (undocumented)
1229+
protected notify(): void;
12281230
// (undocumented)
12291231
readonly options: WatchQueryOptions<TVariables, TData>;
12301232
// (undocumented)
@@ -1244,6 +1246,8 @@ class ObservableQuery<TData = any, TVariables extends OperationVariables = Opera
12441246
resetDiff(): void;
12451247
// (undocumented)
12461248
resetLastResults(): void;
1249+
// @internal (undocumented)
1250+
protected resetNotifications(): void;
12471251
// (undocumented)
12481252
resetQueryStoreErrors(): void;
12491253
// (undocumented)
@@ -1252,6 +1256,8 @@ class ObservableQuery<TData = any, TVariables extends OperationVariables = Opera
12521256
resubscribeAfterError(observer: Observer<ApolloQueryResult<TData>>): Subscription;
12531257
// (undocumented)
12541258
result(): Promise<ApolloQueryResult<MaybeMasked<TData>>>;
1259+
// @internal (undocumented)
1260+
protected scheduleNotify(): void;
12551261
// (undocumented)
12561262
setOptions(newOptions: Partial<WatchQueryOptions<TVariables, TData>>): Promise<ApolloQueryResult<MaybeMasked<TData>>>;
12571263
setVariables(variables: TVariables): Promise<ApolloQueryResult<MaybeMasked<TData>> | void>;
@@ -1372,10 +1378,6 @@ class QueryInfo {
13721378
}): this;
13731379
// (undocumented)
13741380
lastRequestId: number;
1375-
// Warning: (ae-forgotten-export) The symbol "QueryListener" needs to be exported by the entry point index.d.ts
1376-
//
1377-
// (undocumented)
1378-
listeners: Set<QueryListener>;
13791381
// (undocumented)
13801382
markError(error: ApolloError): ApolloError;
13811383
// (undocumented)
@@ -1389,14 +1391,10 @@ class QueryInfo {
13891391
// (undocumented)
13901392
networkStatus?: NetworkStatus;
13911393
// (undocumented)
1392-
notify(): void;
1393-
// (undocumented)
13941394
readonly observableQuery: ObservableQuery<any, any> | null;
13951395
// (undocumented)
13961396
readonly queryId: string;
13971397
// (undocumented)
1398-
reset(): void;
1399-
// (undocumented)
14001398
resetDiff(): void;
14011399
// (undocumented)
14021400
resetLastWrite(): void;
@@ -1412,9 +1410,6 @@ class QueryInfo {
14121410
variables?: Record<string, any>;
14131411
}
14141412

1415-
// @public (undocumented)
1416-
type QueryListener = (queryInfo: QueryInfo) => void;
1417-
14181413
// @public (undocumented)
14191414
class QueryManager<TStore> {
14201415
// Warning: (ae-forgotten-export) The symbol "QueryManagerOptions" needs to be exported by the entry point index.d.ts
@@ -1962,8 +1957,8 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
19621957
// src/core/ObservableQuery.ts:129:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts
19631958
// src/core/QueryManager.ts:159:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
19641959
// src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
1965-
// src/core/types.ts:175:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts
1966-
// src/core/types.ts:204:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts
1960+
// src/core/types.ts:172:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts
1961+
// src/core/types.ts:201:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts
19671962
// src/core/watchQueryOptions.ts:357:2 - (ae-forgotten-export) The symbol "UpdateQueryOptions" needs to be exported by the entry point index.d.ts
19681963

19691964
// (No @packageDocumentation comment for this package)

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,8 @@ class ObservableQuery<TData = any, TVariables extends OperationVariables = Opera
12651265
hasObservers(): boolean;
12661266
// (undocumented)
12671267
isDifferentFromLastResult(newResult: ApolloQueryResult<TData>, variables?: TVariables): boolean | undefined;
1268+
// @internal (undocumented)
1269+
protected notify(): void;
12681270
// (undocumented)
12691271
readonly options: WatchQueryOptions<TVariables, TData>;
12701272
// (undocumented)
@@ -1284,6 +1286,8 @@ class ObservableQuery<TData = any, TVariables extends OperationVariables = Opera
12841286
resetDiff(): void;
12851287
// (undocumented)
12861288
resetLastResults(): void;
1289+
// @internal (undocumented)
1290+
protected resetNotifications(): void;
12871291
// (undocumented)
12881292
resetQueryStoreErrors(): void;
12891293
// (undocumented)
@@ -1292,6 +1296,8 @@ class ObservableQuery<TData = any, TVariables extends OperationVariables = Opera
12921296
resubscribeAfterError(observer: Observer<ApolloQueryResult<TData>>): Subscription;
12931297
// (undocumented)
12941298
result(): Promise<ApolloQueryResult<MaybeMasked<TData>>>;
1299+
// @internal (undocumented)
1300+
protected scheduleNotify(): void;
12951301
// (undocumented)
12961302
setOptions(newOptions: Partial<WatchQueryOptions<TVariables, TData>>): Promise<ApolloQueryResult<MaybeMasked<TData>>>;
12971303
setVariables(variables: TVariables): Promise<ApolloQueryResult<MaybeMasked<TData>> | void>;
@@ -1413,10 +1419,6 @@ class QueryInfo {
14131419
}): this;
14141420
// (undocumented)
14151421
lastRequestId: number;
1416-
// Warning: (ae-forgotten-export) The symbol "QueryListener" needs to be exported by the entry point index.d.ts
1417-
//
1418-
// (undocumented)
1419-
listeners: Set<QueryListener>;
14201422
// (undocumented)
14211423
markError(error: ApolloError): ApolloError;
14221424
// (undocumented)
@@ -1430,14 +1432,10 @@ class QueryInfo {
14301432
// (undocumented)
14311433
networkStatus?: NetworkStatus;
14321434
// (undocumented)
1433-
notify(): void;
1434-
// (undocumented)
14351435
readonly observableQuery: ObservableQuery<any, any> | null;
14361436
// (undocumented)
14371437
readonly queryId: string;
14381438
// (undocumented)
1439-
reset(): void;
1440-
// (undocumented)
14411439
resetDiff(): void;
14421440
// (undocumented)
14431441
resetLastWrite(): void;
@@ -1453,9 +1451,6 @@ class QueryInfo {
14531451
variables?: Record<string, any>;
14541452
}
14551453

1456-
// @public (undocumented)
1457-
type QueryListener = (queryInfo: QueryInfo) => void;
1458-
14591454
// @public (undocumented)
14601455
class QueryManager<TStore> {
14611456
// Warning: (ae-forgotten-export) The symbol "QueryManagerOptions" needs to be exported by the entry point index.d.ts
@@ -1973,8 +1968,8 @@ export function withSubscription<TProps extends TGraphQLVariables | {} = {}, TDa
19731968
// src/core/ObservableQuery.ts:129:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts
19741969
// src/core/QueryManager.ts:159:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
19751970
// src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
1976-
// src/core/types.ts:175:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts
1977-
// src/core/types.ts:204:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts
1971+
// src/core/types.ts:172:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts
1972+
// src/core/types.ts:201:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts
19781973
// src/core/watchQueryOptions.ts:357:2 - (ae-forgotten-export) The symbol "UpdateQueryOptions" needs to be exported by the entry point index.d.ts
19791974

19801975
// (No @packageDocumentation comment for this package)

0 commit comments

Comments
 (0)