Skip to content

Commit a815873

Browse files
authored
Add a new useLoadableQuery hook (#11300)
1 parent d9ca4f0 commit a815873

25 files changed

+5553
-95
lines changed

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

+74-4
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,38 @@ export type LazyQueryResultTuple<TData, TVariables extends OperationVariables> =
10181018
// @public (undocumented)
10191019
type Listener<TData> = (promise: Promise<ApolloQueryResult<TData>>) => void;
10201020

1021+
// @public (undocumented)
1022+
export type LoadableQueryHookFetchPolicy = Extract<WatchQueryFetchPolicy, "cache-first" | "network-only" | "no-cache" | "cache-and-network">;
1023+
1024+
// @public (undocumented)
1025+
export interface LoadableQueryHookOptions {
1026+
// (undocumented)
1027+
canonizeResults?: boolean;
1028+
// (undocumented)
1029+
client?: ApolloClient<any>;
1030+
// (undocumented)
1031+
context?: Context;
1032+
// Warning: (ae-forgotten-export) The symbol "ErrorPolicy" needs to be exported by the entry point index.d.ts
1033+
//
1034+
// (undocumented)
1035+
errorPolicy?: ErrorPolicy;
1036+
// (undocumented)
1037+
fetchPolicy?: LoadableQueryHookFetchPolicy;
1038+
// (undocumented)
1039+
queryKey?: string | number | any[];
1040+
// Warning: (ae-forgotten-export) The symbol "RefetchWritePolicy" needs to be exported by the entry point index.d.ts
1041+
//
1042+
// (undocumented)
1043+
refetchWritePolicy?: RefetchWritePolicy;
1044+
// (undocumented)
1045+
returnPartialData?: boolean;
1046+
}
1047+
1048+
// Warning: (ae-forgotten-export) The symbol "OnlyRequiredProperties" needs to be exported by the entry point index.d.ts
1049+
//
1050+
// @public (undocumented)
1051+
export type LoadQueryFunction<TVariables extends OperationVariables> = (...args: [TVariables] extends [never] ? [] : {} extends OnlyRequiredProperties<TVariables> ? [variables?: TVariables] : [variables: TVariables]) => void;
1052+
10211053
// @public (undocumented)
10221054
class LocalState<TCacheShape> {
10231055
// Warning: (ae-forgotten-export) The symbol "LocalStateOptions" needs to be exported by the entry point index.d.ts
@@ -1119,8 +1151,6 @@ interface MutationBaseOptions<TData = any, TVariables = OperationVariables, TCon
11191151
awaitRefetchQueries?: boolean;
11201152
// (undocumented)
11211153
context?: TContext;
1122-
// Warning: (ae-forgotten-export) The symbol "ErrorPolicy" needs to be exported by the entry point index.d.ts
1123-
//
11241154
// (undocumented)
11251155
errorPolicy?: ErrorPolicy;
11261156
// Warning: (ae-forgotten-export) The symbol "OnQueryUpdated" needs to be exported by the entry point index.d.ts
@@ -1361,6 +1391,11 @@ export interface OnDataOptions<TData = any> {
13611391
data: SubscriptionResult<TData>;
13621392
}
13631393

1394+
// @public (undocumented)
1395+
type OnlyRequiredProperties<T> = {
1396+
[K in keyof T as {} extends Pick<T, K> ? never : K]: T[K];
1397+
};
1398+
13641399
// @public (undocumented)
13651400
type OnQueryUpdated<TResult> = (observableQuery: ObservableQuery<any>, diff: Cache_2.DiffResult<any>, lastDiff: Cache_2.DiffResult<any> | undefined) => boolean | TResult;
13661401

@@ -1800,6 +1835,9 @@ type RequestHandler = (operation: Operation, forward: NextLink) => Observable<Fe
18001835
// @public (undocumented)
18011836
export const resetApolloContext: typeof getApolloContext;
18021837

1838+
// @public (undocumented)
1839+
type ResetFunction = () => void;
1840+
18031841
// @public (undocumented)
18041842
type Resolver = (rootValue?: any, args?: any, context?: any, info?: {
18051843
field: FieldNode;
@@ -2092,6 +2130,39 @@ export type UseFragmentResult<TData> = {
20922130
// @public (undocumented)
20932131
export function useLazyQuery<TData = any, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: LazyQueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>): LazyQueryResultTuple<TData, TVariables>;
20942132

2133+
// @public (undocumented)
2134+
export function useLoadableQuery<TData, TVariables extends OperationVariables, TOptions extends LoadableQueryHookOptions>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: LoadableQueryHookOptions & TOptions): UseLoadableQueryResult<TOptions["errorPolicy"] extends "ignore" | "all" ? TOptions["returnPartialData"] extends true ? DeepPartial<TData> | undefined : TData | undefined : TOptions["returnPartialData"] extends true ? DeepPartial<TData> : TData, TVariables>;
2135+
2136+
// @public (undocumented)
2137+
export function useLoadableQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: LoadableQueryHookOptions & {
2138+
returnPartialData: true;
2139+
errorPolicy: "ignore" | "all";
2140+
}): UseLoadableQueryResult<DeepPartial<TData> | undefined, TVariables>;
2141+
2142+
// @public (undocumented)
2143+
export function useLoadableQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: LoadableQueryHookOptions & {
2144+
errorPolicy: "ignore" | "all";
2145+
}): UseLoadableQueryResult<TData | undefined, TVariables>;
2146+
2147+
// @public (undocumented)
2148+
export function useLoadableQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: LoadableQueryHookOptions & {
2149+
returnPartialData: true;
2150+
}): UseLoadableQueryResult<DeepPartial<TData>, TVariables>;
2151+
2152+
// @public (undocumented)
2153+
export function useLoadableQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: LoadableQueryHookOptions): UseLoadableQueryResult<TData, TVariables>;
2154+
2155+
// @public (undocumented)
2156+
export type UseLoadableQueryResult<TData = unknown, TVariables extends OperationVariables = OperationVariables> = [
2157+
LoadQueryFunction<TVariables>,
2158+
QueryReference<TData> | null,
2159+
{
2160+
fetchMore: FetchMoreFunction<TData, TVariables>;
2161+
refetch: RefetchFunction<TData, TVariables>;
2162+
reset: ResetFunction;
2163+
}
2164+
];
2165+
20952166
// @public (undocumented)
20962167
export function useMutation<TData = any, TVariables = OperationVariables, TContext = Context, TCache extends ApolloCache<any> = ApolloCache<any>>(mutation: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: MutationHookOptions<NoInfer<TData>, NoInfer<TVariables>, TContext, TCache>): MutationTuple<TData, TVariables, TContext, TCache>;
20972168

