@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,955 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ApolloClient,
|
|
3
|
+
DataState,
|
|
4
|
+
DefaultContext,
|
|
5
|
+
DocumentNode,
|
|
6
|
+
ErrorPolicy,
|
|
7
|
+
OperationVariables,
|
|
8
|
+
RefetchOn,
|
|
9
|
+
RefetchWritePolicy,
|
|
10
|
+
TypedDocumentNode,
|
|
11
|
+
WatchQueryFetchPolicy,
|
|
12
|
+
} from '@apollo/client';
|
|
13
|
+
import type { SubscribeToMoreFunction } from '@apollo/client';
|
|
14
|
+
import type { QueryRef } from '@octanejs/apollo-client/react';
|
|
15
|
+
import type { FetchMoreFunction, RefetchFunction } from '@octanejs/apollo-client/react/internal';
|
|
16
|
+
import type { OptionWithFallback, SignatureStyle } from '@apollo/client/utilities/internal';
|
|
17
|
+
type ResetFunction = () => void;
|
|
18
|
+
export declare namespace useLoadableQuery {
|
|
19
|
+
type LoadQueryFunction<TVariables extends OperationVariables> = (
|
|
20
|
+
...args: {} extends TVariables ? [variables?: TVariables] : [variables: TVariables]
|
|
21
|
+
) => void;
|
|
22
|
+
type Result<
|
|
23
|
+
TData = unknown,
|
|
24
|
+
TVariables extends OperationVariables = OperationVariables,
|
|
25
|
+
TStates extends DataState<TData>['dataState'] = DataState<TData>['dataState'],
|
|
26
|
+
> = [
|
|
27
|
+
loadQuery: LoadQueryFunction<TVariables>,
|
|
28
|
+
queryRef: QueryRef<TData, TVariables, TStates> | null,
|
|
29
|
+
handlers: Handlers<TData, TVariables>,
|
|
30
|
+
];
|
|
31
|
+
interface Handlers<TData = unknown, TVariables extends OperationVariables = OperationVariables> {
|
|
32
|
+
/**
|
|
33
|
+
* A function that helps you fetch the next set of results for a [paginated list field](https://www.apollographql.com/docs/react/pagination/core-api/).
|
|
34
|
+
*
|
|
35
|
+
*
|
|
36
|
+
* @docGroup 3. Helper functions
|
|
37
|
+
*/
|
|
38
|
+
fetchMore: FetchMoreFunction<TData, TVariables>;
|
|
39
|
+
/**
|
|
40
|
+
* A function that enables you to re-execute the query, optionally passing in new `variables`.
|
|
41
|
+
*
|
|
42
|
+
* To guarantee that the refetch performs a network request, its `fetchPolicy` is set to `network-only` (unless the original query's `fetchPolicy` is `no-cache` or `cache-and-network`, which also guarantee a network request).
|
|
43
|
+
*
|
|
44
|
+
* See also [Refetching](https://www.apollographql.com/docs/react/data/queries/#refetching).
|
|
45
|
+
*
|
|
46
|
+
* Returns a `ResultPromise` with an additional `.retain()` method. Calling
|
|
47
|
+
* `.retain()` keeps the network operation running even if the `ObservableQuery`
|
|
48
|
+
* no longer requires the result.
|
|
49
|
+
*
|
|
50
|
+
* @docGroup 3. Helper functions
|
|
51
|
+
*/
|
|
52
|
+
refetch: RefetchFunction<TData, TVariables>;
|
|
53
|
+
/**
|
|
54
|
+
* A function that enables you to execute a [subscription](https://www.apollographql.com/docs/react/data/subscriptions/), usually to subscribe to specific fields that were included in the query.
|
|
55
|
+
*
|
|
56
|
+
* This function returns _another_ function that you can call to terminate the subscription.
|
|
57
|
+
*/
|
|
58
|
+
subscribeToMore: SubscribeToMoreFunction<TData, TVariables>;
|
|
59
|
+
/**
|
|
60
|
+
* A function that resets the `queryRef` back to `null`.
|
|
61
|
+
*/
|
|
62
|
+
reset: ResetFunction;
|
|
63
|
+
}
|
|
64
|
+
type FetchPolicy = Extract<
|
|
65
|
+
WatchQueryFetchPolicy,
|
|
66
|
+
'cache-first' | 'network-only' | 'no-cache' | 'cache-and-network'
|
|
67
|
+
>;
|
|
68
|
+
interface Options {
|
|
69
|
+
/**
|
|
70
|
+
* The instance of `ApolloClient` to use to execute the query.
|
|
71
|
+
*
|
|
72
|
+
* By default, the instance that's passed down via context is used, but you
|
|
73
|
+
* can provide a different instance here.
|
|
74
|
+
*
|
|
75
|
+
* @docGroup 1. Operation options
|
|
76
|
+
*/
|
|
77
|
+
client?: ApolloClient;
|
|
78
|
+
/**
|
|
79
|
+
* 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.
|
|
80
|
+
*
|
|
81
|
+
* @docGroup 2. Networking options
|
|
82
|
+
*/
|
|
83
|
+
context?: DefaultContext;
|
|
84
|
+
/**
|
|
85
|
+
* Specifies how the query handles a response that returns both GraphQL errors and partial results.
|
|
86
|
+
*
|
|
87
|
+
* For details, see [GraphQL error policies](https://www.apollographql.com/docs/react/data/error-handling/#graphql-error-policies).
|
|
88
|
+
*
|
|
89
|
+
* The default value is `none`, meaning that the query result includes error details but not partial results.
|
|
90
|
+
*
|
|
91
|
+
* @docGroup 1. Operation options
|
|
92
|
+
*/
|
|
93
|
+
errorPolicy?: ErrorPolicy;
|
|
94
|
+
/**
|
|
95
|
+
* 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).
|
|
96
|
+
*
|
|
97
|
+
* For details, see [Setting a fetch policy](https://www.apollographql.com/docs/react/data/queries/#setting-a-fetch-policy).
|
|
98
|
+
*
|
|
99
|
+
* The default value is `cache-first`.
|
|
100
|
+
*
|
|
101
|
+
* @docGroup 3. Caching options
|
|
102
|
+
*/
|
|
103
|
+
fetchPolicy?: FetchPolicy;
|
|
104
|
+
/**
|
|
105
|
+
* A unique identifier for the query. Each item in the array must be a stable
|
|
106
|
+
* identifier to prevent infinite fetches.
|
|
107
|
+
*
|
|
108
|
+
* This is useful when using the same query and variables combination in more
|
|
109
|
+
* than one component, otherwise the components may clobber each other. This
|
|
110
|
+
* can also be used to force the query to re-evaluate fresh.
|
|
111
|
+
*
|
|
112
|
+
* @docGroup 1. Operation options
|
|
113
|
+
*/
|
|
114
|
+
queryKey?: string | number | any[];
|
|
115
|
+
/**
|
|
116
|
+
* Specifies whether a `NetworkStatus.refetch` operation should merge
|
|
117
|
+
* incoming field data with existing data, or overwrite the existing data.
|
|
118
|
+
* Overwriting is probably preferable, but merging is currently the default
|
|
119
|
+
* behavior, for backwards compatibility with Apollo Client 3.x.
|
|
120
|
+
*
|
|
121
|
+
* @docGroup 3. Caching options
|
|
122
|
+
*/
|
|
123
|
+
refetchWritePolicy?: RefetchWritePolicy;
|
|
124
|
+
/**
|
|
125
|
+
* If `true`, the query can return partial results from the cache if the cache doesn't contain results for all queried fields.
|
|
126
|
+
*
|
|
127
|
+
* The default value is `false`.
|
|
128
|
+
*
|
|
129
|
+
* @docGroup 3. Caching options
|
|
130
|
+
*/
|
|
131
|
+
returnPartialData?: boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Determines whether events trigger refetches for the query. Provide an
|
|
134
|
+
* object mapping each refetch event to `true` (enable), `false` (disable)
|
|
135
|
+
* or a callback function that returns `true`/`false` to control individual
|
|
136
|
+
* events. Provide `false` to disable all automatic refetch events for this
|
|
137
|
+
* query. Provide `true` to enable all automatic refetch events for this query.
|
|
138
|
+
* Provide a callback function to perform additional logic to determine
|
|
139
|
+
* whether to enable or disable a refetch for a query.
|
|
140
|
+
*
|
|
141
|
+
* `@remarks`
|
|
142
|
+
* `refetchOn` inherits from `defaultOptions.watchQuery.refetchOn`. If
|
|
143
|
+
* `defaultOptions.watchQuery.refetchOn` is not set, all refetch events are
|
|
144
|
+
* enabled by default.
|
|
145
|
+
*
|
|
146
|
+
* This option only has an effect when the client is configured with a
|
|
147
|
+
* `refetchEventManager`.
|
|
148
|
+
* @docGroup 1. Operation options
|
|
149
|
+
*/
|
|
150
|
+
refetchOn?: RefetchOn.Option;
|
|
151
|
+
}
|
|
152
|
+
interface DefaultOptions extends ApolloClient.DefaultOptions.WatchQuery.Calculated {}
|
|
153
|
+
type ResultForOptions<
|
|
154
|
+
TData,
|
|
155
|
+
TVariables extends OperationVariables,
|
|
156
|
+
TOptions extends Record<string, never> | Options,
|
|
157
|
+
> = Result<
|
|
158
|
+
TData,
|
|
159
|
+
TVariables,
|
|
160
|
+
| 'complete'
|
|
161
|
+
| 'streaming'
|
|
162
|
+
| (OptionWithFallback<TOptions, DefaultOptions, 'errorPolicy'> extends 'none' ? never : 'empty')
|
|
163
|
+
| (OptionWithFallback<TOptions, DefaultOptions, 'returnPartialData'> extends false
|
|
164
|
+
? never
|
|
165
|
+
: 'partial')
|
|
166
|
+
>;
|
|
167
|
+
namespace DocumentationTypes {
|
|
168
|
+
interface useLoadableQuery {
|
|
169
|
+
/**
|
|
170
|
+
* A hook for imperatively loading a query, such as responding to a user
|
|
171
|
+
* interaction.
|
|
172
|
+
*
|
|
173
|
+
* > Refer to the [Suspense - Fetching in response to user interaction](https://www.apollographql.com/docs/react/data/suspense#fetching-in-response-to-user-interaction) section for a more in-depth overview of `useLoadableQuery`.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
*
|
|
177
|
+
* ```jsx
|
|
178
|
+
* import { gql, useLoadableQuery } from "@apollo/client";
|
|
179
|
+
*
|
|
180
|
+
* const GET_GREETING = gql`
|
|
181
|
+
* query GetGreeting($language: String!) {
|
|
182
|
+
* greeting(language: $language) {
|
|
183
|
+
* message
|
|
184
|
+
* }
|
|
185
|
+
* }
|
|
186
|
+
* `;
|
|
187
|
+
*
|
|
188
|
+
* function App() {
|
|
189
|
+
* const [loadGreeting, queryRef] = useLoadableQuery(GET_GREETING);
|
|
190
|
+
*
|
|
191
|
+
* return (
|
|
192
|
+
* <>
|
|
193
|
+
* <button onClick={() => loadGreeting({ language: "english" })}>
|
|
194
|
+
* Load greeting
|
|
195
|
+
* </button>
|
|
196
|
+
* <Suspense fallback={<div>Loading...</div>}>
|
|
197
|
+
* {queryRef && <Hello queryRef={queryRef} />}
|
|
198
|
+
* </Suspense>
|
|
199
|
+
* </>
|
|
200
|
+
* );
|
|
201
|
+
* }
|
|
202
|
+
*
|
|
203
|
+
* function Hello({ queryRef }) {
|
|
204
|
+
* const { data } = useReadQuery(queryRef);
|
|
205
|
+
*
|
|
206
|
+
* return <div>{data.greeting.message}</div>;
|
|
207
|
+
* }
|
|
208
|
+
* ```
|
|
209
|
+
*
|
|
210
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
211
|
+
* @param options - Options to control how the query is executed.
|
|
212
|
+
* @returns A tuple in the form of `[loadQuery, queryRef, handlers]`
|
|
213
|
+
*/
|
|
214
|
+
<TData = unknown, TVariables extends OperationVariables = OperationVariables>(
|
|
215
|
+
query: DocumentNode | TypedDocumentNode<TData, TVariables>,
|
|
216
|
+
options: useLoadableQuery.Options,
|
|
217
|
+
): useLoadableQuery.Result<TData, TVariables>;
|
|
218
|
+
}
|
|
219
|
+
interface useLoadableQuery_Deprecated {
|
|
220
|
+
/**
|
|
221
|
+
* @deprecated Avoid manually specifying generics on `useLoadableQuery`.
|
|
222
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
223
|
+
*
|
|
224
|
+
*
|
|
225
|
+
* A hook for imperatively loading a query, such as responding to a user
|
|
226
|
+
* interaction.
|
|
227
|
+
*
|
|
228
|
+
* > Refer to the [Suspense - Fetching in response to user interaction](https://www.apollographql.com/docs/react/data/suspense#fetching-in-response-to-user-interaction) section for a more in-depth overview of `useLoadableQuery`.
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
*
|
|
232
|
+
* ```jsx
|
|
233
|
+
* import { gql, useLoadableQuery } from "@apollo/client";
|
|
234
|
+
*
|
|
235
|
+
* const GET_GREETING = gql`
|
|
236
|
+
* query GetGreeting($language: String!) {
|
|
237
|
+
* greeting(language: $language) {
|
|
238
|
+
* message
|
|
239
|
+
* }
|
|
240
|
+
* }
|
|
241
|
+
* `;
|
|
242
|
+
*
|
|
243
|
+
* function App() {
|
|
244
|
+
* const [loadGreeting, queryRef] = useLoadableQuery(GET_GREETING);
|
|
245
|
+
*
|
|
246
|
+
* return (
|
|
247
|
+
* <>
|
|
248
|
+
* <button onClick={() => loadGreeting({ language: "english" })}>
|
|
249
|
+
* Load greeting
|
|
250
|
+
* </button>
|
|
251
|
+
* <Suspense fallback={<div>Loading...</div>}>
|
|
252
|
+
* {queryRef && <Hello queryRef={queryRef} />}
|
|
253
|
+
* </Suspense>
|
|
254
|
+
* </>
|
|
255
|
+
* );
|
|
256
|
+
* }
|
|
257
|
+
*
|
|
258
|
+
* function Hello({ queryRef }) {
|
|
259
|
+
* const { data } = useReadQuery(queryRef);
|
|
260
|
+
*
|
|
261
|
+
* return <div>{data.greeting.message}</div>;
|
|
262
|
+
* }
|
|
263
|
+
* ```
|
|
264
|
+
*
|
|
265
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
266
|
+
* @param options - Options to control how the query is executed.
|
|
267
|
+
* @returns A tuple in the form of `[loadQuery, queryRef, handlers]`
|
|
268
|
+
*/
|
|
269
|
+
<TData = unknown, TVariables extends OperationVariables = OperationVariables>(
|
|
270
|
+
query: DocumentNode | TypedDocumentNode<TData, TVariables>,
|
|
271
|
+
options: useLoadableQuery.Options,
|
|
272
|
+
): useLoadableQuery.Result<TData, TVariables>;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
namespace Signatures {
|
|
276
|
+
/**
|
|
277
|
+
* A hook for imperatively loading a query, such as responding to a user
|
|
278
|
+
* interaction.
|
|
279
|
+
*
|
|
280
|
+
* > Refer to the [Suspense - Fetching in response to user interaction](https://www.apollographql.com/docs/react/data/suspense#fetching-in-response-to-user-interaction) section for a more in-depth overview of `useLoadableQuery`.
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
*
|
|
284
|
+
* ```jsx
|
|
285
|
+
* import { gql, useLoadableQuery } from "@apollo/client";
|
|
286
|
+
*
|
|
287
|
+
* const GET_GREETING = gql`
|
|
288
|
+
* query GetGreeting($language: String!) {
|
|
289
|
+
* greeting(language: $language) {
|
|
290
|
+
* message
|
|
291
|
+
* }
|
|
292
|
+
* }
|
|
293
|
+
* `;
|
|
294
|
+
*
|
|
295
|
+
* function App() {
|
|
296
|
+
* const [loadGreeting, queryRef] = useLoadableQuery(GET_GREETING);
|
|
297
|
+
*
|
|
298
|
+
* return (
|
|
299
|
+
* <>
|
|
300
|
+
* <button onClick={() => loadGreeting({ language: "english" })}>
|
|
301
|
+
* Load greeting
|
|
302
|
+
* </button>
|
|
303
|
+
* <Suspense fallback={<div>Loading...</div>}>
|
|
304
|
+
* {queryRef && <Hello queryRef={queryRef} />}
|
|
305
|
+
* </Suspense>
|
|
306
|
+
* </>
|
|
307
|
+
* );
|
|
308
|
+
* }
|
|
309
|
+
*
|
|
310
|
+
* function Hello({ queryRef }) {
|
|
311
|
+
* const { data } = useReadQuery(queryRef);
|
|
312
|
+
*
|
|
313
|
+
* return <div>{data.greeting.message}</div>;
|
|
314
|
+
* }
|
|
315
|
+
* ```
|
|
316
|
+
*
|
|
317
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
318
|
+
* @param options - Options to control how the query is executed.
|
|
319
|
+
* @returns A tuple in the form of `[loadQuery, queryRef, handlers]`
|
|
320
|
+
*/
|
|
321
|
+
interface Classic {
|
|
322
|
+
/**
|
|
323
|
+
* A hook for imperatively loading a query, such as responding to a user
|
|
324
|
+
* interaction.
|
|
325
|
+
*
|
|
326
|
+
* > Refer to the [Suspense - Fetching in response to user interaction](https://www.apollographql.com/docs/react/data/suspense#fetching-in-response-to-user-interaction) section for a more in-depth overview of `useLoadableQuery`.
|
|
327
|
+
*
|
|
328
|
+
* @example
|
|
329
|
+
*
|
|
330
|
+
* ```jsx
|
|
331
|
+
* import { gql, useLoadableQuery } from "@apollo/client";
|
|
332
|
+
*
|
|
333
|
+
* const GET_GREETING = gql`
|
|
334
|
+
* query GetGreeting($language: String!) {
|
|
335
|
+
* greeting(language: $language) {
|
|
336
|
+
* message
|
|
337
|
+
* }
|
|
338
|
+
* }
|
|
339
|
+
* `;
|
|
340
|
+
*
|
|
341
|
+
* function App() {
|
|
342
|
+
* const [loadGreeting, queryRef] = useLoadableQuery(GET_GREETING);
|
|
343
|
+
*
|
|
344
|
+
* return (
|
|
345
|
+
* <>
|
|
346
|
+
* <button onClick={() => loadGreeting({ language: "english" })}>
|
|
347
|
+
* Load greeting
|
|
348
|
+
* </button>
|
|
349
|
+
* <Suspense fallback={<div>Loading...</div>}>
|
|
350
|
+
* {queryRef && <Hello queryRef={queryRef} />}
|
|
351
|
+
* </Suspense>
|
|
352
|
+
* </>
|
|
353
|
+
* );
|
|
354
|
+
* }
|
|
355
|
+
*
|
|
356
|
+
* function Hello({ queryRef }) {
|
|
357
|
+
* const { data } = useReadQuery(queryRef);
|
|
358
|
+
*
|
|
359
|
+
* return <div>{data.greeting.message}</div>;
|
|
360
|
+
* }
|
|
361
|
+
* ```
|
|
362
|
+
*
|
|
363
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
364
|
+
* @param options - Options to control how the query is executed.
|
|
365
|
+
* @returns A tuple in the form of `[loadQuery, queryRef, handlers]`
|
|
366
|
+
*/
|
|
367
|
+
<
|
|
368
|
+
TData,
|
|
369
|
+
TVariables extends OperationVariables,
|
|
370
|
+
_INFERENCE_ONLY_DO_NOT_SPECIFY extends 'inferred',
|
|
371
|
+
>(
|
|
372
|
+
query: DocumentNode | TypedDocumentNode<TData, TVariables>,
|
|
373
|
+
options: useLoadableQuery.Options & {
|
|
374
|
+
returnPartialData: true;
|
|
375
|
+
errorPolicy: 'ignore' | 'all';
|
|
376
|
+
},
|
|
377
|
+
): useLoadableQuery.Result<TData, TVariables, 'complete' | 'streaming' | 'partial' | 'empty'>;
|
|
378
|
+
/**
|
|
379
|
+
* A hook for imperatively loading a query, such as responding to a user
|
|
380
|
+
* interaction.
|
|
381
|
+
*
|
|
382
|
+
* > Refer to the [Suspense - Fetching in response to user interaction](https://www.apollographql.com/docs/react/data/suspense#fetching-in-response-to-user-interaction) section for a more in-depth overview of `useLoadableQuery`.
|
|
383
|
+
*
|
|
384
|
+
* @example
|
|
385
|
+
*
|
|
386
|
+
* ```jsx
|
|
387
|
+
* import { gql, useLoadableQuery } from "@apollo/client";
|
|
388
|
+
*
|
|
389
|
+
* const GET_GREETING = gql`
|
|
390
|
+
* query GetGreeting($language: String!) {
|
|
391
|
+
* greeting(language: $language) {
|
|
392
|
+
* message
|
|
393
|
+
* }
|
|
394
|
+
* }
|
|
395
|
+
* `;
|
|
396
|
+
*
|
|
397
|
+
* function App() {
|
|
398
|
+
* const [loadGreeting, queryRef] = useLoadableQuery(GET_GREETING);
|
|
399
|
+
*
|
|
400
|
+
* return (
|
|
401
|
+
* <>
|
|
402
|
+
* <button onClick={() => loadGreeting({ language: "english" })}>
|
|
403
|
+
* Load greeting
|
|
404
|
+
* </button>
|
|
405
|
+
* <Suspense fallback={<div>Loading...</div>}>
|
|
406
|
+
* {queryRef && <Hello queryRef={queryRef} />}
|
|
407
|
+
* </Suspense>
|
|
408
|
+
* </>
|
|
409
|
+
* );
|
|
410
|
+
* }
|
|
411
|
+
*
|
|
412
|
+
* function Hello({ queryRef }) {
|
|
413
|
+
* const { data } = useReadQuery(queryRef);
|
|
414
|
+
*
|
|
415
|
+
* return <div>{data.greeting.message}</div>;
|
|
416
|
+
* }
|
|
417
|
+
* ```
|
|
418
|
+
*
|
|
419
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
420
|
+
* @param options - Options to control how the query is executed.
|
|
421
|
+
* @returns A tuple in the form of `[loadQuery, queryRef, handlers]`
|
|
422
|
+
*/
|
|
423
|
+
<
|
|
424
|
+
TData,
|
|
425
|
+
TVariables extends OperationVariables,
|
|
426
|
+
_INFERENCE_ONLY_DO_NOT_SPECIFY extends 'inferred',
|
|
427
|
+
>(
|
|
428
|
+
query: DocumentNode | TypedDocumentNode<TData, TVariables>,
|
|
429
|
+
options: useLoadableQuery.Options & {
|
|
430
|
+
errorPolicy: 'ignore' | 'all';
|
|
431
|
+
},
|
|
432
|
+
): useLoadableQuery.Result<TData, TVariables, 'complete' | 'streaming' | 'empty'>;
|
|
433
|
+
/**
|
|
434
|
+
* A hook for imperatively loading a query, such as responding to a user
|
|
435
|
+
* interaction.
|
|
436
|
+
*
|
|
437
|
+
* > Refer to the [Suspense - Fetching in response to user interaction](https://www.apollographql.com/docs/react/data/suspense#fetching-in-response-to-user-interaction) section for a more in-depth overview of `useLoadableQuery`.
|
|
438
|
+
*
|
|
439
|
+
* @example
|
|
440
|
+
*
|
|
441
|
+
* ```jsx
|
|
442
|
+
* import { gql, useLoadableQuery } from "@apollo/client";
|
|
443
|
+
*
|
|
444
|
+
* const GET_GREETING = gql`
|
|
445
|
+
* query GetGreeting($language: String!) {
|
|
446
|
+
* greeting(language: $language) {
|
|
447
|
+
* message
|
|
448
|
+
* }
|
|
449
|
+
* }
|
|
450
|
+
* `;
|
|
451
|
+
*
|
|
452
|
+
* function App() {
|
|
453
|
+
* const [loadGreeting, queryRef] = useLoadableQuery(GET_GREETING);
|
|
454
|
+
*
|
|
455
|
+
* return (
|
|
456
|
+
* <>
|
|
457
|
+
* <button onClick={() => loadGreeting({ language: "english" })}>
|
|
458
|
+
* Load greeting
|
|
459
|
+
* </button>
|
|
460
|
+
* <Suspense fallback={<div>Loading...</div>}>
|
|
461
|
+
* {queryRef && <Hello queryRef={queryRef} />}
|
|
462
|
+
* </Suspense>
|
|
463
|
+
* </>
|
|
464
|
+
* );
|
|
465
|
+
* }
|
|
466
|
+
*
|
|
467
|
+
* function Hello({ queryRef }) {
|
|
468
|
+
* const { data } = useReadQuery(queryRef);
|
|
469
|
+
*
|
|
470
|
+
* return <div>{data.greeting.message}</div>;
|
|
471
|
+
* }
|
|
472
|
+
* ```
|
|
473
|
+
*
|
|
474
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
475
|
+
* @param options - Options to control how the query is executed.
|
|
476
|
+
* @returns A tuple in the form of `[loadQuery, queryRef, handlers]`
|
|
477
|
+
*/
|
|
478
|
+
<
|
|
479
|
+
TData,
|
|
480
|
+
TVariables extends OperationVariables,
|
|
481
|
+
_INFERENCE_ONLY_DO_NOT_SPECIFY extends 'inferred',
|
|
482
|
+
>(
|
|
483
|
+
query: DocumentNode | TypedDocumentNode<TData, TVariables>,
|
|
484
|
+
options: useLoadableQuery.Options & {
|
|
485
|
+
returnPartialData: true;
|
|
486
|
+
},
|
|
487
|
+
): useLoadableQuery.Result<TData, TVariables, 'complete' | 'streaming' | 'partial'>;
|
|
488
|
+
/**
|
|
489
|
+
* A hook for imperatively loading a query, such as responding to a user
|
|
490
|
+
* interaction.
|
|
491
|
+
*
|
|
492
|
+
* > Refer to the [Suspense - Fetching in response to user interaction](https://www.apollographql.com/docs/react/data/suspense#fetching-in-response-to-user-interaction) section for a more in-depth overview of `useLoadableQuery`.
|
|
493
|
+
*
|
|
494
|
+
* @example
|
|
495
|
+
*
|
|
496
|
+
* ```jsx
|
|
497
|
+
* import { gql, useLoadableQuery } from "@apollo/client";
|
|
498
|
+
*
|
|
499
|
+
* const GET_GREETING = gql`
|
|
500
|
+
* query GetGreeting($language: String!) {
|
|
501
|
+
* greeting(language: $language) {
|
|
502
|
+
* message
|
|
503
|
+
* }
|
|
504
|
+
* }
|
|
505
|
+
* `;
|
|
506
|
+
*
|
|
507
|
+
* function App() {
|
|
508
|
+
* const [loadGreeting, queryRef] = useLoadableQuery(GET_GREETING);
|
|
509
|
+
*
|
|
510
|
+
* return (
|
|
511
|
+
* <>
|
|
512
|
+
* <button onClick={() => loadGreeting({ language: "english" })}>
|
|
513
|
+
* Load greeting
|
|
514
|
+
* </button>
|
|
515
|
+
* <Suspense fallback={<div>Loading...</div>}>
|
|
516
|
+
* {queryRef && <Hello queryRef={queryRef} />}
|
|
517
|
+
* </Suspense>
|
|
518
|
+
* </>
|
|
519
|
+
* );
|
|
520
|
+
* }
|
|
521
|
+
*
|
|
522
|
+
* function Hello({ queryRef }) {
|
|
523
|
+
* const { data } = useReadQuery(queryRef);
|
|
524
|
+
*
|
|
525
|
+
* return <div>{data.greeting.message}</div>;
|
|
526
|
+
* }
|
|
527
|
+
* ```
|
|
528
|
+
*
|
|
529
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
530
|
+
* @param options - Options to control how the query is executed.
|
|
531
|
+
* @returns A tuple in the form of `[loadQuery, queryRef, handlers]`
|
|
532
|
+
*/
|
|
533
|
+
<
|
|
534
|
+
TData,
|
|
535
|
+
TVariables extends OperationVariables,
|
|
536
|
+
_INFERENCE_ONLY_DO_NOT_SPECIFY extends 'inferred',
|
|
537
|
+
>(
|
|
538
|
+
query: DocumentNode | TypedDocumentNode<TData, TVariables>,
|
|
539
|
+
options?: useLoadableQuery.Options,
|
|
540
|
+
): useLoadableQuery.Result<TData, TVariables, 'complete' | 'streaming'>;
|
|
541
|
+
/**
|
|
542
|
+
* @deprecated Avoid manually specifying generics on `useLoadableQuery`.
|
|
543
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
544
|
+
*
|
|
545
|
+
*
|
|
546
|
+
* A hook for imperatively loading a query, such as responding to a user
|
|
547
|
+
* interaction.
|
|
548
|
+
*
|
|
549
|
+
* > Refer to the [Suspense - Fetching in response to user interaction](https://www.apollographql.com/docs/react/data/suspense#fetching-in-response-to-user-interaction) section for a more in-depth overview of `useLoadableQuery`.
|
|
550
|
+
*
|
|
551
|
+
* @example
|
|
552
|
+
*
|
|
553
|
+
* ```jsx
|
|
554
|
+
* import { gql, useLoadableQuery } from "@apollo/client";
|
|
555
|
+
*
|
|
556
|
+
* const GET_GREETING = gql`
|
|
557
|
+
* query GetGreeting($language: String!) {
|
|
558
|
+
* greeting(language: $language) {
|
|
559
|
+
* message
|
|
560
|
+
* }
|
|
561
|
+
* }
|
|
562
|
+
* `;
|
|
563
|
+
*
|
|
564
|
+
* function App() {
|
|
565
|
+
* const [loadGreeting, queryRef] = useLoadableQuery(GET_GREETING);
|
|
566
|
+
*
|
|
567
|
+
* return (
|
|
568
|
+
* <>
|
|
569
|
+
* <button onClick={() => loadGreeting({ language: "english" })}>
|
|
570
|
+
* Load greeting
|
|
571
|
+
* </button>
|
|
572
|
+
* <Suspense fallback={<div>Loading...</div>}>
|
|
573
|
+
* {queryRef && <Hello queryRef={queryRef} />}
|
|
574
|
+
* </Suspense>
|
|
575
|
+
* </>
|
|
576
|
+
* );
|
|
577
|
+
* }
|
|
578
|
+
*
|
|
579
|
+
* function Hello({ queryRef }) {
|
|
580
|
+
* const { data } = useReadQuery(queryRef);
|
|
581
|
+
*
|
|
582
|
+
* return <div>{data.greeting.message}</div>;
|
|
583
|
+
* }
|
|
584
|
+
* ```
|
|
585
|
+
*
|
|
586
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
587
|
+
* @param options - Options to control how the query is executed.
|
|
588
|
+
* @returns A tuple in the form of `[loadQuery, queryRef, handlers]`
|
|
589
|
+
*/
|
|
590
|
+
<TData, TVariables extends OperationVariables = OperationVariables>(
|
|
591
|
+
query: DocumentNode | TypedDocumentNode<TData, TVariables>,
|
|
592
|
+
options: useLoadableQuery.Options & {
|
|
593
|
+
returnPartialData: true;
|
|
594
|
+
errorPolicy: 'ignore' | 'all';
|
|
595
|
+
},
|
|
596
|
+
): useLoadableQuery.Result<TData, TVariables, 'complete' | 'streaming' | 'partial' | 'empty'>;
|
|
597
|
+
/**
|
|
598
|
+
* @deprecated Avoid manually specifying generics on `useLoadableQuery`.
|
|
599
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
600
|
+
*
|
|
601
|
+
*
|
|
602
|
+
* A hook for imperatively loading a query, such as responding to a user
|
|
603
|
+
* interaction.
|
|
604
|
+
*
|
|
605
|
+
* > Refer to the [Suspense - Fetching in response to user interaction](https://www.apollographql.com/docs/react/data/suspense#fetching-in-response-to-user-interaction) section for a more in-depth overview of `useLoadableQuery`.
|
|
606
|
+
*
|
|
607
|
+
* @example
|
|
608
|
+
*
|
|
609
|
+
* ```jsx
|
|
610
|
+
* import { gql, useLoadableQuery } from "@apollo/client";
|
|
611
|
+
*
|
|
612
|
+
* const GET_GREETING = gql`
|
|
613
|
+
* query GetGreeting($language: String!) {
|
|
614
|
+
* greeting(language: $language) {
|
|
615
|
+
* message
|
|
616
|
+
* }
|
|
617
|
+
* }
|
|
618
|
+
* `;
|
|
619
|
+
*
|
|
620
|
+
* function App() {
|
|
621
|
+
* const [loadGreeting, queryRef] = useLoadableQuery(GET_GREETING);
|
|
622
|
+
*
|
|
623
|
+
* return (
|
|
624
|
+
* <>
|
|
625
|
+
* <button onClick={() => loadGreeting({ language: "english" })}>
|
|
626
|
+
* Load greeting
|
|
627
|
+
* </button>
|
|
628
|
+
* <Suspense fallback={<div>Loading...</div>}>
|
|
629
|
+
* {queryRef && <Hello queryRef={queryRef} />}
|
|
630
|
+
* </Suspense>
|
|
631
|
+
* </>
|
|
632
|
+
* );
|
|
633
|
+
* }
|
|
634
|
+
*
|
|
635
|
+
* function Hello({ queryRef }) {
|
|
636
|
+
* const { data } = useReadQuery(queryRef);
|
|
637
|
+
*
|
|
638
|
+
* return <div>{data.greeting.message}</div>;
|
|
639
|
+
* }
|
|
640
|
+
* ```
|
|
641
|
+
*
|
|
642
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
643
|
+
* @param options - Options to control how the query is executed.
|
|
644
|
+
* @returns A tuple in the form of `[loadQuery, queryRef, handlers]`
|
|
645
|
+
*/
|
|
646
|
+
<TData, TVariables extends OperationVariables = OperationVariables>(
|
|
647
|
+
query: DocumentNode | TypedDocumentNode<TData, TVariables>,
|
|
648
|
+
options: useLoadableQuery.Options & {
|
|
649
|
+
errorPolicy: 'ignore' | 'all';
|
|
650
|
+
},
|
|
651
|
+
): useLoadableQuery.Result<TData, TVariables, 'complete' | 'streaming' | 'empty'>;
|
|
652
|
+
/**
|
|
653
|
+
* @deprecated Avoid manually specifying generics on `useLoadableQuery`.
|
|
654
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
655
|
+
*
|
|
656
|
+
*
|
|
657
|
+
* A hook for imperatively loading a query, such as responding to a user
|
|
658
|
+
* interaction.
|
|
659
|
+
*
|
|
660
|
+
* > Refer to the [Suspense - Fetching in response to user interaction](https://www.apollographql.com/docs/react/data/suspense#fetching-in-response-to-user-interaction) section for a more in-depth overview of `useLoadableQuery`.
|
|
661
|
+
*
|
|
662
|
+
* @example
|
|
663
|
+
*
|
|
664
|
+
* ```jsx
|
|
665
|
+
* import { gql, useLoadableQuery } from "@apollo/client";
|
|
666
|
+
*
|
|
667
|
+
* const GET_GREETING = gql`
|
|
668
|
+
* query GetGreeting($language: String!) {
|
|
669
|
+
* greeting(language: $language) {
|
|
670
|
+
* message
|
|
671
|
+
* }
|
|
672
|
+
* }
|
|
673
|
+
* `;
|
|
674
|
+
*
|
|
675
|
+
* function App() {
|
|
676
|
+
* const [loadGreeting, queryRef] = useLoadableQuery(GET_GREETING);
|
|
677
|
+
*
|
|
678
|
+
* return (
|
|
679
|
+
* <>
|
|
680
|
+
* <button onClick={() => loadGreeting({ language: "english" })}>
|
|
681
|
+
* Load greeting
|
|
682
|
+
* </button>
|
|
683
|
+
* <Suspense fallback={<div>Loading...</div>}>
|
|
684
|
+
* {queryRef && <Hello queryRef={queryRef} />}
|
|
685
|
+
* </Suspense>
|
|
686
|
+
* </>
|
|
687
|
+
* );
|
|
688
|
+
* }
|
|
689
|
+
*
|
|
690
|
+
* function Hello({ queryRef }) {
|
|
691
|
+
* const { data } = useReadQuery(queryRef);
|
|
692
|
+
*
|
|
693
|
+
* return <div>{data.greeting.message}</div>;
|
|
694
|
+
* }
|
|
695
|
+
* ```
|
|
696
|
+
*
|
|
697
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
698
|
+
* @param options - Options to control how the query is executed.
|
|
699
|
+
* @returns A tuple in the form of `[loadQuery, queryRef, handlers]`
|
|
700
|
+
*/
|
|
701
|
+
<TData, TVariables extends OperationVariables = OperationVariables>(
|
|
702
|
+
query: DocumentNode | TypedDocumentNode<TData, TVariables>,
|
|
703
|
+
options: useLoadableQuery.Options & {
|
|
704
|
+
returnPartialData: true;
|
|
705
|
+
},
|
|
706
|
+
): useLoadableQuery.Result<TData, TVariables, 'complete' | 'streaming' | 'partial'>;
|
|
707
|
+
/**
|
|
708
|
+
* @deprecated Avoid manually specifying generics on `useLoadableQuery`.
|
|
709
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
710
|
+
*
|
|
711
|
+
*
|
|
712
|
+
* A hook for imperatively loading a query, such as responding to a user
|
|
713
|
+
* interaction.
|
|
714
|
+
*
|
|
715
|
+
* > Refer to the [Suspense - Fetching in response to user interaction](https://www.apollographql.com/docs/react/data/suspense#fetching-in-response-to-user-interaction) section for a more in-depth overview of `useLoadableQuery`.
|
|
716
|
+
*
|
|
717
|
+
* @example
|
|
718
|
+
*
|
|
719
|
+
* ```jsx
|
|
720
|
+
* import { gql, useLoadableQuery } from "@apollo/client";
|
|
721
|
+
*
|
|
722
|
+
* const GET_GREETING = gql`
|
|
723
|
+
* query GetGreeting($language: String!) {
|
|
724
|
+
* greeting(language: $language) {
|
|
725
|
+
* message
|
|
726
|
+
* }
|
|
727
|
+
* }
|
|
728
|
+
* `;
|
|
729
|
+
*
|
|
730
|
+
* function App() {
|
|
731
|
+
* const [loadGreeting, queryRef] = useLoadableQuery(GET_GREETING);
|
|
732
|
+
*
|
|
733
|
+
* return (
|
|
734
|
+
* <>
|
|
735
|
+
* <button onClick={() => loadGreeting({ language: "english" })}>
|
|
736
|
+
* Load greeting
|
|
737
|
+
* </button>
|
|
738
|
+
* <Suspense fallback={<div>Loading...</div>}>
|
|
739
|
+
* {queryRef && <Hello queryRef={queryRef} />}
|
|
740
|
+
* </Suspense>
|
|
741
|
+
* </>
|
|
742
|
+
* );
|
|
743
|
+
* }
|
|
744
|
+
*
|
|
745
|
+
* function Hello({ queryRef }) {
|
|
746
|
+
* const { data } = useReadQuery(queryRef);
|
|
747
|
+
*
|
|
748
|
+
* return <div>{data.greeting.message}</div>;
|
|
749
|
+
* }
|
|
750
|
+
* ```
|
|
751
|
+
*
|
|
752
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
753
|
+
* @param options - Options to control how the query is executed.
|
|
754
|
+
* @returns A tuple in the form of `[loadQuery, queryRef, handlers]`
|
|
755
|
+
*/
|
|
756
|
+
<TData, TVariables extends OperationVariables = OperationVariables>(
|
|
757
|
+
query: DocumentNode | TypedDocumentNode<TData, TVariables>,
|
|
758
|
+
options?: useLoadableQuery.Options,
|
|
759
|
+
): useLoadableQuery.Result<TData, TVariables, 'complete' | 'streaming'>;
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* A hook for imperatively loading a query, such as responding to a user
|
|
763
|
+
* interaction.
|
|
764
|
+
*
|
|
765
|
+
* > Refer to the [Suspense - Fetching in response to user interaction](https://www.apollographql.com/docs/react/data/suspense#fetching-in-response-to-user-interaction) section for a more in-depth overview of `useLoadableQuery`.
|
|
766
|
+
*
|
|
767
|
+
* @example
|
|
768
|
+
*
|
|
769
|
+
* ```jsx
|
|
770
|
+
* import { gql, useLoadableQuery } from "@apollo/client";
|
|
771
|
+
*
|
|
772
|
+
* const GET_GREETING = gql`
|
|
773
|
+
* query GetGreeting($language: String!) {
|
|
774
|
+
* greeting(language: $language) {
|
|
775
|
+
* message
|
|
776
|
+
* }
|
|
777
|
+
* }
|
|
778
|
+
* `;
|
|
779
|
+
*
|
|
780
|
+
* function App() {
|
|
781
|
+
* const [loadGreeting, queryRef] = useLoadableQuery(GET_GREETING);
|
|
782
|
+
*
|
|
783
|
+
* return (
|
|
784
|
+
* <>
|
|
785
|
+
* <button onClick={() => loadGreeting({ language: "english" })}>
|
|
786
|
+
* Load greeting
|
|
787
|
+
* </button>
|
|
788
|
+
* <Suspense fallback={<div>Loading...</div>}>
|
|
789
|
+
* {queryRef && <Hello queryRef={queryRef} />}
|
|
790
|
+
* </Suspense>
|
|
791
|
+
* </>
|
|
792
|
+
* );
|
|
793
|
+
* }
|
|
794
|
+
*
|
|
795
|
+
* function Hello({ queryRef }) {
|
|
796
|
+
* const { data } = useReadQuery(queryRef);
|
|
797
|
+
*
|
|
798
|
+
* return <div>{data.greeting.message}</div>;
|
|
799
|
+
* }
|
|
800
|
+
* ```
|
|
801
|
+
*
|
|
802
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
803
|
+
* @param options - Options to control how the query is executed.
|
|
804
|
+
* @returns A tuple in the form of `[loadQuery, queryRef, handlers]`
|
|
805
|
+
*/
|
|
806
|
+
interface Modern {
|
|
807
|
+
/**
|
|
808
|
+
* A hook for imperatively loading a query, such as responding to a user
|
|
809
|
+
* interaction.
|
|
810
|
+
*
|
|
811
|
+
* > Refer to the [Suspense - Fetching in response to user interaction](https://www.apollographql.com/docs/react/data/suspense#fetching-in-response-to-user-interaction) section for a more in-depth overview of `useLoadableQuery`.
|
|
812
|
+
*
|
|
813
|
+
* @example
|
|
814
|
+
*
|
|
815
|
+
* ```jsx
|
|
816
|
+
* import { gql, useLoadableQuery } from "@apollo/client";
|
|
817
|
+
*
|
|
818
|
+
* const GET_GREETING = gql`
|
|
819
|
+
* query GetGreeting($language: String!) {
|
|
820
|
+
* greeting(language: $language) {
|
|
821
|
+
* message
|
|
822
|
+
* }
|
|
823
|
+
* }
|
|
824
|
+
* `;
|
|
825
|
+
*
|
|
826
|
+
* function App() {
|
|
827
|
+
* const [loadGreeting, queryRef] = useLoadableQuery(GET_GREETING);
|
|
828
|
+
*
|
|
829
|
+
* return (
|
|
830
|
+
* <>
|
|
831
|
+
* <button onClick={() => loadGreeting({ language: "english" })}>
|
|
832
|
+
* Load greeting
|
|
833
|
+
* </button>
|
|
834
|
+
* <Suspense fallback={<div>Loading...</div>}>
|
|
835
|
+
* {queryRef && <Hello queryRef={queryRef} />}
|
|
836
|
+
* </Suspense>
|
|
837
|
+
* </>
|
|
838
|
+
* );
|
|
839
|
+
* }
|
|
840
|
+
*
|
|
841
|
+
* function Hello({ queryRef }) {
|
|
842
|
+
* const { data } = useReadQuery(queryRef);
|
|
843
|
+
*
|
|
844
|
+
* return <div>{data.greeting.message}</div>;
|
|
845
|
+
* }
|
|
846
|
+
* ```
|
|
847
|
+
*
|
|
848
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
849
|
+
* @param options - Options to control how the query is executed.
|
|
850
|
+
* @returns A tuple in the form of `[loadQuery, queryRef, handlers]`
|
|
851
|
+
*/
|
|
852
|
+
<TData, TVariables extends OperationVariables, TOptions extends never>(
|
|
853
|
+
query: DocumentNode | TypedDocumentNode<TData, TVariables>,
|
|
854
|
+
): useLoadableQuery.ResultForOptions<TData, TVariables, Record<string, never>>;
|
|
855
|
+
/**
|
|
856
|
+
* A hook for imperatively loading a query, such as responding to a user
|
|
857
|
+
* interaction.
|
|
858
|
+
*
|
|
859
|
+
* > Refer to the [Suspense - Fetching in response to user interaction](https://www.apollographql.com/docs/react/data/suspense#fetching-in-response-to-user-interaction) section for a more in-depth overview of `useLoadableQuery`.
|
|
860
|
+
*
|
|
861
|
+
* @example
|
|
862
|
+
*
|
|
863
|
+
* ```jsx
|
|
864
|
+
* import { gql, useLoadableQuery } from "@apollo/client";
|
|
865
|
+
*
|
|
866
|
+
* const GET_GREETING = gql`
|
|
867
|
+
* query GetGreeting($language: String!) {
|
|
868
|
+
* greeting(language: $language) {
|
|
869
|
+
* message
|
|
870
|
+
* }
|
|
871
|
+
* }
|
|
872
|
+
* `;
|
|
873
|
+
*
|
|
874
|
+
* function App() {
|
|
875
|
+
* const [loadGreeting, queryRef] = useLoadableQuery(GET_GREETING);
|
|
876
|
+
*
|
|
877
|
+
* return (
|
|
878
|
+
* <>
|
|
879
|
+
* <button onClick={() => loadGreeting({ language: "english" })}>
|
|
880
|
+
* Load greeting
|
|
881
|
+
* </button>
|
|
882
|
+
* <Suspense fallback={<div>Loading...</div>}>
|
|
883
|
+
* {queryRef && <Hello queryRef={queryRef} />}
|
|
884
|
+
* </Suspense>
|
|
885
|
+
* </>
|
|
886
|
+
* );
|
|
887
|
+
* }
|
|
888
|
+
*
|
|
889
|
+
* function Hello({ queryRef }) {
|
|
890
|
+
* const { data } = useReadQuery(queryRef);
|
|
891
|
+
*
|
|
892
|
+
* return <div>{data.greeting.message}</div>;
|
|
893
|
+
* }
|
|
894
|
+
* ```
|
|
895
|
+
*
|
|
896
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
897
|
+
* @param options - Options to control how the query is executed.
|
|
898
|
+
* @returns A tuple in the form of `[loadQuery, queryRef, handlers]`
|
|
899
|
+
*/
|
|
900
|
+
<TData, TVariables extends OperationVariables, TOptions extends useLoadableQuery.Options>(
|
|
901
|
+
query: DocumentNode | TypedDocumentNode<TData, TVariables>,
|
|
902
|
+
options: TOptions,
|
|
903
|
+
): useLoadableQuery.ResultForOptions<TData, TVariables, TOptions>;
|
|
904
|
+
}
|
|
905
|
+
type Evaluated = SignatureStyle extends 'classic' ? Classic : Modern;
|
|
906
|
+
}
|
|
907
|
+
/**
|
|
908
|
+
* A hook for imperatively loading a query, such as responding to a user
|
|
909
|
+
* interaction.
|
|
910
|
+
*
|
|
911
|
+
* > Refer to the [Suspense - Fetching in response to user interaction](https://www.apollographql.com/docs/react/data/suspense#fetching-in-response-to-user-interaction) section for a more in-depth overview of `useLoadableQuery`.
|
|
912
|
+
*
|
|
913
|
+
* @example
|
|
914
|
+
*
|
|
915
|
+
* ```jsx
|
|
916
|
+
* import { gql, useLoadableQuery } from "@apollo/client";
|
|
917
|
+
*
|
|
918
|
+
* const GET_GREETING = gql`
|
|
919
|
+
* query GetGreeting($language: String!) {
|
|
920
|
+
* greeting(language: $language) {
|
|
921
|
+
* message
|
|
922
|
+
* }
|
|
923
|
+
* }
|
|
924
|
+
* `;
|
|
925
|
+
*
|
|
926
|
+
* function App() {
|
|
927
|
+
* const [loadGreeting, queryRef] = useLoadableQuery(GET_GREETING);
|
|
928
|
+
*
|
|
929
|
+
* return (
|
|
930
|
+
* <>
|
|
931
|
+
* <button onClick={() => loadGreeting({ language: "english" })}>
|
|
932
|
+
* Load greeting
|
|
933
|
+
* </button>
|
|
934
|
+
* <Suspense fallback={<div>Loading...</div>}>
|
|
935
|
+
* {queryRef && <Hello queryRef={queryRef} />}
|
|
936
|
+
* </Suspense>
|
|
937
|
+
* </>
|
|
938
|
+
* );
|
|
939
|
+
* }
|
|
940
|
+
*
|
|
941
|
+
* function Hello({ queryRef }) {
|
|
942
|
+
* const { data } = useReadQuery(queryRef);
|
|
943
|
+
*
|
|
944
|
+
* return <div>{data.greeting.message}</div>;
|
|
945
|
+
* }
|
|
946
|
+
* ```
|
|
947
|
+
*
|
|
948
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
949
|
+
* @param options - Options to control how the query is executed.
|
|
950
|
+
* @returns A tuple in the form of `[loadQuery, queryRef, handlers]`
|
|
951
|
+
*/
|
|
952
|
+
interface Signature extends Signatures.Evaluated {}
|
|
953
|
+
}
|
|
954
|
+
export declare const useLoadableQuery: useLoadableQuery.Signature;
|
|
955
|
+
export {};
|