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