@apollo/client 4.2.0-alpha.6 → 4.2.0-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +66 -0
- package/__cjs/core/ApolloClient.cjs +27 -7
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/RefetchEventManager.cjs +9 -1
- package/__cjs/core/RefetchEventManager.cjs.map +1 -1
- package/__cjs/core/RefetchEventManager.d.cts +10 -0
- package/__cjs/invariantErrorCodes.cjs +1 -1
- package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
- package/__cjs/react/query-preloader/createQueryPreloader.d.cts +395 -123
- package/__cjs/version.cjs +1 -1
- package/core/ApolloClient.js +27 -7
- package/core/ApolloClient.js.map +1 -1
- package/core/RefetchEventManager.d.ts +10 -0
- package/core/RefetchEventManager.js +9 -1
- package/core/RefetchEventManager.js.map +1 -1
- package/invariantErrorCodes.js +1 -1
- package/package.json +1 -1
- package/react/query-preloader/createQueryPreloader.d.ts +395 -123
- package/react/query-preloader/createQueryPreloader.js.map +1 -1
- package/version.js +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ApolloClient, DefaultContext, DocumentNode, ErrorPolicy, OperationVariables, RefetchOn, RefetchWritePolicy, TypedDocumentNode, WatchQueryFetchPolicy } from "@apollo/client";
|
|
2
2
|
import type { PreloadedQueryRef } from "@apollo/client/react";
|
|
3
|
-
import type { NoInfer, VariablesOption } from "@apollo/client/utilities/internal";
|
|
3
|
+
import type { NoInfer, OptionWithFallback, SignatureStyle, VariablesOption } from "@apollo/client/utilities/internal";
|
|
4
4
|
export type PreloadQueryFetchPolicy = Extract<WatchQueryFetchPolicy, "cache-first" | "network-only" | "no-cache" | "cache-and-network">;
|
|
5
5
|
export type PreloadQueryOptions<TVariables extends OperationVariables = OperationVariables> = {
|
|
6
6
|
/**
|
|
@@ -93,128 +93,7 @@ export type PreloadQueryOptions<TVariables extends OperationVariables = Operatio
|
|
|
93
93
|
* }
|
|
94
94
|
* ```
|
|
95
95
|
*/
|
|
96
|
-
export interface PreloadQueryFunction {
|
|
97
|
-
/**
|
|
98
|
-
* A function that will begin loading a query when called. It's result can be
|
|
99
|
-
* read by `useReadQuery` which will suspend until the query is loaded.
|
|
100
|
-
* This is useful when you want to start loading a query as early as possible
|
|
101
|
-
* outside of a React component.
|
|
102
|
-
*
|
|
103
|
-
* @example
|
|
104
|
-
*
|
|
105
|
-
* ```js
|
|
106
|
-
* const preloadQuery = createQueryPreloader(client);
|
|
107
|
-
* const queryRef = preloadQuery(query, { variables, ...otherOptions });
|
|
108
|
-
*
|
|
109
|
-
* function App() {
|
|
110
|
-
* return (
|
|
111
|
-
* <Suspense fallback={<div>Loading</div>}>
|
|
112
|
-
* <MyQuery />
|
|
113
|
-
* </Suspense>
|
|
114
|
-
* );
|
|
115
|
-
* }
|
|
116
|
-
*
|
|
117
|
-
* function MyQuery() {
|
|
118
|
-
* const { data } = useReadQuery(queryRef);
|
|
119
|
-
*
|
|
120
|
-
* // do something with `data`
|
|
121
|
-
* }
|
|
122
|
-
* ```
|
|
123
|
-
*/
|
|
124
|
-
<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: PreloadQueryOptions<NoInfer<TVariables>> & {
|
|
125
|
-
returnPartialData: true;
|
|
126
|
-
errorPolicy: "ignore" | "all";
|
|
127
|
-
}): PreloadedQueryRef<TData, TVariables, "complete" | "streaming" | "partial" | "empty">;
|
|
128
|
-
/**
|
|
129
|
-
* A function that will begin loading a query when called. It's result can be
|
|
130
|
-
* read by `useReadQuery` which will suspend until the query is loaded.
|
|
131
|
-
* This is useful when you want to start loading a query as early as possible
|
|
132
|
-
* outside of a React component.
|
|
133
|
-
*
|
|
134
|
-
* @example
|
|
135
|
-
*
|
|
136
|
-
* ```js
|
|
137
|
-
* const preloadQuery = createQueryPreloader(client);
|
|
138
|
-
* const queryRef = preloadQuery(query, { variables, ...otherOptions });
|
|
139
|
-
*
|
|
140
|
-
* function App() {
|
|
141
|
-
* return (
|
|
142
|
-
* <Suspense fallback={<div>Loading</div>}>
|
|
143
|
-
* <MyQuery />
|
|
144
|
-
* </Suspense>
|
|
145
|
-
* );
|
|
146
|
-
* }
|
|
147
|
-
*
|
|
148
|
-
* function MyQuery() {
|
|
149
|
-
* const { data } = useReadQuery(queryRef);
|
|
150
|
-
*
|
|
151
|
-
* // do something with `data`
|
|
152
|
-
* }
|
|
153
|
-
* ```
|
|
154
|
-
*/
|
|
155
|
-
<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: PreloadQueryOptions<NoInfer<TVariables>> & {
|
|
156
|
-
errorPolicy: "ignore" | "all";
|
|
157
|
-
}): PreloadedQueryRef<TData, TVariables, "complete" | "streaming" | "empty">;
|
|
158
|
-
/**
|
|
159
|
-
* A function that will begin loading a query when called. It's result can be
|
|
160
|
-
* read by `useReadQuery` which will suspend until the query is loaded.
|
|
161
|
-
* This is useful when you want to start loading a query as early as possible
|
|
162
|
-
* outside of a React component.
|
|
163
|
-
*
|
|
164
|
-
* @example
|
|
165
|
-
*
|
|
166
|
-
* ```js
|
|
167
|
-
* const preloadQuery = createQueryPreloader(client);
|
|
168
|
-
* const queryRef = preloadQuery(query, { variables, ...otherOptions });
|
|
169
|
-
*
|
|
170
|
-
* function App() {
|
|
171
|
-
* return (
|
|
172
|
-
* <Suspense fallback={<div>Loading</div>}>
|
|
173
|
-
* <MyQuery />
|
|
174
|
-
* </Suspense>
|
|
175
|
-
* );
|
|
176
|
-
* }
|
|
177
|
-
*
|
|
178
|
-
* function MyQuery() {
|
|
179
|
-
* const { data } = useReadQuery(queryRef);
|
|
180
|
-
*
|
|
181
|
-
* // do something with `data`
|
|
182
|
-
* }
|
|
183
|
-
* ```
|
|
184
|
-
*/
|
|
185
|
-
<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: PreloadQueryOptions<NoInfer<TVariables>> & {
|
|
186
|
-
returnPartialData: true;
|
|
187
|
-
}): PreloadedQueryRef<TData, TVariables, "complete" | "streaming" | "partial">;
|
|
188
|
-
/**
|
|
189
|
-
* A function that will begin loading a query when called. It's result can be
|
|
190
|
-
* read by `useReadQuery` which will suspend until the query is loaded.
|
|
191
|
-
* This is useful when you want to start loading a query as early as possible
|
|
192
|
-
* outside of a React component.
|
|
193
|
-
*
|
|
194
|
-
* @example
|
|
195
|
-
*
|
|
196
|
-
* ```js
|
|
197
|
-
* const preloadQuery = createQueryPreloader(client);
|
|
198
|
-
* const queryRef = preloadQuery(query, { variables, ...otherOptions });
|
|
199
|
-
*
|
|
200
|
-
* function App() {
|
|
201
|
-
* return (
|
|
202
|
-
* <Suspense fallback={<div>Loading</div>}>
|
|
203
|
-
* <MyQuery />
|
|
204
|
-
* </Suspense>
|
|
205
|
-
* );
|
|
206
|
-
* }
|
|
207
|
-
*
|
|
208
|
-
* function MyQuery() {
|
|
209
|
-
* const { data } = useReadQuery(queryRef);
|
|
210
|
-
*
|
|
211
|
-
* // do something with `data`
|
|
212
|
-
* }
|
|
213
|
-
* ```
|
|
214
|
-
*/
|
|
215
|
-
<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, ...[options]: {} extends TVariables ? [
|
|
216
|
-
options?: PreloadQueryOptions<NoInfer<TVariables>>
|
|
217
|
-
] : [options: PreloadQueryOptions<NoInfer<TVariables>>]): PreloadedQueryRef<TData, TVariables, "complete" | "streaming">;
|
|
96
|
+
export interface PreloadQueryFunction extends PreloadQueryFunction.Signatures.Evaluated {
|
|
218
97
|
/**
|
|
219
98
|
* A function that returns a promise that resolves when the query has finished
|
|
220
99
|
* loading. The promise resolves with the `QueryReference` itself.
|
|
@@ -253,6 +132,399 @@ export interface PreloadQueryFunction {
|
|
|
253
132
|
*/
|
|
254
133
|
toPromise<TQueryRef extends PreloadedQueryRef<any, any, any>>(queryRef: TQueryRef): Promise<TQueryRef>;
|
|
255
134
|
}
|
|
135
|
+
export declare namespace PreloadQueryFunction {
|
|
136
|
+
interface DefaultOptions extends ApolloClient.DefaultOptions.WatchQuery.Calculated {
|
|
137
|
+
}
|
|
138
|
+
namespace DocumentationTypes {
|
|
139
|
+
/**
|
|
140
|
+
* @deprecated Avoid manually specifying generics on `preloadQuery`.
|
|
141
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
142
|
+
*
|
|
143
|
+
*
|
|
144
|
+
* A function that will begin loading a query when called. It's result can be
|
|
145
|
+
* read by `useReadQuery` which will suspend until the query is loaded.
|
|
146
|
+
* This is useful when you want to start loading a query as early as possible
|
|
147
|
+
* outside of a React component.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
*
|
|
151
|
+
* ```js
|
|
152
|
+
* const preloadQuery = createQueryPreloader(client);
|
|
153
|
+
* const queryRef = preloadQuery(query, { variables, ...otherOptions });
|
|
154
|
+
*
|
|
155
|
+
* function App() {
|
|
156
|
+
* return (
|
|
157
|
+
* <Suspense fallback={<div>Loading</div>}>
|
|
158
|
+
* <MyQuery />
|
|
159
|
+
* </Suspense>
|
|
160
|
+
* );
|
|
161
|
+
* }
|
|
162
|
+
*
|
|
163
|
+
* function MyQuery() {
|
|
164
|
+
* const { data } = useReadQuery(queryRef);
|
|
165
|
+
*
|
|
166
|
+
* // do something with `data`
|
|
167
|
+
* }
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
interface PreloadQueryFunction_Deprecated extends PreloadQueryFunction {
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
type ResultForOptions<TData, TVariables extends OperationVariables, TOptions extends Record<string, never> | PreloadQueryOptions<TVariables>> = TOptions extends any ? PreloadedQueryRef<TData, TVariables, ResultForOptions.States<TOptions, DefaultOptions>> : never;
|
|
174
|
+
namespace ResultForOptions {
|
|
175
|
+
type States<TOptions, TDefaultOptions extends DefaultOptions = DefaultOptions> = "complete" | "streaming" | (OptionWithFallback<TOptions, TDefaultOptions, "errorPolicy"> extends ("none") ? never : "empty") | (OptionWithFallback<TOptions, TDefaultOptions, "returnPartialData"> extends false ? never : "partial");
|
|
176
|
+
}
|
|
177
|
+
namespace Signatures {
|
|
178
|
+
interface Classic {
|
|
179
|
+
/**
|
|
180
|
+
* A function that will begin loading a query when called. It's result can be
|
|
181
|
+
* read by `useReadQuery` which will suspend until the query is loaded.
|
|
182
|
+
* This is useful when you want to start loading a query as early as possible
|
|
183
|
+
* outside of a React component.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
*
|
|
187
|
+
* ```js
|
|
188
|
+
* const preloadQuery = createQueryPreloader(client);
|
|
189
|
+
* const queryRef = preloadQuery(query, { variables, ...otherOptions });
|
|
190
|
+
*
|
|
191
|
+
* function App() {
|
|
192
|
+
* return (
|
|
193
|
+
* <Suspense fallback={<div>Loading</div>}>
|
|
194
|
+
* <MyQuery />
|
|
195
|
+
* </Suspense>
|
|
196
|
+
* );
|
|
197
|
+
* }
|
|
198
|
+
*
|
|
199
|
+
* function MyQuery() {
|
|
200
|
+
* const { data } = useReadQuery(queryRef);
|
|
201
|
+
*
|
|
202
|
+
* // do something with `data`
|
|
203
|
+
* }
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
<TData, TVariables extends OperationVariables, _INFERENCE_ONLY_DO_NOT_SPECIFY extends "inferred">(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: PreloadQueryOptions<NoInfer<TVariables>> & {
|
|
207
|
+
returnPartialData: true;
|
|
208
|
+
errorPolicy: "ignore" | "all";
|
|
209
|
+
}): PreloadedQueryRef<TData, TVariables, "complete" | "streaming" | "partial" | "empty">;
|
|
210
|
+
/**
|
|
211
|
+
* A function that will begin loading a query when called. It's result can be
|
|
212
|
+
* read by `useReadQuery` which will suspend until the query is loaded.
|
|
213
|
+
* This is useful when you want to start loading a query as early as possible
|
|
214
|
+
* outside of a React component.
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
*
|
|
218
|
+
* ```js
|
|
219
|
+
* const preloadQuery = createQueryPreloader(client);
|
|
220
|
+
* const queryRef = preloadQuery(query, { variables, ...otherOptions });
|
|
221
|
+
*
|
|
222
|
+
* function App() {
|
|
223
|
+
* return (
|
|
224
|
+
* <Suspense fallback={<div>Loading</div>}>
|
|
225
|
+
* <MyQuery />
|
|
226
|
+
* </Suspense>
|
|
227
|
+
* );
|
|
228
|
+
* }
|
|
229
|
+
*
|
|
230
|
+
* function MyQuery() {
|
|
231
|
+
* const { data } = useReadQuery(queryRef);
|
|
232
|
+
*
|
|
233
|
+
* // do something with `data`
|
|
234
|
+
* }
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
<TData, TVariables extends OperationVariables, _INFERENCE_ONLY_DO_NOT_SPECIFY extends "inferred">(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: PreloadQueryOptions<NoInfer<TVariables>> & {
|
|
238
|
+
errorPolicy: "ignore" | "all";
|
|
239
|
+
}): PreloadedQueryRef<TData, TVariables, "complete" | "streaming" | "empty">;
|
|
240
|
+
/**
|
|
241
|
+
* A function that will begin loading a query when called. It's result can be
|
|
242
|
+
* read by `useReadQuery` which will suspend until the query is loaded.
|
|
243
|
+
* This is useful when you want to start loading a query as early as possible
|
|
244
|
+
* outside of a React component.
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
*
|
|
248
|
+
* ```js
|
|
249
|
+
* const preloadQuery = createQueryPreloader(client);
|
|
250
|
+
* const queryRef = preloadQuery(query, { variables, ...otherOptions });
|
|
251
|
+
*
|
|
252
|
+
* function App() {
|
|
253
|
+
* return (
|
|
254
|
+
* <Suspense fallback={<div>Loading</div>}>
|
|
255
|
+
* <MyQuery />
|
|
256
|
+
* </Suspense>
|
|
257
|
+
* );
|
|
258
|
+
* }
|
|
259
|
+
*
|
|
260
|
+
* function MyQuery() {
|
|
261
|
+
* const { data } = useReadQuery(queryRef);
|
|
262
|
+
*
|
|
263
|
+
* // do something with `data`
|
|
264
|
+
* }
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
267
|
+
<TData, TVariables extends OperationVariables, _INFERENCE_ONLY_DO_NOT_SPECIFY extends "inferred">(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: PreloadQueryOptions<NoInfer<TVariables>> & {
|
|
268
|
+
returnPartialData: true;
|
|
269
|
+
}): PreloadedQueryRef<TData, TVariables, "complete" | "streaming" | "partial">;
|
|
270
|
+
/**
|
|
271
|
+
* A function that will begin loading a query when called. It's result can be
|
|
272
|
+
* read by `useReadQuery` which will suspend until the query is loaded.
|
|
273
|
+
* This is useful when you want to start loading a query as early as possible
|
|
274
|
+
* outside of a React component.
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
*
|
|
278
|
+
* ```js
|
|
279
|
+
* const preloadQuery = createQueryPreloader(client);
|
|
280
|
+
* const queryRef = preloadQuery(query, { variables, ...otherOptions });
|
|
281
|
+
*
|
|
282
|
+
* function App() {
|
|
283
|
+
* return (
|
|
284
|
+
* <Suspense fallback={<div>Loading</div>}>
|
|
285
|
+
* <MyQuery />
|
|
286
|
+
* </Suspense>
|
|
287
|
+
* );
|
|
288
|
+
* }
|
|
289
|
+
*
|
|
290
|
+
* function MyQuery() {
|
|
291
|
+
* const { data } = useReadQuery(queryRef);
|
|
292
|
+
*
|
|
293
|
+
* // do something with `data`
|
|
294
|
+
* }
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
<TData, TVariables extends OperationVariables, _INFERENCE_ONLY_DO_NOT_SPECIFY extends "inferred">(query: DocumentNode | TypedDocumentNode<TData, TVariables>, ...[options]: {} extends TVariables ? [
|
|
298
|
+
options?: PreloadQueryOptions<NoInfer<TVariables>>
|
|
299
|
+
] : [options: PreloadQueryOptions<NoInfer<TVariables>>]): PreloadedQueryRef<TData, TVariables, "complete" | "streaming">;
|
|
300
|
+
/**
|
|
301
|
+
* @deprecated Avoid manually specifying generics on `preloadQuery`.
|
|
302
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
303
|
+
*
|
|
304
|
+
*
|
|
305
|
+
* A function that will begin loading a query when called. It's result can be
|
|
306
|
+
* read by `useReadQuery` which will suspend until the query is loaded.
|
|
307
|
+
* This is useful when you want to start loading a query as early as possible
|
|
308
|
+
* outside of a React component.
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
*
|
|
312
|
+
* ```js
|
|
313
|
+
* const preloadQuery = createQueryPreloader(client);
|
|
314
|
+
* const queryRef = preloadQuery(query, { variables, ...otherOptions });
|
|
315
|
+
*
|
|
316
|
+
* function App() {
|
|
317
|
+
* return (
|
|
318
|
+
* <Suspense fallback={<div>Loading</div>}>
|
|
319
|
+
* <MyQuery />
|
|
320
|
+
* </Suspense>
|
|
321
|
+
* );
|
|
322
|
+
* }
|
|
323
|
+
*
|
|
324
|
+
* function MyQuery() {
|
|
325
|
+
* const { data } = useReadQuery(queryRef);
|
|
326
|
+
*
|
|
327
|
+
* // do something with `data`
|
|
328
|
+
* }
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
<TData, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: PreloadQueryOptions<NoInfer<TVariables>> & {
|
|
332
|
+
returnPartialData: true;
|
|
333
|
+
errorPolicy: "ignore" | "all";
|
|
334
|
+
}): PreloadedQueryRef<TData, TVariables, "complete" | "streaming" | "partial" | "empty">;
|
|
335
|
+
/**
|
|
336
|
+
* @deprecated Avoid manually specifying generics on `preloadQuery`.
|
|
337
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
338
|
+
*
|
|
339
|
+
*
|
|
340
|
+
* A function that will begin loading a query when called. It's result can be
|
|
341
|
+
* read by `useReadQuery` which will suspend until the query is loaded.
|
|
342
|
+
* This is useful when you want to start loading a query as early as possible
|
|
343
|
+
* outside of a React component.
|
|
344
|
+
*
|
|
345
|
+
* @example
|
|
346
|
+
*
|
|
347
|
+
* ```js
|
|
348
|
+
* const preloadQuery = createQueryPreloader(client);
|
|
349
|
+
* const queryRef = preloadQuery(query, { variables, ...otherOptions });
|
|
350
|
+
*
|
|
351
|
+
* function App() {
|
|
352
|
+
* return (
|
|
353
|
+
* <Suspense fallback={<div>Loading</div>}>
|
|
354
|
+
* <MyQuery />
|
|
355
|
+
* </Suspense>
|
|
356
|
+
* );
|
|
357
|
+
* }
|
|
358
|
+
*
|
|
359
|
+
* function MyQuery() {
|
|
360
|
+
* const { data } = useReadQuery(queryRef);
|
|
361
|
+
*
|
|
362
|
+
* // do something with `data`
|
|
363
|
+
* }
|
|
364
|
+
* ```
|
|
365
|
+
*/
|
|
366
|
+
<TData, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: PreloadQueryOptions<NoInfer<TVariables>> & {
|
|
367
|
+
errorPolicy: "ignore" | "all";
|
|
368
|
+
}): PreloadedQueryRef<TData, TVariables, "complete" | "streaming" | "empty">;
|
|
369
|
+
/**
|
|
370
|
+
* @deprecated Avoid manually specifying generics on `preloadQuery`.
|
|
371
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
372
|
+
*
|
|
373
|
+
*
|
|
374
|
+
* A function that will begin loading a query when called. It's result can be
|
|
375
|
+
* read by `useReadQuery` which will suspend until the query is loaded.
|
|
376
|
+
* This is useful when you want to start loading a query as early as possible
|
|
377
|
+
* outside of a React component.
|
|
378
|
+
*
|
|
379
|
+
* @example
|
|
380
|
+
*
|
|
381
|
+
* ```js
|
|
382
|
+
* const preloadQuery = createQueryPreloader(client);
|
|
383
|
+
* const queryRef = preloadQuery(query, { variables, ...otherOptions });
|
|
384
|
+
*
|
|
385
|
+
* function App() {
|
|
386
|
+
* return (
|
|
387
|
+
* <Suspense fallback={<div>Loading</div>}>
|
|
388
|
+
* <MyQuery />
|
|
389
|
+
* </Suspense>
|
|
390
|
+
* );
|
|
391
|
+
* }
|
|
392
|
+
*
|
|
393
|
+
* function MyQuery() {
|
|
394
|
+
* const { data } = useReadQuery(queryRef);
|
|
395
|
+
*
|
|
396
|
+
* // do something with `data`
|
|
397
|
+
* }
|
|
398
|
+
* ```
|
|
399
|
+
*/
|
|
400
|
+
<TData, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: PreloadQueryOptions<NoInfer<TVariables>> & {
|
|
401
|
+
returnPartialData: true;
|
|
402
|
+
}): PreloadedQueryRef<TData, TVariables, "complete" | "streaming" | "partial">;
|
|
403
|
+
/**
|
|
404
|
+
* @deprecated Avoid manually specifying generics on `preloadQuery`.
|
|
405
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
406
|
+
*
|
|
407
|
+
*
|
|
408
|
+
* A function that will begin loading a query when called. It's result can be
|
|
409
|
+
* read by `useReadQuery` which will suspend until the query is loaded.
|
|
410
|
+
* This is useful when you want to start loading a query as early as possible
|
|
411
|
+
* outside of a React component.
|
|
412
|
+
*
|
|
413
|
+
* @example
|
|
414
|
+
*
|
|
415
|
+
* ```js
|
|
416
|
+
* const preloadQuery = createQueryPreloader(client);
|
|
417
|
+
* const queryRef = preloadQuery(query, { variables, ...otherOptions });
|
|
418
|
+
*
|
|
419
|
+
* function App() {
|
|
420
|
+
* return (
|
|
421
|
+
* <Suspense fallback={<div>Loading</div>}>
|
|
422
|
+
* <MyQuery />
|
|
423
|
+
* </Suspense>
|
|
424
|
+
* );
|
|
425
|
+
* }
|
|
426
|
+
*
|
|
427
|
+
* function MyQuery() {
|
|
428
|
+
* const { data } = useReadQuery(queryRef);
|
|
429
|
+
*
|
|
430
|
+
* // do something with `data`
|
|
431
|
+
* }
|
|
432
|
+
* ```
|
|
433
|
+
*/
|
|
434
|
+
<TData, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, ...[options]: {} extends TVariables ? [
|
|
435
|
+
options?: PreloadQueryOptions<NoInfer<TVariables>>
|
|
436
|
+
] : [options: PreloadQueryOptions<NoInfer<TVariables>>]): PreloadedQueryRef<TData, TVariables, "complete" | "streaming">;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* A function that will begin loading a query when called. It's result can be
|
|
440
|
+
* read by `useReadQuery` which will suspend until the query is loaded.
|
|
441
|
+
* This is useful when you want to start loading a query as early as possible
|
|
442
|
+
* outside of a React component.
|
|
443
|
+
*
|
|
444
|
+
* @example
|
|
445
|
+
*
|
|
446
|
+
* ```js
|
|
447
|
+
* const preloadQuery = createQueryPreloader(client);
|
|
448
|
+
* const queryRef = preloadQuery(query, { variables, ...otherOptions });
|
|
449
|
+
*
|
|
450
|
+
* function App() {
|
|
451
|
+
* return (
|
|
452
|
+
* <Suspense fallback={<div>Loading</div>}>
|
|
453
|
+
* <MyQuery />
|
|
454
|
+
* </Suspense>
|
|
455
|
+
* );
|
|
456
|
+
* }
|
|
457
|
+
*
|
|
458
|
+
* function MyQuery() {
|
|
459
|
+
* const { data } = useReadQuery(queryRef);
|
|
460
|
+
*
|
|
461
|
+
* // do something with `data`
|
|
462
|
+
* }
|
|
463
|
+
* ```
|
|
464
|
+
*/
|
|
465
|
+
interface Modern {
|
|
466
|
+
/**
|
|
467
|
+
* A function that will begin loading a query when called. It's result can be
|
|
468
|
+
* read by `useReadQuery` which will suspend until the query is loaded.
|
|
469
|
+
* This is useful when you want to start loading a query as early as possible
|
|
470
|
+
* outside of a React component.
|
|
471
|
+
*
|
|
472
|
+
* @example
|
|
473
|
+
*
|
|
474
|
+
* ```js
|
|
475
|
+
* const preloadQuery = createQueryPreloader(client);
|
|
476
|
+
* const queryRef = preloadQuery(query, { variables, ...otherOptions });
|
|
477
|
+
*
|
|
478
|
+
* function App() {
|
|
479
|
+
* return (
|
|
480
|
+
* <Suspense fallback={<div>Loading</div>}>
|
|
481
|
+
* <MyQuery />
|
|
482
|
+
* </Suspense>
|
|
483
|
+
* );
|
|
484
|
+
* }
|
|
485
|
+
*
|
|
486
|
+
* function MyQuery() {
|
|
487
|
+
* const { data } = useReadQuery(queryRef);
|
|
488
|
+
*
|
|
489
|
+
* // do something with `data`
|
|
490
|
+
* }
|
|
491
|
+
* ```
|
|
492
|
+
*/
|
|
493
|
+
<TData, TVariables extends OperationVariables, TOptions extends never>(query: {} extends TVariables ? DocumentNode | TypedDocumentNode<TData, TVariables> : never): PreloadQueryFunction.ResultForOptions<TData, TVariables, Record<string, never>>;
|
|
494
|
+
/**
|
|
495
|
+
* A function that will begin loading a query when called. It's result can be
|
|
496
|
+
* read by `useReadQuery` which will suspend until the query is loaded.
|
|
497
|
+
* This is useful when you want to start loading a query as early as possible
|
|
498
|
+
* outside of a React component.
|
|
499
|
+
*
|
|
500
|
+
* @example
|
|
501
|
+
*
|
|
502
|
+
* ```js
|
|
503
|
+
* const preloadQuery = createQueryPreloader(client);
|
|
504
|
+
* const queryRef = preloadQuery(query, { variables, ...otherOptions });
|
|
505
|
+
*
|
|
506
|
+
* function App() {
|
|
507
|
+
* return (
|
|
508
|
+
* <Suspense fallback={<div>Loading</div>}>
|
|
509
|
+
* <MyQuery />
|
|
510
|
+
* </Suspense>
|
|
511
|
+
* );
|
|
512
|
+
* }
|
|
513
|
+
*
|
|
514
|
+
* function MyQuery() {
|
|
515
|
+
* const { data } = useReadQuery(queryRef);
|
|
516
|
+
*
|
|
517
|
+
* // do something with `data`
|
|
518
|
+
* }
|
|
519
|
+
* ```
|
|
520
|
+
*/
|
|
521
|
+
<TData, TVariables extends OperationVariables, TOptions extends PreloadQueryOptions<NoInfer<TVariables>> & VariablesOption<TVariables & {
|
|
522
|
+
[K in Exclude<keyof TOptions["variables"], keyof TVariables>]?: never;
|
|
523
|
+
}>>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, ...[options]: {} extends TVariables ? [options?: TOptions] : [options: TOptions]): PreloadQueryFunction.ResultForOptions<TData, TVariables, TOptions>;
|
|
524
|
+
}
|
|
525
|
+
type Evaluated = SignatureStyle extends "classic" ? Classic : Modern;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
256
528
|
/**
|
|
257
529
|
* A higher order function that returns a `preloadQuery` function which
|
|
258
530
|
* can be used to begin loading a query with the given `client`. This is useful
|
package/__cjs/version.cjs
CHANGED
package/core/ApolloClient.js
CHANGED
|
@@ -222,22 +222,42 @@ export class ApolloClient {
|
|
|
222
222
|
* a description of store reactivity.
|
|
223
223
|
*/
|
|
224
224
|
watchQuery(options) {
|
|
225
|
+
const { refetchOn } = options;
|
|
225
226
|
if (this.defaultOptions.watchQuery) {
|
|
227
|
+
// Capture the default `refetchOn` at the time of the `watchQuery`
|
|
228
|
+
// call so that it is unaffected even if defaultOptions.refetchOn is
|
|
229
|
+
// mutated later.
|
|
226
230
|
const defaultRefetchOn = this.defaultOptions.watchQuery.refetchOn;
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
defaultRefetchOn
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
231
|
+
let mergedRefetchOn;
|
|
232
|
+
if (refetchOn && typeof refetchOn === "object") {
|
|
233
|
+
if (typeof defaultRefetchOn === "object") {
|
|
234
|
+
mergedRefetchOn = { ...defaultRefetchOn, ...refetchOn };
|
|
235
|
+
}
|
|
236
|
+
else if (defaultRefetchOn != null) {
|
|
237
|
+
// We set the merged `refetchOn` option to a callback function in case
|
|
238
|
+
// the client hasn't connected to a RefetchEventManager yet, or
|
|
239
|
+
// sources are added to the manager after watchQuery is called. This
|
|
240
|
+
// ensures we can handle any registered source regardless of when it
|
|
241
|
+
// was registered.
|
|
242
|
+
mergedRefetchOn = (ctx) => {
|
|
243
|
+
const value = refetchOn[ctx.source] ?? defaultRefetchOn;
|
|
244
|
+
if (typeof value === "function") {
|
|
245
|
+
return value(ctx);
|
|
246
|
+
}
|
|
247
|
+
return value;
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
}
|
|
233
251
|
options = mergeOptions(this.defaultOptions.watchQuery, options);
|
|
234
252
|
if (mergedRefetchOn) {
|
|
235
253
|
options.refetchOn = mergedRefetchOn;
|
|
236
254
|
}
|
|
237
255
|
}
|
|
238
256
|
if (__DEV__) {
|
|
239
|
-
const {
|
|
257
|
+
const { query } = options;
|
|
240
258
|
const { refetchEventManager } = this;
|
|
259
|
+
// Note: refetchOn evaluates the original refetchOn value, not the merged
|
|
260
|
+
// refetchOn value.
|
|
241
261
|
if (refetchOn) {
|
|
242
262
|
const operationName = getOperationName(query, "(anonymous)");
|
|
243
263
|
if (!refetchEventManager) {
|