Skip to content

Commit 09a6677

Browse files
authored
also wrap createQueryPreloader (#11719)
* also wrap `createQueryPreloader` * changeset * Clean up Prettier, Size-limit, and Api-Extractor --------- Co-authored-by: phryneas <phryneas@users.noreply.github.com>
1 parent a0868da commit 09a6677

File tree

5 files changed

+89
-3
lines changed

5 files changed

+89
-3
lines changed

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

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,11 @@ class Concast<T> extends Observable<T> {
493493
// @public (undocumented)
494494
type ConcastSourcesIterable<T> = Iterable<Source<T>>;
495495

496+
// Warning: (ae-forgotten-export) The symbol "PreloadQueryFunction" needs to be exported by the entry point index.d.ts
497+
//
498+
// @public
499+
function createQueryPreloader(client: ApolloClient<any>): PreloadQueryFunction;
500+
496501
// @public (undocumented)
497502
namespace DataProxy {
498503
// (undocumented)
@@ -1252,6 +1257,11 @@ const OBSERVED_CHANGED_OPTIONS: readonly ["canonizeResults", "context", "errorPo
12521257
// @public (undocumented)
12531258
type ObservedOptions = Pick<WatchQueryOptions, (typeof OBSERVED_CHANGED_OPTIONS)[number]>;
12541259

1260+
// @public
1261+
type OnlyRequiredProperties<T> = {
1262+
[K in keyof T as {} extends Pick<T, K> ? never : K]: T[K];
1263+
};
1264+
12551265
// @public (undocumented)
12561266
type OnQueryUpdated<TResult> = (observableQuery: ObservableQuery<any>, diff: Cache_2.DiffResult<any>, lastDiff: Cache_2.DiffResult<any> | undefined) => boolean | TResult;
12571267

@@ -1291,6 +1301,50 @@ export interface PreloadedQueryRef<TData = unknown, TVariables = unknown> extend
12911301
toPromise(): Promise<PreloadedQueryRef<TData, TVariables>>;
12921302
}
12931303

1304+
// @public (undocumented)
1305+
type PreloadQueryFetchPolicy = Extract<WatchQueryFetchPolicy, "cache-first" | "network-only" | "no-cache" | "cache-and-network">;
1306+
1307+
// @public
1308+
interface PreloadQueryFunction {
1309+
// Warning: (ae-forgotten-export) The symbol "PreloadQueryOptions" needs to be exported by the entry point index.d.ts
1310+
// Warning: (ae-forgotten-export) The symbol "PreloadQueryOptionsArg" needs to be exported by the entry point index.d.ts
1311+
<TData, TVariables extends OperationVariables, TOptions extends Omit<PreloadQueryOptions, "variables">>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, ...[options]: PreloadQueryOptionsArg<NoInfer_2<TVariables>, TOptions>): PreloadedQueryRef<TOptions["errorPolicy"] extends "ignore" | "all" ? TOptions["returnPartialData"] extends true ? DeepPartial<TData> | undefined : TData | undefined : TOptions["returnPartialData"] extends true ? DeepPartial<TData> : TData, TVariables>;
1312+
<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: PreloadQueryOptions<NoInfer_2<TVariables>> & {
1313+
returnPartialData: true;
1314+
errorPolicy: "ignore" | "all";
1315+
}): PreloadedQueryRef<DeepPartial<TData> | undefined, TVariables>;
1316+
<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: PreloadQueryOptions<NoInfer_2<TVariables>> & {
1317+
errorPolicy: "ignore" | "all";
1318+
}): PreloadedQueryRef<TData | undefined, TVariables>;
1319+
<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: PreloadQueryOptions<NoInfer_2<TVariables>> & {
1320+
returnPartialData: true;
1321+
}): PreloadedQueryRef<DeepPartial<TData>, TVariables>;
1322+
<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, ...[options]: PreloadQueryOptionsArg<NoInfer_2<TVariables>>): PreloadedQueryRef<TData, TVariables>;
1323+
}
1324+
1325+
// Warning: (ae-forgotten-export) The symbol "VariablesOption" needs to be exported by the entry point index.d.ts
1326+
//
1327+
// @public (undocumented)
1328+
type PreloadQueryOptions<TVariables extends OperationVariables = OperationVariables> = {
1329+
canonizeResults?: boolean;
1330+
context?: DefaultContext;
1331+
errorPolicy?: ErrorPolicy;
1332+
fetchPolicy?: PreloadQueryFetchPolicy;
1333+
returnPartialData?: boolean;
1334+
refetchWritePolicy?: RefetchWritePolicy;
1335+
} & VariablesOption<TVariables>;
1336+
1337+
// Warning: (ae-forgotten-export) The symbol "OnlyRequiredProperties" needs to be exported by the entry point index.d.ts
1338+
//
1339+
// @public (undocumented)
1340+
type PreloadQueryOptionsArg<TVariables extends OperationVariables, TOptions = unknown> = [TVariables] extends [never] ? [
1341+
options?: PreloadQueryOptions<never> & TOptions
1342+
] : {} extends OnlyRequiredProperties<TVariables> ? [
1343+
options?: PreloadQueryOptions<NoInfer_2<TVariables>> & Omit<TOptions, "variables">
1344+
] : [
1345+
options: PreloadQueryOptions<NoInfer_2<TVariables>> & Omit<TOptions, "variables">
1346+
];
1347+
12941348
// @public (undocumented)
12951349
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
12961350

