Skip to content

Commit 670f112

Browse files
authoredFeb 6, 2025··
Provide type-safe solution for updateQuery previous data (#12276)
1 parent 5031837 commit 670f112

36 files changed

+1063
-356
lines changed
 

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

+42-18
Original file line numberDiff line numberDiff line change
@@ -1726,8 +1726,8 @@ export class ObservableQuery<TData = any, TVariables extends OperationVariables
17261726
silentSetOptions(newOptions: Partial<WatchQueryOptions<TVariables, TData>>): void;
17271727
startPolling(pollInterval: number): void;
17281728
stopPolling(): void;
1729-
subscribeToMore<TSubscriptionData = TData, TSubscriptionVariables extends OperationVariables = TVariables>(options: SubscribeToMoreOptions<TData, TSubscriptionVariables, TSubscriptionData>): () => void;
1730-
updateQuery<TVars extends OperationVariables = TVariables>(mapFn: (previousQueryResult: Unmasked<TData>, options: Pick<WatchQueryOptions<TVars, TData>, "variables">) => Unmasked<TData>): void;
1729+
subscribeToMore<TSubscriptionData = TData, TSubscriptionVariables extends OperationVariables = TVariables>(options: SubscribeToMoreOptions<TData, TSubscriptionVariables, TSubscriptionData, TVariables>): () => void;
1730+
updateQuery(mapFn: UpdateQueryMapFn<TData, TVariables>): void;
17311731
get variables(): TVariables | undefined;
17321732
}
17331733

@@ -2317,12 +2317,33 @@ class Stump extends Layer {
23172317
}
23182318