@@ -2193,8 +2264,6 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
21932264
//
21942265
// (undocumented)
21952266
nextFetchPolicy?: WatchQueryFetchPolicy | ((this: WatchQueryOptions<TVariables, TData>, currentFetchPolicy: WatchQueryFetchPolicy, context: NextFetchPolicyContext<TData, TVariables>) => WatchQueryFetchPolicy);
2196-
// Warning: (ae-forgotten-export) The symbol "RefetchWritePolicy" needs to be exported by the entry point index.d.ts
2197-
//
21982267
// (undocumented)
21992268
refetchWritePolicy?: RefetchWritePolicy;
22002269
}
@@ -2221,6 +2290,7 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
22212290
// src/core/watchQueryOptions.ts:191:3 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
22222291
// src/react/hooks/useBackgroundQuery.ts:26:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts
22232292
// src/react/hooks/useBackgroundQuery.ts:27:3 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts
2293+
// src/react/hooks/useLoadableQuery.ts:51:5 - (ae-forgotten-export) The symbol "ResetFunction" needs to be exported by the entry point index.d.ts
22242294
// src/utilities/graphql/DocumentTransform.ts:130:7 - (ae-forgotten-export) The symbol "DocumentTransformCacheKey" needs to be exported by the entry point index.d.ts
22252295

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

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

