@octanejs/apollo-client 0.1.0
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/LICENSE +49 -0
- package/README.md +97 -0
- package/package.json +77 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +3 -0
- package/src/react/context/ApolloContext.d.ts +8 -0
- package/src/react/context/ApolloContext.js +21 -0
- package/src/react/context/ApolloProvider.d.ts +9 -0
- package/src/react/context/ApolloProvider.js +15 -0
- package/src/react/hooks/constants.d.ts +2 -0
- package/src/react/hooks/constants.js +1 -0
- package/src/react/hooks/internal/__use.d.ts +3 -0
- package/src/react/hooks/internal/__use.js +9 -0
- package/src/react/hooks/internal/index.d.ts +5 -0
- package/src/react/hooks/internal/index.js +6 -0
- package/src/react/hooks/internal/site.d.ts +2 -0
- package/src/react/hooks/internal/site.js +20 -0
- package/src/react/hooks/internal/useDeepMemo.d.ts +5 -0
- package/src/react/hooks/internal/useDeepMemo.js +11 -0
- package/src/react/hooks/internal/useIsomorphicLayoutEffect.d.ts +2 -0
- package/src/react/hooks/internal/useIsomorphicLayoutEffect.js +8 -0
- package/src/react/hooks/internal/useRenderGuard.d.ts +1 -0
- package/src/react/hooks/internal/useRenderGuard.js +14 -0
- package/src/react/hooks/internal/useSuspenseHookCacheKey.d.ts +13 -0
- package/src/react/hooks/internal/useSuspenseHookCacheKey.js +19 -0
- package/src/react/hooks/internal/validateSuspenseHookOptions.d.ts +4 -0
- package/src/react/hooks/internal/validateSuspenseHookOptions.js +16 -0
- package/src/react/hooks/internal/wrapHook.d.ts +77 -0
- package/src/react/hooks/internal/wrapHook.js +64 -0
- package/src/react/hooks/useApolloClient.d.ts +17 -0
- package/src/react/hooks/useApolloClient.js +27 -0
- package/src/react/hooks/useBackgroundQuery.d.ts +3061 -0
- package/src/react/hooks/useBackgroundQuery.js +88 -0
- package/src/react/hooks/useFragment.d.ts +205 -0
- package/src/react/hooks/useFragment.js +75 -0
- package/src/react/hooks/useLazyQuery.d.ts +947 -0
- package/src/react/hooks/useLazyQuery.js +156 -0
- package/src/react/hooks/useLoadableQuery.d.ts +955 -0
- package/src/react/hooks/useLoadableQuery.js +98 -0
- package/src/react/hooks/useMutation.d.ts +585 -0
- package/src/react/hooks/useMutation.js +121 -0
- package/src/react/hooks/useQuery.d.ts +1401 -0
- package/src/react/hooks/useQuery.js +234 -0
- package/src/react/hooks/useQueryRefHandlers.d.ts +85 -0
- package/src/react/hooks/useQueryRefHandlers.js +79 -0
- package/src/react/hooks/useReactiveVar.d.ts +21 -0
- package/src/react/hooks/useReactiveVar.js +41 -0
- package/src/react/hooks/useReadQuery.d.ts +104 -0
- package/src/react/hooks/useReadQuery.js +83 -0
- package/src/react/hooks/useSubscription.d.ts +289 -0
- package/src/react/hooks/useSubscription.js +258 -0
- package/src/react/hooks/useSuspenseFragment.d.ts +154 -0
- package/src/react/hooks/useSuspenseFragment.js +50 -0
- package/src/react/hooks/useSuspenseQuery.d.ts +1629 -0
- package/src/react/hooks/useSuspenseQuery.js +130 -0
- package/src/react/hooks/useSyncExternalStore.d.ts +2 -0
- package/src/react/hooks/useSyncExternalStore.js +125 -0
- package/src/react/index.d.ts +68 -0
- package/src/react/index.js +18 -0
- package/src/react/internal/cache/FragmentReference.d.ts +41 -0
- package/src/react/internal/cache/FragmentReference.js +117 -0
- package/src/react/internal/cache/QueryReference.d.ts +180 -0
- package/src/react/internal/cache/QueryReference.js +310 -0
- package/src/react/internal/cache/SuspenseCache.d.ts +38 -0
- package/src/react/internal/cache/SuspenseCache.js +39 -0
- package/src/react/internal/cache/getSuspenseCache.d.ts +26 -0
- package/src/react/internal/cache/getSuspenseCache.js +8 -0
- package/src/react/internal/cache/types.d.ts +13 -0
- package/src/react/internal/cache/types.js +1 -0
- package/src/react/internal/index.d.ts +16 -0
- package/src/react/internal/index.js +10 -0
- package/src/react/internal/types.d.ts +15 -0
- package/src/react/internal/types.js +1 -0
- package/src/react/query-preloader/createQueryPreloader.d.ts +630 -0
- package/src/react/query-preloader/createQueryPreloader.js +89 -0
- package/src/react/types/deprecated.d.ts +140 -0
- package/src/react/types/deprecated.js +1 -0
- package/src/react/types/types.documentation.d.ts +551 -0
- package/src/react/types/types.documentation.js +1 -0
- package/src/testing/index.d.ts +1 -0
- package/src/testing/index.js +1 -0
- package/src/testing/react/MockedProvider.d.ts +21 -0
- package/src/testing/react/MockedProvider.js +53 -0
- package/src/testing/react/index.d.ts +2 -0
- package/src/testing/react/index.js +1 -0
|
@@ -0,0 +1,630 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ApolloClient,
|
|
3
|
+
DefaultContext,
|
|
4
|
+
DocumentNode,
|
|
5
|
+
ErrorPolicy,
|
|
6
|
+
OperationVariables,
|
|
7
|
+
RefetchOn,
|
|
8
|
+
RefetchWritePolicy,
|
|
9
|
+
TypedDocumentNode,
|
|
10
|
+
WatchQueryFetchPolicy,
|
|
11
|
+
} from '@apollo/client';
|
|
12
|
+
import type { PreloadedQueryRef } from '@octanejs/apollo-client/react';
|
|
13
|
+
import type {
|
|
14
|
+
NoInfer,
|
|
15
|
+
OptionWithFallback,
|
|
16
|
+
SignatureStyle,
|
|
17
|
+
VariablesOption,
|
|
18
|
+
} from '@apollo/client/utilities/internal';
|
|
19
|
+
export type PreloadQueryFetchPolicy = Extract<
|
|
20
|
+
WatchQueryFetchPolicy,
|
|
21
|
+
'cache-first' | 'network-only' | 'no-cache' | 'cache-and-network'
|
|
22
|
+
>;
|
|
23
|
+
export type PreloadQueryOptions<TVariables extends OperationVariables = OperationVariables> = {
|
|
24
|
+
/**
|
|
25
|
+
* If you're using [Apollo Link](https://www.apollographql.com/docs/react/api/link/introduction/), this object is the initial value of the `context` object that's passed along your link chain.
|
|
26
|
+
*
|
|
27
|
+
* @docGroup 2. Networking options
|
|
28
|
+
*/
|
|
29
|
+
context?: DefaultContext;
|
|
30
|
+
/**
|
|
31
|
+
* Specifies how the query handles a response that returns both GraphQL errors and partial results.
|
|
32
|
+
*
|
|
33
|
+
* For details, see [GraphQL error policies](https://www.apollographql.com/docs/react/data/error-handling/#graphql-error-policies).
|
|
34
|
+
*
|
|
35
|
+
* The default value is `none`, meaning that the query result includes error details but not partial results.
|
|
36
|
+
*
|
|
37
|
+
* @docGroup 1. Operation options
|
|
38
|
+
*/
|
|
39
|
+
errorPolicy?: ErrorPolicy;
|
|
40
|
+
/**
|
|
41
|
+
* Specifies how the query interacts with the Apollo Client cache during execution (for example, whether it checks the cache for results before sending a request to the server).
|
|
42
|
+
*
|
|
43
|
+
* For details, see [Setting a fetch policy](https://www.apollographql.com/docs/react/data/queries/#setting-a-fetch-policy).
|
|
44
|
+
*
|
|
45
|
+
* The default value is `cache-first`.
|
|
46
|
+
*
|
|
47
|
+
* @docGroup 3. Caching options
|
|
48
|
+
*/
|
|
49
|
+
fetchPolicy?: PreloadQueryFetchPolicy;
|
|
50
|
+
/**
|
|
51
|
+
* If `true`, the query can return partial results from the cache if the cache doesn't contain results for all queried fields.
|
|
52
|
+
*
|
|
53
|
+
* The default value is `false`.
|
|
54
|
+
*
|
|
55
|
+
* @docGroup 3. Caching options
|
|
56
|
+
*/
|
|
57
|
+
returnPartialData?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Specifies whether a `NetworkStatus.refetch` operation should merge
|
|
60
|
+
* incoming field data with existing data, or overwrite the existing data.
|
|
61
|
+
* Overwriting is probably preferable, but merging is currently the default
|
|
62
|
+
* behavior, for backwards compatibility with Apollo Client 3.x.
|
|
63
|
+
*
|
|
64
|
+
* @docGroup 3. Caching options
|
|
65
|
+
*/
|
|
66
|
+
refetchWritePolicy?: RefetchWritePolicy;
|
|
67
|
+
/**
|
|
68
|
+
* Determines whether events trigger refetches for the query. Provide an
|
|
69
|
+
* object mapping each refetch event to `true` (enable), `false` (disable)
|
|
70
|
+
* or a callback function that returns `true`/`false` to control individual
|
|
71
|
+
* events. Provide `false` to disable all automatic refetch events for this
|
|
72
|
+
* query. Provide `true` to enable all automatic refetch events for this query.
|
|
73
|
+
* Provide a callback function to perform additional logic to determine
|
|
74
|
+
* whether to enable or disable a refetch for a query.
|
|
75
|
+
*
|
|
76
|
+
* `@remarks`
|
|
77
|
+
* `refetchOn` inherits from `defaultOptions.watchQuery.refetchOn`. If
|
|
78
|
+
* `defaultOptions.watchQuery.refetchOn` is not set, all refetch events are
|
|
79
|
+
* enabled by default.
|
|
80
|
+
*
|
|
81
|
+
* This option only has an effect when the client is configured with a
|
|
82
|
+
* `refetchEventManager`.
|
|
83
|
+
* @docGroup 1. Operation options
|
|
84
|
+
*/
|
|
85
|
+
refetchOn?: RefetchOn.Option;
|
|
86
|
+
} & VariablesOption<TVariables>;
|
|
87
|
+
/**
|
|
88
|
+
* A function that will begin loading a query when called. It's result can be
|
|
89
|
+
* read by `useReadQuery` which will suspend until the query is loaded.
|
|
90
|
+
* This is useful when you want to start loading a query as early as possible
|
|
91
|
+
* outside of a React component.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
*
|
|
95
|
+
* ```js
|
|
96
|
+
* const preloadQuery = createQueryPreloader(client);
|
|
97
|
+
* const queryRef = preloadQuery(query, { variables, ...otherOptions });
|
|
98
|
+
*
|
|
99
|
+
* function App() {
|
|
100
|
+
* return (
|
|
101
|
+
* <Suspense fallback={<div>Loading</div>}>
|
|
102
|
+
* <MyQuery />
|
|
103
|
+
* </Suspense>
|
|
104
|
+
* );
|
|
105
|
+
* }
|
|
106
|
+
*
|
|
107
|
+
* function MyQuery() {
|
|
108
|
+
* const { data } = useReadQuery(queryRef);
|
|
109
|
+
*
|
|
110
|
+
* // do something with `data`
|
|
111
|
+
* }
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export interface PreloadQueryFunction extends PreloadQueryFunction.Signatures.Evaluated {
|
|
115
|
+
/**
|
|
116
|
+
* A function that returns a promise that resolves when the query has finished
|
|
117
|
+
* loading. The promise resolves with the `QueryReference` itself.
|
|
118
|
+
*
|
|
119
|
+
* @remarks
|
|
120
|
+
* This method is useful for preloading queries in data loading routers, such
|
|
121
|
+
* as [React Router](https://reactrouter.com/en/main) or [TanStack Router](https://tanstack.com/router),
|
|
122
|
+
* to prevent routes from transitioning until the query has finished loading.
|
|
123
|
+
* `data` is not exposed on the promise to discourage using the data in
|
|
124
|
+
* `loader` functions and exposing it to your route components. Instead, we
|
|
125
|
+
* prefer you rely on `useReadQuery` to access the data to ensure your
|
|
126
|
+
* component can rerender with cache updates. If you need to access raw query
|
|
127
|
+
* data, use `client.query()` directly.
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* Here's an example using React Router's `loader` function:
|
|
131
|
+
*
|
|
132
|
+
* ```ts
|
|
133
|
+
* import { createQueryPreloader } from "@apollo/client";
|
|
134
|
+
*
|
|
135
|
+
* const preloadQuery = createQueryPreloader(client);
|
|
136
|
+
*
|
|
137
|
+
* export async function loader() {
|
|
138
|
+
* const queryRef = preloadQuery(GET_DOGS_QUERY);
|
|
139
|
+
*
|
|
140
|
+
* return preloadQuery.toPromise(queryRef);
|
|
141
|
+
* }
|
|
142
|
+
*
|
|
143
|
+
* export function RouteComponent() {
|
|
144
|
+
* const queryRef = useLoaderData();
|
|
145
|
+
* const { data } = useReadQuery(queryRef);
|
|
146
|
+
*
|
|
147
|
+
* // ...
|
|
148
|
+
* }
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
toPromise<TQueryRef extends PreloadedQueryRef<any, any, any>>(
|
|
152
|
+
queryRef: TQueryRef,
|
|
153
|
+
): Promise<TQueryRef>;
|
|
154
|
+
}
|
|
155
|
+
export declare namespace PreloadQueryFunction {
|
|
156
|
+
interface DefaultOptions extends ApolloClient.DefaultOptions.WatchQuery.Calculated {}
|
|
157
|
+
namespace DocumentationTypes {
|
|
158
|
+
/**
|
|
159
|
+
* @deprecated Avoid manually specifying generics on `preloadQuery`.
|
|
160
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
161
|
+
*
|
|
162
|
+
*
|
|
163
|
+
* A function that will begin loading a query when called. It's result can be
|
|
164
|
+
* read by `useReadQuery` which will suspend until the query is loaded.
|
|
165
|
+
* This is useful when you want to start loading a query as early as possible
|
|
166
|
+
* outside of a React component.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
*
|
|
170
|
+
* ```js
|
|
171
|
+
* const preloadQuery = createQueryPreloader(client);
|
|
172
|
+
* const queryRef = preloadQuery(query, { variables, ...otherOptions });
|
|
173
|
+
*
|
|
174
|
+
* function App() {
|
|
175
|
+
* return (
|
|
176
|
+
* <Suspense fallback={<div>Loading</div>}>
|
|
177
|
+
* <MyQuery />
|
|
178
|
+
* </Suspense>
|
|
179
|
+
* );
|
|
180
|
+
* }
|
|
181
|
+
*
|
|
182
|
+
* function MyQuery() {
|
|
183
|
+
* const { data } = useReadQuery(queryRef);
|
|
184
|
+
*
|
|
185
|
+
* // do something with `data`
|
|
186
|
+
* }
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
interface PreloadQueryFunction_Deprecated extends PreloadQueryFunction {}
|
|
190
|
+
}
|
|
191
|
+
type ResultForOptions<
|
|
192
|
+
TData,
|
|
193
|
+
TVariables extends OperationVariables,
|
|
194
|
+
TOptions extends Record<string, never> | PreloadQueryOptions<TVariables>,
|
|
195
|
+
> = TOptions extends any
|
|
196
|
+
? PreloadedQueryRef<TData, TVariables, ResultForOptions.States<TOptions, DefaultOptions>>
|
|
197
|
+
: never;
|
|
198
|
+
namespace ResultForOptions {
|
|
199
|
+
type States<TOptions, TDefaultOptions extends DefaultOptions = DefaultOptions> =
|
|
200
|
+
| 'complete'
|
|
201
|
+
| 'streaming'
|
|
202
|
+
| (OptionWithFallback<TOptions, TDefaultOptions, 'errorPolicy'> extends 'none'
|
|
203
|
+
? never
|
|
204
|
+
: 'empty')
|
|
205
|
+
| (OptionWithFallback<TOptions, TDefaultOptions, 'returnPartialData'> extends false
|
|
206
|
+
? never
|
|
207
|
+
: 'partial');
|
|
208
|
+
}
|
|
209
|
+
namespace Signatures {
|
|
210
|
+
interface Classic {
|
|
211
|
+
/**
|
|
212
|
+
* A function that will begin loading a query when called. It's result can be
|
|
213
|
+
* read by `useReadQuery` which will suspend until the query is loaded.
|
|
214
|
+
* This is useful when you want to start loading a query as early as possible
|
|
215
|
+
* outside of a React component.
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
*
|
|
219
|
+
* ```js
|
|
220
|
+
* const preloadQuery = createQueryPreloader(client);
|
|
221
|
+
* const queryRef = preloadQuery(query, { variables, ...otherOptions });
|
|
222
|
+
*
|
|
223
|
+
* function App() {
|
|
224
|
+
* return (
|
|
225
|
+
* <Suspense fallback={<div>Loading</div>}>
|
|
226
|
+
* <MyQuery />
|
|
227
|
+
* </Suspense>
|
|
228
|
+
* );
|
|
229
|
+
* }
|
|
230
|
+
*
|
|
231
|
+
* function MyQuery() {
|
|
232
|
+
* const { data } = useReadQuery(queryRef);
|
|
233
|
+
*
|
|
234
|
+
* // do something with `data`
|
|
235
|
+
* }
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
<
|
|
239
|
+
TData,
|
|
240
|
+
TVariables extends OperationVariables,
|
|
241
|
+
_INFERENCE_ONLY_DO_NOT_SPECIFY extends 'inferred',
|
|
242
|
+
>(
|
|
243
|
+
query: DocumentNode | TypedDocumentNode<TData, TVariables>,
|
|
244
|
+
options: PreloadQueryOptions<NoInfer<TVariables>> & {
|
|
245
|
+
returnPartialData: true;
|
|
246
|
+
errorPolicy: 'ignore' | 'all';
|
|
247
|
+
},
|
|
248
|
+
): PreloadedQueryRef<TData, TVariables, 'complete' | 'streaming' | 'partial' | 'empty'>;
|
|
249
|
+
/**
|
|
250
|
+
* A function that will begin loading a query when called. It's result can be
|
|
251
|
+
* read by `useReadQuery` which will suspend until the query is loaded.
|
|
252
|
+
* This is useful when you want to start loading a query as early as possible
|
|
253
|
+
* outside of a React component.
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
*
|
|
257
|
+
* ```js
|
|
258
|
+
* const preloadQuery = createQueryPreloader(client);
|
|
259
|
+
* const queryRef = preloadQuery(query, { variables, ...otherOptions });
|
|
260
|
+
*
|
|
261
|
+
* function App() {
|
|
262
|
+
* return (
|
|
263
|
+
* <Suspense fallback={<div>Loading</div>}>
|
|
264
|
+
* <MyQuery />
|
|
265
|
+
* </Suspense>
|
|
266
|
+
* );
|
|
267
|
+
* }
|
|
268
|
+
*
|
|
269
|
+
* function MyQuery() {
|
|
270
|
+
* const { data } = useReadQuery(queryRef);
|
|
271
|
+
*
|
|
272
|
+
* // do something with `data`
|
|
273
|
+
* }
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
276
|
+
<
|
|
277
|
+
TData,
|
|
278
|
+
TVariables extends OperationVariables,
|
|
279
|
+
_INFERENCE_ONLY_DO_NOT_SPECIFY extends 'inferred',
|
|
280
|
+
>(
|
|
281
|
+
query: DocumentNode | TypedDocumentNode<TData, TVariables>,
|
|
282
|
+
options: PreloadQueryOptions<NoInfer<TVariables>> & {
|
|
283
|
+
errorPolicy: 'ignore' | 'all';
|
|
284
|
+
},
|
|
285
|
+
): PreloadedQueryRef<TData, TVariables, 'complete' | 'streaming' | 'empty'>;
|
|
286
|
+
/**
|
|
287
|
+
* A function that will begin loading a query when called. It's result can be
|
|
288
|
+
* read by `useReadQuery` which will suspend until the query is loaded.
|
|
289
|
+
* This is useful when you want to start loading a query as early as possible
|
|
290
|
+
* outside of a React component.
|
|
291
|
+
*
|
|
292
|
+
* @example
|
|
293
|
+
*
|
|
294
|
+
* ```js
|
|
295
|
+
* const preloadQuery = createQueryPreloader(client);
|
|
296
|
+
* const queryRef = preloadQuery(query, { variables, ...otherOptions });
|
|
297
|
+
*
|
|
298
|
+
* function App() {
|
|
299
|
+
* return (
|
|
300
|
+
* <Suspense fallback={<div>Loading</div>}>
|
|
301
|
+
* <MyQuery />
|
|
302
|
+
* </Suspense>
|
|
303
|
+
* );
|
|
304
|
+
* }
|
|
305
|
+
*
|
|
306
|
+
* function MyQuery() {
|
|
307
|
+
* const { data } = useReadQuery(queryRef);
|
|
308
|
+
*
|
|
309
|
+
* // do something with `data`
|
|
310
|
+
* }
|
|
311
|
+
* ```
|
|
312
|
+
*/
|
|
313
|
+
<
|
|
314
|
+
TData,
|
|
315
|
+
TVariables extends OperationVariables,
|
|
316
|
+
_INFERENCE_ONLY_DO_NOT_SPECIFY extends 'inferred',
|
|
317
|
+
>(
|
|
318
|
+
query: DocumentNode | TypedDocumentNode<TData, TVariables>,
|
|
319
|
+
options: PreloadQueryOptions<NoInfer<TVariables>> & {
|
|
320
|
+
returnPartialData: true;
|
|
321
|
+
},
|
|
322
|
+
): PreloadedQueryRef<TData, TVariables, 'complete' | 'streaming' | 'partial'>;
|
|
323
|
+
/**
|
|
324
|
+
* A function that will begin loading a query when called. It's result can be
|
|
325
|
+
* read by `useReadQuery` which will suspend until the query is loaded.
|
|
326
|
+
* This is useful when you want to start loading a query as early as possible
|
|
327
|
+
* outside of a React component.
|
|
328
|
+
*
|
|
329
|
+
* @example
|
|
330
|
+
*
|
|
331
|
+
* ```js
|
|
332
|
+
* const preloadQuery = createQueryPreloader(client);
|
|
333
|
+
* const queryRef = preloadQuery(query, { variables, ...otherOptions });
|
|
334
|
+
*
|
|
335
|
+
* function App() {
|
|
336
|
+
* return (
|
|
337
|
+
* <Suspense fallback={<div>Loading</div>}>
|
|
338
|
+
* <MyQuery />
|
|
339
|
+
* </Suspense>
|
|
340
|
+
* );
|
|
341
|
+
* }
|
|
342
|
+
*
|
|
343
|
+
* function MyQuery() {
|
|
344
|
+
* const { data } = useReadQuery(queryRef);
|
|
345
|
+
*
|
|
346
|
+
* // do something with `data`
|
|
347
|
+
* }
|
|
348
|
+
* ```
|
|
349
|
+
*/
|
|
350
|
+
<
|
|
351
|
+
TData,
|
|
352
|
+
TVariables extends OperationVariables,
|
|
353
|
+
_INFERENCE_ONLY_DO_NOT_SPECIFY extends 'inferred',
|
|
354
|
+
>(
|
|
355
|
+
query: DocumentNode | TypedDocumentNode<TData, TVariables>,
|
|
356
|
+
...[options]: {} extends TVariables
|
|
357
|
+
? [options?: PreloadQueryOptions<NoInfer<TVariables>>]
|
|
358
|
+
: [options: PreloadQueryOptions<NoInfer<TVariables>>]
|
|
359
|
+
): PreloadedQueryRef<TData, TVariables, 'complete' | 'streaming'>;
|
|
360
|
+
/**
|
|
361
|
+
* @deprecated Avoid manually specifying generics on `preloadQuery`.
|
|
362
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
363
|
+
*
|
|
364
|
+
*
|
|
365
|
+
* A function that will begin loading a query when called. It's result can be
|
|
366
|
+
* read by `useReadQuery` which will suspend until the query is loaded.
|
|
367
|
+
* This is useful when you want to start loading a query as early as possible
|
|
368
|
+
* outside of a React component.
|
|
369
|
+
*
|
|
370
|
+
* @example
|
|
371
|
+
*
|
|
372
|
+
* ```js
|
|
373
|
+
* const preloadQuery = createQueryPreloader(client);
|
|
374
|
+
* const queryRef = preloadQuery(query, { variables, ...otherOptions });
|
|
375
|
+
*
|
|
376
|
+
* function App() {
|
|
377
|
+
* return (
|
|
378
|
+
* <Suspense fallback={<div>Loading</div>}>
|
|
379
|
+
* <MyQuery />
|
|
380
|
+
* </Suspense>
|
|
381
|
+
* );
|
|
382
|
+
* }
|
|
383
|
+
*
|
|
384
|
+
* function MyQuery() {
|
|
385
|
+
* const { data } = useReadQuery(queryRef);
|
|
386
|
+
*
|
|
387
|
+
* // do something with `data`
|
|
388
|
+
* }
|
|
389
|
+
* ```
|
|
390
|
+
*/
|
|
391
|
+
<TData, TVariables extends OperationVariables = OperationVariables>(
|
|
392
|
+
query: DocumentNode | TypedDocumentNode<TData, TVariables>,
|
|
393
|
+
options: PreloadQueryOptions<NoInfer<TVariables>> & {
|
|
394
|
+
returnPartialData: true;
|
|
395
|
+
errorPolicy: 'ignore' | 'all';
|
|
396
|
+
},
|
|
397
|
+
): PreloadedQueryRef<TData, TVariables, 'complete' | 'streaming' | 'partial' | 'empty'>;
|
|
398
|
+
/**
|
|
399
|
+
* @deprecated Avoid manually specifying generics on `preloadQuery`.
|
|
400
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
401
|
+
*
|
|
402
|
+
*
|
|
403
|
+
* A function that will begin loading a query when called. It's result can be
|
|
404
|
+
* read by `useReadQuery` which will suspend until the query is loaded.
|
|
405
|
+
* This is useful when you want to start loading a query as early as possible
|
|
406
|
+
* outside of a React component.
|
|
407
|
+
*
|
|
408
|
+
* @example
|
|
409
|
+
*
|
|
410
|
+
* ```js
|
|
411
|
+
* const preloadQuery = createQueryPreloader(client);
|
|
412
|
+
* const queryRef = preloadQuery(query, { variables, ...otherOptions });
|
|
413
|
+
*
|
|
414
|
+
* function App() {
|
|
415
|
+
* return (
|
|
416
|
+
* <Suspense fallback={<div>Loading</div>}>
|
|
417
|
+
* <MyQuery />
|
|
418
|
+
* </Suspense>
|
|
419
|
+
* );
|
|
420
|
+
* }
|
|
421
|
+
*
|
|
422
|
+
* function MyQuery() {
|
|
423
|
+
* const { data } = useReadQuery(queryRef);
|
|
424
|
+
*
|
|
425
|
+
* // do something with `data`
|
|
426
|
+
* }
|
|
427
|
+
* ```
|
|
428
|
+
*/
|
|
429
|
+
<TData, TVariables extends OperationVariables = OperationVariables>(
|
|
430
|
+
query: DocumentNode | TypedDocumentNode<TData, TVariables>,
|
|
431
|
+
options: PreloadQueryOptions<NoInfer<TVariables>> & {
|
|
432
|
+
errorPolicy: 'ignore' | 'all';
|
|
433
|
+
},
|
|
434
|
+
): PreloadedQueryRef<TData, TVariables, 'complete' | 'streaming' | 'empty'>;
|
|
435
|
+
/**
|
|
436
|
+
* @deprecated Avoid manually specifying generics on `preloadQuery`.
|
|
437
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
438
|
+
*
|
|
439
|
+
*
|
|
440
|
+
* A function that will begin loading a query when called. It's result can be
|
|
441
|
+
* read by `useReadQuery` which will suspend until the query is loaded.
|
|
442
|
+
* This is useful when you want to start loading a query as early as possible
|
|
443
|
+
* outside of a React component.
|
|
444
|
+
*
|
|
445
|
+
* @example
|
|
446
|
+
*
|
|
447
|
+
* ```js
|
|
448
|
+
* const preloadQuery = createQueryPreloader(client);
|
|
449
|
+
* const queryRef = preloadQuery(query, { variables, ...otherOptions });
|
|
450
|
+
*
|
|
451
|
+
* function App() {
|
|
452
|
+
* return (
|
|
453
|
+
* <Suspense fallback={<div>Loading</div>}>
|
|
454
|
+
* <MyQuery />
|
|
455
|
+
* </Suspense>
|
|
456
|
+
* );
|
|
457
|
+
* }
|
|
458
|
+
*
|
|
459
|
+
* function MyQuery() {
|
|
460
|
+
* const { data } = useReadQuery(queryRef);
|
|
461
|
+
*
|
|
462
|
+
* // do something with `data`
|
|
463
|
+
* }
|
|
464
|
+
* ```
|
|
465
|
+
*/
|
|
466
|
+
<TData, TVariables extends OperationVariables = OperationVariables>(
|
|
467
|
+
query: DocumentNode | TypedDocumentNode<TData, TVariables>,
|
|
468
|
+
options: PreloadQueryOptions<NoInfer<TVariables>> & {
|
|
469
|
+
returnPartialData: true;
|
|
470
|
+
},
|
|
471
|
+
): PreloadedQueryRef<TData, TVariables, 'complete' | 'streaming' | 'partial'>;
|
|
472
|
+
/**
|
|
473
|
+
* @deprecated Avoid manually specifying generics on `preloadQuery`.
|
|
474
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
475
|
+
*
|
|
476
|
+
*
|
|
477
|
+
* A function that will begin loading a query when called. It's result can be
|
|
478
|
+
* read by `useReadQuery` which will suspend until the query is loaded.
|
|
479
|
+
* This is useful when you want to start loading a query as early as possible
|
|
480
|
+
* outside of a React component.
|
|
481
|
+
*
|
|
482
|
+
* @example
|
|
483
|
+
*
|
|
484
|
+
* ```js
|
|
485
|
+
* const preloadQuery = createQueryPreloader(client);
|
|
486
|
+
* const queryRef = preloadQuery(query, { variables, ...otherOptions });
|
|
487
|
+
*
|
|
488
|
+
* function App() {
|
|
489
|
+
* return (
|
|
490
|
+
* <Suspense fallback={<div>Loading</div>}>
|
|
491
|
+
* <MyQuery />
|
|
492
|
+
* </Suspense>
|
|
493
|
+
* );
|
|
494
|
+
* }
|
|
495
|
+
*
|
|
496
|
+
* function MyQuery() {
|
|
497
|
+
* const { data } = useReadQuery(queryRef);
|
|
498
|
+
*
|
|
499
|
+
* // do something with `data`
|
|
500
|
+
* }
|
|
501
|
+
* ```
|
|
502
|
+
*/
|
|
503
|
+
<TData, TVariables extends OperationVariables = OperationVariables>(
|
|
504
|
+
query: DocumentNode | TypedDocumentNode<TData, TVariables>,
|
|
505
|
+
...[options]: {} extends TVariables
|
|
506
|
+
? [options?: PreloadQueryOptions<NoInfer<TVariables>>]
|
|
507
|
+
: [options: PreloadQueryOptions<NoInfer<TVariables>>]
|
|
508
|
+
): PreloadedQueryRef<TData, TVariables, 'complete' | 'streaming'>;
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* A function that will begin loading a query when called. It's result can be
|
|
512
|
+
* read by `useReadQuery` which will suspend until the query is loaded.
|
|
513
|
+
* This is useful when you want to start loading a query as early as possible
|
|
514
|
+
* outside of a React component.
|
|
515
|
+
*
|
|
516
|
+
* @example
|
|
517
|
+
*
|
|
518
|
+
* ```js
|
|
519
|
+
* const preloadQuery = createQueryPreloader(client);
|
|
520
|
+
* const queryRef = preloadQuery(query, { variables, ...otherOptions });
|
|
521
|
+
*
|
|
522
|
+
* function App() {
|
|
523
|
+
* return (
|
|
524
|
+
* <Suspense fallback={<div>Loading</div>}>
|
|
525
|
+
* <MyQuery />
|
|
526
|
+
* </Suspense>
|
|
527
|
+
* );
|
|
528
|
+
* }
|
|
529
|
+
*
|
|
530
|
+
* function MyQuery() {
|
|
531
|
+
* const { data } = useReadQuery(queryRef);
|
|
532
|
+
*
|
|
533
|
+
* // do something with `data`
|
|
534
|
+
* }
|
|
535
|
+
* ```
|
|
536
|
+
*/
|
|
537
|
+
interface Modern {
|
|
538
|
+
/**
|
|
539
|
+
* A function that will begin loading a query when called. It's result can be
|
|
540
|
+
* read by `useReadQuery` which will suspend until the query is loaded.
|
|
541
|
+
* This is useful when you want to start loading a query as early as possible
|
|
542
|
+
* outside of a React component.
|
|
543
|
+
*
|
|
544
|
+
* @example
|
|
545
|
+
*
|
|
546
|
+
* ```js
|
|
547
|
+
* const preloadQuery = createQueryPreloader(client);
|
|
548
|
+
* const queryRef = preloadQuery(query, { variables, ...otherOptions });
|
|
549
|
+
*
|
|
550
|
+
* function App() {
|
|
551
|
+
* return (
|
|
552
|
+
* <Suspense fallback={<div>Loading</div>}>
|
|
553
|
+
* <MyQuery />
|
|
554
|
+
* </Suspense>
|
|
555
|
+
* );
|
|
556
|
+
* }
|
|
557
|
+
*
|
|
558
|
+
* function MyQuery() {
|
|
559
|
+
* const { data } = useReadQuery(queryRef);
|
|
560
|
+
*
|
|
561
|
+
* // do something with `data`
|
|
562
|
+
* }
|
|
563
|
+
* ```
|
|
564
|
+
*/
|
|
565
|
+
<TData, TVariables extends OperationVariables, TOptions extends never>(
|
|
566
|
+
query: {} extends TVariables ? DocumentNode | TypedDocumentNode<TData, TVariables> : never,
|
|
567
|
+
): PreloadQueryFunction.ResultForOptions<TData, TVariables, Record<string, never>>;
|
|
568
|
+
/**
|
|
569
|
+
* A function that will begin loading a query when called. It's result can be
|
|
570
|
+
* read by `useReadQuery` which will suspend until the query is loaded.
|
|
571
|
+
* This is useful when you want to start loading a query as early as possible
|
|
572
|
+
* outside of a React component.
|
|
573
|
+
*
|
|
574
|
+
* @example
|
|
575
|
+
*
|
|
576
|
+
* ```js
|
|
577
|
+
* const preloadQuery = createQueryPreloader(client);
|
|
578
|
+
* const queryRef = preloadQuery(query, { variables, ...otherOptions });
|
|
579
|
+
*
|
|
580
|
+
* function App() {
|
|
581
|
+
* return (
|
|
582
|
+
* <Suspense fallback={<div>Loading</div>}>
|
|
583
|
+
* <MyQuery />
|
|
584
|
+
* </Suspense>
|
|
585
|
+
* );
|
|
586
|
+
* }
|
|
587
|
+
*
|
|
588
|
+
* function MyQuery() {
|
|
589
|
+
* const { data } = useReadQuery(queryRef);
|
|
590
|
+
*
|
|
591
|
+
* // do something with `data`
|
|
592
|
+
* }
|
|
593
|
+
* ```
|
|
594
|
+
*/
|
|
595
|
+
<
|
|
596
|
+
TData,
|
|
597
|
+
TVariables extends OperationVariables,
|
|
598
|
+
TOptions extends PreloadQueryOptions<NoInfer<TVariables>> &
|
|
599
|
+
VariablesOption<
|
|
600
|
+
TVariables & {
|
|
601
|
+
[K in Exclude<keyof TOptions['variables'], keyof TVariables>]?: never;
|
|
602
|
+
}
|
|
603
|
+
>,
|
|
604
|
+
>(
|
|
605
|
+
query: DocumentNode | TypedDocumentNode<TData, TVariables>,
|
|
606
|
+
...[options]: {} extends TVariables ? [options?: TOptions] : [options: TOptions]
|
|
607
|
+
): PreloadQueryFunction.ResultForOptions<TData, TVariables, TOptions>;
|
|
608
|
+
}
|
|
609
|
+
type Evaluated = SignatureStyle extends 'classic' ? Classic : Modern;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* A higher order function that returns a `preloadQuery` function which
|
|
614
|
+
* can be used to begin loading a query with the given `client`. This is useful
|
|
615
|
+
* when you want to start loading a query as early as possible outside of a
|
|
616
|
+
* React component.
|
|
617
|
+
*
|
|
618
|
+
* > Refer to the [Suspense - Initiating queries outside React](https://www.apollographql.com/docs/react/data/suspense#initiating-queries-outside-react) section for a more in-depth overview.
|
|
619
|
+
*
|
|
620
|
+
* @param client - The `ApolloClient` instance that will be used to load queries
|
|
621
|
+
* from the returned `preloadQuery` function.
|
|
622
|
+
* @returns The `preloadQuery` function.
|
|
623
|
+
*
|
|
624
|
+
* @example
|
|
625
|
+
*
|
|
626
|
+
* ```js
|
|
627
|
+
* const preloadQuery = createQueryPreloader(client);
|
|
628
|
+
* ```
|
|
629
|
+
*/
|
|
630
|
+
export declare function createQueryPreloader(client: ApolloClient): PreloadQueryFunction;
|