23192319
// @public (undocumented)
2320-
export type SubscribeToMoreOptions<TData = any, TSubscriptionVariables = OperationVariables, TSubscriptionData = TData> = {
2320+
export interface SubscribeToMoreFunction<TData, TVariables extends OperationVariables = OperationVariables> {
2321+
// (undocumented)
2322+
<TSubscriptionData = TData, TSubscriptionVariables extends OperationVariables = TVariables>(options: SubscribeToMoreOptions<TData, TSubscriptionVariables, TSubscriptionData, TVariables>): () => void;
2323+
}
2324+
2325+
// @public (undocumented)
2326+
export interface SubscribeToMoreOptions<TData = any, TSubscriptionVariables extends OperationVariables = OperationVariables, TSubscriptionData = TData, TVariables extends OperationVariables = TSubscriptionVariables> {
2327+
// (undocumented)
2328+
context?: DefaultContext;
2329+
// (undocumented)
23212330
document: DocumentNode | TypedDocumentNode<TSubscriptionData, TSubscriptionVariables>;
2322-
variables?: TSubscriptionVariables;
2323-
updateQuery?: UpdateQueryFn<TData, TSubscriptionVariables, TSubscriptionData>;
2331+
// (undocumented)
23242332
onError?: (error: Error) => void;
2325-
context?: DefaultContext;
2333+
// (undocumented)
2334+
updateQuery?: SubscribeToMoreUpdateQueryFn<TData, TVariables, TSubscriptionData>;
2335+
// (undocumented)
2336+
variables?: TSubscriptionVariables;
2337+
}
2338+
2339+
// @public (undocumented)
2340+
export type SubscribeToMoreUpdateQueryFn<TData = any, TVariables extends OperationVariables = OperationVariables, TSubscriptionData = TData> = {
2341+
(
2342+
unsafePreviousData: Unmasked<TData>, options: UpdateQueryOptions<TData, TVariables> & {
2343+
subscriptionData: {
2344+
data: Unmasked<TSubscriptionData>;
2345+
};
2346+
}): Unmasked<TData> | void;
23262347
};
23272348

23282349
// @public (undocumented)
@@ -2421,18 +2442,22 @@ type UnwrapFragmentRefs<TData> = true extends IsAny<TData> ? TData : TData exten
24212442
type UpdateQueries<TData> = MutationOptions<TData, any, any>["updateQueries"];
24222443

24232444
// @public (undocumented)
2424-
type UpdateQueryFn<TData = any, TSubscriptionVariables = OperationVariables, TSubscriptionData = TData> = (previousQueryResult: Unmasked<TData>, options: {
2425-
subscriptionData: {
2426-
data: Unmasked<TSubscriptionData>;
2427-
};
2428-
variables?: TSubscriptionVariables;
2429-
}) => Unmasked<TData>;
2445+
export interface UpdateQueryMapFn<TData = any, TVariables = OperationVariables> {
2446+
// (undocumented)
2447+
(
2448+
unsafePreviousData: Unmasked<TData>, options: UpdateQueryOptions<TData, TVariables>): Unmasked<TData> | void;
2449+
}
24302450

24312451
// @public (undocumented)
2432-
export interface UpdateQueryOptions<TVariables> {
2433-
// (undocumented)
2452+
export type UpdateQueryOptions<TData, TVariables> = {
24342453
variables?: TVariables;
2435-
}
2454+
} & ({
2455+
complete: true;
2456+
previousData: Unmasked<TData>;
2457+
} | {
2458+
complete: false;
2459+
previousData: DeepPartial<Unmasked<TData>> | undefined;
2460+
});
24362461

24372462
// @public (undocumented)
24382463
export interface UriFunction {
@@ -2508,11 +2533,10 @@ interface WriteContext extends ReadMergeModifyContext {
25082533
// src/cache/inmemory/policies.ts:162:3 - (ae-forgotten-export) The symbol "KeySpecifier" needs to be exported by the entry point index.d.ts
25092534
// src/cache/inmemory/policies.ts:162:3 - (ae-forgotten-export) The symbol "KeyArgsFunction" needs to be exported by the entry point index.d.ts
25102535
// src/cache/inmemory/types.ts:139:3 - (ae-forgotten-export) The symbol "KeyFieldsFunction" needs to be exported by the entry point index.d.ts
2511-
// src/core/ObservableQuery.ts:120:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
2512-
// src/core/ObservableQuery.ts:121:5 - (ae-forgotten-export) The symbol "QueryInfo" 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
25132538
// src/core/QueryManager.ts:159:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
25142539
// src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
2515-
// src/core/watchQueryOptions.ts:277:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
25162540
// src/link/http/selectHttpOptionsAndBody.ts:128:32 - (ae-forgotten-export) The symbol "HttpQueryOptions" needs to be exported by the entry point index.d.ts
25172541

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

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

+52-21
Original file line numberDiff line numberDiff line change
@@ -1434,8 +1434,9 @@ class ObservableQuery<TData = any, TVariables extends OperationVariables = Opera
14341434
startPolling(pollInterval: number): void;
14351435
stopPolling(): void;
14361436
// Warning: (ae-forgotten-export) The symbol "SubscribeToMoreOptions" needs to be exported by the entry point index.d.ts
1437-
subscribeToMore<TSubscriptionData = TData, TSubscriptionVariables extends OperationVariables = TVariables>(options: SubscribeToMoreOptions<TData, TSubscriptionVariables, TSubscriptionData>): () => void;
1438-
updateQuery<TVars extends OperationVariables = TVariables>(mapFn: (previousQueryResult: Unmasked<TData>, options: Pick<WatchQueryOptions<TVars, TData>, "variables">) => Unmasked<TData>): void;
1437+
subscribeToMore<TSubscriptionData = TData, TSubscriptionVariables extends OperationVariables = TVariables>(options: SubscribeToMoreOptions<TData, TSubscriptionVariables, TSubscriptionData, TVariables>): () => void;
1438+
// Warning: (ae-forgotten-export) The symbol "UpdateQueryMapFn" needs to be exported by the entry point index.d.ts
1439+
updateQuery(mapFn: UpdateQueryMapFn<TData, TVariables>): void;
14391440
get variables(): TVariables | undefined;
14401441
}
14411442

@@ -1452,8 +1453,9 @@ export interface ObservableQueryFields<TData, TVariables extends OperationVariab
14521453
reobserve: (newOptions?: Partial<WatchQueryOptions<TVariables, TData>>, newNetworkStatus?: NetworkStatus) => Promise<ApolloQueryResult<MaybeMasked<TData>>>;
14531454
startPolling: (pollInterval: number) => void;
14541455
stopPolling: () => void;
1455-
subscribeToMore: <TSubscriptionData = TData, TSubscriptionVariables extends OperationVariables = TVariables>(options: SubscribeToMoreOptions<TData, TSubscriptionVariables, TSubscriptionData>) => () => void;
1456-
updateQuery: <TVars extends OperationVariables = TVariables>(mapFn: (previousQueryResult: Unmasked<TData>, options: Pick<WatchQueryOptions<TVars, TData>, "variables">) => Unmasked<TData>) => void;
1456+
// Warning: (ae-forgotten-export) The symbol "SubscribeToMoreFunction" needs to be exported by the entry point index.d.ts
1457+
subscribeToMore: SubscribeToMoreFunction<TData, TVariables>;
1458+
updateQuery: (mapFn: UpdateQueryMapFn<TData, TVariables>) => void;
14571459
variables: TVariables | undefined;
14581460
}
14591461

@@ -2093,15 +2095,35 @@ Item
20932095
type StoreValue = number | string | string[] | Reference | Reference[] | null | undefined | void | Object;
20942096

20952097
// @public (undocumented)
2096-
type SubscribeToMoreFunction<TData, TVariables extends OperationVariables> = ObservableQueryFields<TData, TVariables>["subscribeToMore"];
2098+
interface SubscribeToMoreFunction<TData, TVariables extends OperationVariables = OperationVariables> {
2099+
// (undocumented)
2100+
<TSubscriptionData = TData, TSubscriptionVariables extends OperationVariables = TVariables>(options: SubscribeToMoreOptions<TData, TSubscriptionVariables, TSubscriptionData, TVariables>): () => void;
2101+
}
20972102

20982103
// @public (undocumented)
2099-
type SubscribeToMoreOptions<TData = any, TSubscriptionVariables = OperationVariables, TSubscriptionData = TData> = {
2104+
interface SubscribeToMoreOptions<TData = any, TSubscriptionVariables extends OperationVariables = OperationVariables, TSubscriptionData = TData, TVariables extends OperationVariables = TSubscriptionVariables> {
2105+
// (undocumented)
2106+
context?: Context;
2107+
// (undocumented)
21002108
document: DocumentNode | TypedDocumentNode<TSubscriptionData, TSubscriptionVariables>;
2101-
variables?: TSubscriptionVariables;
2102-
updateQuery?: UpdateQueryFn<TData, TSubscriptionVariables, TSubscriptionData>;
2109+
// (undocumented)
21032110
onError?: (error: Error) => void;
2104-
context?: Context;
2111+
// Warning: (ae-forgotten-export) The symbol "SubscribeToMoreUpdateQueryFn" needs to be exported by the entry point index.d.ts
2112+
//
2113+
// (undocumented)
2114+
updateQuery?: SubscribeToMoreUpdateQueryFn<TData, TVariables, TSubscriptionData>;
2115+
// (undocumented)
2116+
variables?: TSubscriptionVariables;
2117+
}
2118+
2119+
// @public (undocumented)
2120+
type SubscribeToMoreUpdateQueryFn<TData = any, TVariables extends OperationVariables = OperationVariables, TSubscriptionData = TData> = {
2121+
(
2122+
unsafePreviousData: Unmasked<TData>, options: UpdateQueryOptions<TData, TVariables> & {
2123+
subscriptionData: {
2124+
data: Unmasked<TSubscriptionData>;
2125+
};
2126+
}): Unmasked<TData> | void;
21052127
};
21062128

21072129
// @public (undocumented)
@@ -2223,12 +2245,22 @@ type UnwrapFragmentRefs<TData> = true extends IsAny<TData> ? TData : TData exten
22232245
type UpdateQueries<TData> = MutationOptions<TData, any, any>["updateQueries"];
22242246

22252247
// @public (undocumented)
2226-
type UpdateQueryFn<TData = any, TSubscriptionVariables = OperationVariables, TSubscriptionData = TData> = (previousQueryResult: Unmasked<TData>, options: {
2227-
subscriptionData: {
2228-
data: Unmasked<TSubscriptionData>;
2229-
};
2230-
variables?: TSubscriptionVariables;
2231-
}) => Unmasked<TData>;
2248+
interface UpdateQueryMapFn<TData = any, TVariables = OperationVariables> {
2249+
// (undocumented)
2250+
(
2251+
unsafePreviousData: Unmasked<TData>, options: UpdateQueryOptions<TData, TVariables>): Unmasked<TData> | void;
2252+
}
2253+
2254+
// @public (undocumented)
2255+
type UpdateQueryOptions<TData, TVariables> = {
2256+
variables?: TVariables;
2257+
} & ({
2258+
complete: true;
2259+
previousData: Unmasked<TData>;
2260+
} | {
2261+
complete: false;
2262+
previousData: DeepPartial<Unmasked<TData>> | undefined;
2263+
});
22322264

22332265
// @public (undocumented)
22342266
interface UriFunction {
@@ -2557,16 +2589,15 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
25572589
// 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
25582590
// 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
25592591
// src/core/LocalState.ts:46:5 - (ae-forgotten-export) The symbol "FragmentMap" needs to be exported by the entry point index.d.ts
2560-
// src/core/ObservableQuery.ts:120:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
2561-
// src/core/ObservableQuery.ts:121:5 - (ae-forgotten-export) The symbol "QueryInfo" 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
25622594
// src/core/QueryManager.ts:159:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
25632595
// src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
25642596
// src/core/types.ts:175:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts
25652597
// src/core/types.ts:204:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts
2566-
// src/core/watchQueryOptions.ts:277:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
2567-
// src/react/hooks/useBackgroundQuery.ts:38:3 - (ae-forgotten-export) The symbol "SubscribeToMoreFunction" needs to be exported by the entry point index.d.ts
2568-
// src/react/hooks/useBackgroundQuery.ts:54:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts
2569-
// src/react/hooks/useBackgroundQuery.ts:78:4 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts
2598+
// src/core/watchQueryOptions.ts:357:2 - (ae-forgotten-export) The symbol "UpdateQueryOptions" needs to be exported by the entry point index.d.ts
2599+
// src/react/hooks/useBackgroundQuery.ts:51:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts
2600+
// src/react/hooks/useBackgroundQuery.ts:75:4 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts
25702601
// src/react/hooks/useLoadableQuery.ts:120:9 - (ae-forgotten-export) The symbol "ResetFunction" needs to be exported by the entry point index.d.ts
25712602
// src/react/hooks/useSuspenseFragment.ts:60:5 - (ae-forgotten-export) The symbol "From" needs to be exported by the entry point index.d.ts
25722603

0 commit comments

Comments
 (0)
Please sign in to comment.