+78-4
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,40 @@ type LazyQueryResultTuple<TData, TVariables extends OperationVariables> = [LazyQ
969969
// @public (undocumented)
970970
type Listener<TData> = (promise: Promise<ApolloQueryResult<TData>>) => void;
971971

972+
// @public (undocumented)
973+
type LoadableQueryHookFetchPolicy = Extract<WatchQueryFetchPolicy, "cache-first" | "network-only" | "no-cache" | "cache-and-network">;
974+
975+
// @public (undocumented)
976+
interface LoadableQueryHookOptions {
977+
// (undocumented)
978+
canonizeResults?: boolean;
979+
// (undocumented)
980+
client?: ApolloClient<any>;
981+
// (undocumented)
982+
context?: DefaultContext;
983+
// Warning: (ae-forgotten-export) The symbol "ErrorPolicy" needs to be exported by the entry point index.d.ts
984+
//
985+
// (undocumented)
986+
errorPolicy?: ErrorPolicy;
987+
// Warning: (ae-forgotten-export) The symbol "LoadableQueryHookFetchPolicy" needs to be exported by the entry point index.d.ts
988+
//
989+
// (undocumented)
990+
fetchPolicy?: LoadableQueryHookFetchPolicy;
991+
// (undocumented)
992+
queryKey?: string | number | any[];
993+
// Warning: (ae-forgotten-export) The symbol "RefetchWritePolicy" needs to be exported by the entry point index.d.ts
994+
//
995+
// (undocumented)
996+
refetchWritePolicy?: RefetchWritePolicy;
997+
// (undocumented)
998+
returnPartialData?: boolean;
999+
}
1000+
1001+
// Warning: (ae-forgotten-export) The symbol "OnlyRequiredProperties" needs to be exported by the entry point index.d.ts
1002+
//
1003+
// @public (undocumented)
1004+
export type LoadQueryFunction<TVariables extends OperationVariables> = (...args: [TVariables] extends [never] ? [] : {} extends OnlyRequiredProperties<TVariables> ? [variables?: TVariables] : [variables: TVariables]) => void;
1005+
9721006
// @public (undocumented)
9731007
class LocalState<TCacheShape> {
9741008
// Warning: (ae-forgotten-export) The symbol "LocalStateOptions" needs to be exported by the entry point index.d.ts
@@ -1070,8 +1104,6 @@ interface MutationBaseOptions<TData = any, TVariables = OperationVariables, TCon
10701104
awaitRefetchQueries?: boolean;
10711105
// (undocumented)
10721106
context?: TContext;
1073-
// Warning: (ae-forgotten-export) The symbol "ErrorPolicy" needs to be exported by the entry point index.d.ts
1074-
//
10751107
// (undocumented)
10761108
errorPolicy?: ErrorPolicy;
10771109
// Warning: (ae-forgotten-export) The symbol "OnQueryUpdated" needs to be exported by the entry point index.d.ts
@@ -1310,6 +1342,11 @@ interface OnDataOptions<TData = any> {
13101342
data: SubscriptionResult<TData>;
13111343
}
13121344

1345+
// @public (undocumented)
1346+
type OnlyRequiredProperties<T> = {
1347+
[K in keyof T as {} extends Pick<T, K> ? never : K]: T[K];
1348+
};
1349+
13131350
// @public (undocumented)
13141351
type OnQueryUpdated<TResult> = (observableQuery: ObservableQuery<any>, diff: Cache_2.DiffResult<any>, lastDiff: Cache_2.DiffResult<any> | undefined) => boolean | TResult;
13151352

@@ -1696,6 +1733,9 @@ type RefetchWritePolicy = "merge" | "overwrite";
16961733
// @public (undocumented)
16971734
type RequestHandler = (operation: Operation, forward: NextLink) => Observable<FetchResult> | null;
16981735

1736+
// @public (undocumented)
1737+
type ResetFunction = () => void;
1738+
16991739
// @public (undocumented)
17001740
type Resolver = (rootValue?: any, args?: any, context?: any, info?: {
17011741
field: FieldNode;
@@ -1979,6 +2019,41 @@ export type UseFragmentResult<TData> = {
19792019
// @public (undocumented)
19802020
export function useLazyQuery<TData = any, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: LazyQueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>): LazyQueryResultTuple<TData, TVariables>;
19812021

2022+
// Warning: (ae-forgotten-export) The symbol "LoadableQueryHookOptions" needs to be exported by the entry point index.d.ts
2023+
//
2024+
// @public (undocumented)
2025+
export function useLoadableQuery<TData, TVariables extends OperationVariables, TOptions extends LoadableQueryHookOptions>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: LoadableQueryHookOptions & TOptions): UseLoadableQueryResult<TOptions["errorPolicy"] extends "ignore" | "all" ? TOptions["returnPartialData"] extends true ? DeepPartial<TData> | undefined : TData | undefined : TOptions["returnPartialData"] extends true ? DeepPartial<TData> : TData, TVariables>;
2026+
2027+
// @public (undocumented)
2028+
export function useLoadableQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: LoadableQueryHookOptions & {
2029+
returnPartialData: true;
2030+
errorPolicy: "ignore" | "all";
2031+
}): UseLoadableQueryResult<DeepPartial<TData> | undefined, TVariables>;
2032+
2033+
// @public (undocumented)
2034+
export function useLoadableQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: LoadableQueryHookOptions & {
2035+
errorPolicy: "ignore" | "all";
2036+
}): UseLoadableQueryResult<TData | undefined, TVariables>;
2037+
2038+
// @public (undocumented)
2039+
export function useLoadableQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: LoadableQueryHookOptions & {
2040+
returnPartialData: true;
2041+
}): UseLoadableQueryResult<DeepPartial<TData>, TVariables>;
2042+
2043+
// @public (undocumented)
2044+
export function useLoadableQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: LoadableQueryHookOptions): UseLoadableQueryResult<TData, TVariables>;
2045+
2046+
// @public (undocumented)
2047+
export type UseLoadableQueryResult<TData = unknown, TVariables extends OperationVariables = OperationVariables> = [
2048+
LoadQueryFunction<TVariables>,
2049+
QueryReference<TData> | null,
2050+
{
2051+
fetchMore: FetchMoreFunction<TData, TVariables>;
2052+
refetch: RefetchFunction<TData, TVariables>;
2053+
reset: ResetFunction;
2054+
}
2055+
];
2056+
19822057
// Warning: (ae-forgotten-export) The symbol "MutationHookOptions" needs to be exported by the entry point index.d.ts
19832058
// Warning: (ae-forgotten-export) The symbol "MutationTuple" needs to be exported by the entry point index.d.ts
19842059
//
@@ -2087,8 +2162,6 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
20872162
//
20882163
// (undocumented)
20892164
nextFetchPolicy?: WatchQueryFetchPolicy | ((this: WatchQueryOptions<TVariables, TData>, currentFetchPolicy: WatchQueryFetchPolicy, context: NextFetchPolicyContext<TData, TVariables>) => WatchQueryFetchPolicy);
2090-
// Warning: (ae-forgotten-export) The symbol "RefetchWritePolicy" needs to be exported by the entry point index.d.ts
2091-
//
20922165
// (undocumented)
20932166
refetchWritePolicy?: RefetchWritePolicy;
20942167
}
@@ -2115,6 +2188,7 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
21152188
// src/core/watchQueryOptions.ts:191:3 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
21162189
// src/react/hooks/useBackgroundQuery.ts:26:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts
21172190
// src/react/hooks/useBackgroundQuery.ts:27:3 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts
2191+
// src/react/hooks/useLoadableQuery.ts:51:5 - (ae-forgotten-export) The symbol "ResetFunction" needs to be exported by the entry point index.d.ts
21182192
// src/utilities/graphql/DocumentTransform.ts:130:7 - (ae-forgotten-export) The symbol "DocumentTransformCacheKey" needs to be exported by the entry point index.d.ts
21192193

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

.api-reports/api-report-utilities.md

+5
Original file line numberDiff line numberDiff line change
@@ -1803,6 +1803,11 @@ export function offsetLimitPagination<T = Reference>(keyArgs?: KeyArgs): FieldPo
18031803
// @public (undocumented)
18041804
export function omitDeep<T, K extends string>(value: T, key: K): DeepOmit<T, K>;
18051805

1806+
// @public (undocumented)
1807+
export type OnlyRequiredProperties<T> = {
1808+
[K in keyof T as {} extends Pick<T, K> ? never : K]: T[K];
1809+
};
1810+
18061811
// @public (undocumented)
18071812
type OnQueryUpdated<TResult> = (observableQuery: ObservableQuery<any>, diff: Cache_2.DiffResult<any>, lastDiff: Cache_2.DiffResult<any> | undefined) => boolean | TResult;
18081813

0 commit comments

Comments
 (0)