@@ -1692,7 +1746,6 @@ interface SharedWatchQueryOptions<TVariables extends OperationVariables, TData>
16921746
// @deprecated
16931747
partialRefetch?: boolean;
16941748
pollInterval?: number;
1695-
// Warning: (ae-forgotten-export) The symbol "RefetchWritePolicy" needs to be exported by the entry point index.d.ts
16961749
refetchWritePolicy?: RefetchWritePolicy;
16971750
returnPartialData?: boolean;
16981751
skipPollAttempt?: () => boolean;
@@ -2049,6 +2102,17 @@ interface UseSuspenseQueryResult<TData = unknown, TVariables extends OperationVa
20492102
subscribeToMore: SubscribeToMoreFunction<TData, TVariables>;
20502103
}
20512104

2105+
// @public (undocumented)
2106+
type VariablesOption<TVariables extends OperationVariables> = [
2107+
TVariables
2108+
] extends [never] ? {
2109+
variables?: Record<string, never>;
2110+
} : {} extends OnlyRequiredProperties<TVariables> ? {
2111+
variables?: TVariables;
2112+
} : {
2113+
variables: TVariables;
2114+
};
2115+
20522116
// @public
20532117
interface WatchFragmentOptions<TData, TVars> {
20542118
// @deprecated (undocumented)
@@ -2081,6 +2145,10 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
20812145

20822146
// @public (undocumented)
20832147
interface WrappableHooks {
2148+
// Warning: (ae-forgotten-export) The symbol "createQueryPreloader" needs to be exported by the entry point index.d.ts
2149+
//
2150+
// (undocumented)
2151+
createQueryPreloader: typeof createQueryPreloader;
20842152
// Warning: (ae-forgotten-export) The symbol "useBackgroundQuery" needs to be exported by the entry point index.d.ts
20852153
//
20862154
// (undocumented)
@@ -2141,6 +2209,8 @@ export function wrapQueryRef<TData, TVariables extends OperationVariables>(inter
21412209
// src/react/hooks/useBackgroundQuery.ts:38:3 - (ae-forgotten-export) The symbol "SubscribeToMoreFunction" needs to be exported by the entry point index.d.ts
21422210
// src/react/hooks/useBackgroundQuery.ts:54:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts
21432211
// src/react/hooks/useBackgroundQuery.ts:78:4 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts
2212+
// src/react/query-preloader/createQueryPreloader.ts:145:3 - (ae-forgotten-export) The symbol "PreloadQueryFetchPolicy" needs to be exported by the entry point index.d.ts
2213+
// src/react/query-preloader/createQueryPreloader.ts:167:5 - (ae-forgotten-export) The symbol "RefetchWritePolicy" needs to be exported by the entry point index.d.ts
21442214

21452215
// (No @packageDocumentation comment for this package)
21462216

.changeset/thin-lies-begin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@apollo/client": patch
3+
---
4+
5+
Allow wrapping `createQueryPreloader`

.size-limits.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"dist/apollo-client.min.cjs": 40015,
2+
"dist/apollo-client.min.cjs": 40030,
33
"import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32903
44
}

src/react/hooks/internal/wrapHook.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ import type {
99
import type { QueryManager } from "../../../core/QueryManager.js";
1010
import type { ApolloClient } from "../../../core/ApolloClient.js";
1111
import type { ObservableQuery } from "../../../core/ObservableQuery.js";
12+
import type { createQueryPreloader } from "../../query-preloader/createQueryPreloader.js";
1213

1314
const wrapperSymbol = Symbol.for("apollo.hook.wrappers");
1415

1516
interface WrappableHooks {
17+
createQueryPreloader: typeof createQueryPreloader;
1618
useQuery: typeof useQuery;
1719
useSuspenseQuery: typeof useSuspenseQuery;
1820
useBackgroundQuery: typeof useBackgroundQuery;

src/react/query-preloader/createQueryPreloader.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type {
1616
import { InternalQueryReference, wrapQueryRef } from "../internal/index.js";
1717
import type { PreloadedQueryRef } from "../internal/index.js";
1818
import type { NoInfer } from "../index.js";
19+
import { wrapHook } from "../hooks/internal/index.js";
1920

2021
type VariablesOption<TVariables extends OperationVariables> =
2122
[TVariables] extends [never] ?
@@ -168,6 +169,14 @@ export interface PreloadQueryFunction {
168169
export function createQueryPreloader(
169170
client: ApolloClient<any>
170171
): PreloadQueryFunction {
172+
return wrapHook(
173+
"createQueryPreloader",
174+
_createQueryPreloader,
175+
client
176+
)(client);
177+
}
178+
179+
const _createQueryPreloader: typeof createQueryPreloader = (client) => {
171180
return function preloadQuery<
172181
TData = unknown,
173182
TVariables extends OperationVariables = OperationVariables,
@@ -189,4 +198,4 @@ export function createQueryPreloader(
189198

190199
return wrapQueryRef(queryRef) as PreloadedQueryRef<TData, TVariables>;
191200
};
192-
}
201+
};

0 commit comments

Comments
 (0)