UNPKG

32.8 kBTypeScriptView Raw
1import type * as ReactTypes from "react";
2import type { DocumentNode, GraphQLFormattedError } from "graphql";
3import type { TypedDocumentNode } from "@graphql-typed-document-node/core";
4import type { Observable, ObservableSubscription } from "../../utilities/index.js";
5import type { FetchResult } from "../../link/core/index.js";
6import type { ApolloError } from "../../errors/index.js";
7import type { ApolloCache, ApolloClient, DefaultContext, FetchPolicy, NetworkStatus, ObservableQuery, OperationVariables, InternalRefetchQueriesInclude, WatchQueryOptions, WatchQueryFetchPolicy, SubscribeToMoreOptions, ApolloQueryResult, FetchMoreQueryOptions, ErrorPolicy, RefetchWritePolicy } from "../../core/index.js";
8import type { MutationSharedOptions, SharedWatchQueryOptions } from "../../core/watchQueryOptions.js";
9export type { QueryReference, QueryRef, PreloadedQueryRef, } from "../internal/index.js";
10export type { DefaultContext as Context } from "../../core/index.js";
11export type CommonOptions<TOptions> = TOptions & {
12 client?: ApolloClient<object>;
13};
14export interface BaseQueryOptions<TVariables extends OperationVariables = OperationVariables, TData = any> extends SharedWatchQueryOptions<TVariables, TData> {
15 /**
16 * Pass `false` to skip executing the query during [server-side rendering](https://www.apollographql.com/docs/react/performance/server-side-rendering/).
17 *
18 * @docGroup
19 *
20 * 2. Networking options
21 */
22 ssr?: boolean;
23 /**
24 * The instance of `ApolloClient` to use to execute the query.
25 *
26 * By default, the instance that's passed down via context is used, but you can provide a different instance here.
27 *
28 * @docGroup
29 *
30 * 1. Operation options
31 */
32 client?: ApolloClient<any>;
33 /**
34 * 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.
35 *
36 * @docGroup
37 *
38 * 2. Networking options
39 */
40 context?: DefaultContext;
41}
42export interface QueryFunctionOptions<TData = any, TVariables extends OperationVariables = OperationVariables> extends BaseQueryOptions<TVariables, TData> {
43 /**
44 * If true, the query is not executed.
45 *
46 * The default value is `false`.
47 *
48 * @docGroup
49 *
50 * 1. Operation options
51 */
52 skip?: boolean;
53 /**
54 * A callback function that's called when your query successfully completes with zero errors (or if `errorPolicy` is `ignore` and partial data is returned).
55 *
56 * This function is passed the query's result `data`.
57 *
58 * @docGroup
59 *
60 * 1. Operation options
61 */
62 onCompleted?: (data: TData) => void;
63 /**
64 * A callback function that's called when the query encounters one or more errors (unless `errorPolicy` is `ignore`).
65 *
66 * This function is passed an `ApolloError` object that contains either a `networkError` object or a `graphQLErrors` array, depending on the error(s) that occurred.
67 *
68 * @docGroup
69 *
70 * 1. Operation options
71 */
72 onError?: (error: ApolloError) => void;
73 /** @internal */
74 defaultOptions?: Partial<WatchQueryOptions<TVariables, TData>>;
75}
76export interface ObservableQueryFields<TData, TVariables extends OperationVariables> {
77 /**
78 * A function that instructs the query to begin re-executing at a specified interval (in milliseconds).
79 *
80 *
81 * @docGroup
82 *
83 * 3. Helper functions
84 */
85 startPolling: (pollInterval: number) => void;
86 /**
87 * A function that instructs the query to stop polling after a previous call to `startPolling`.
88 *
89 *
90 * @docGroup
91 *
92 * 3. Helper functions
93 */
94 stopPolling: () => void;
95 /**
96 * 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.
97 *
98 * This function returns _another_ function that you can call to terminate the subscription.
99 *
100 *
101 * @docGroup
102 *
103 * 3. Helper functions
104 */
105 subscribeToMore: <TSubscriptionData = TData, TSubscriptionVariables extends OperationVariables = TVariables>(options: SubscribeToMoreOptions<TData, TSubscriptionVariables, TSubscriptionData>) => () => void;
106 /**
107 * A function that enables you to update the query's cached result without executing a followup GraphQL operation.
108 *
109 * See [using updateQuery and updateFragment](https://www.apollographql.com/docs/react/caching/cache-interaction/#using-updatequery-and-updatefragment) for additional information.
110 *
111 *
112 * @docGroup
113 *
114 * 3. Helper functions
115 */
116 updateQuery: <TVars extends OperationVariables = TVariables>(mapFn: (previousQueryResult: TData, options: Pick<WatchQueryOptions<TVars, TData>, "variables">) => TData) => void;
117 /**
118 * A function that enables you to re-execute the query, optionally passing in new `variables`.
119 *
120 * 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).
121 *
122 * See also [Refetching](https://www.apollographql.com/docs/react/data/queries/#refetching).
123 *
124 * @docGroup
125 *
126 * 3. Helper functions
127 */
128 refetch: (variables?: Partial<TVariables>) => Promise<ApolloQueryResult<TData>>;
129 /** @internal */
130 reobserve: (newOptions?: Partial<WatchQueryOptions<TVariables, TData>>, newNetworkStatus?: NetworkStatus) => Promise<ApolloQueryResult<TData>>;
131 /**
132 * An object containing the variables that were provided for the query.
133 *
134 * @docGroup
135 *
136 * 1. Operation data
137 */
138 variables: TVariables | undefined;
139 /**
140 * 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/).
141 *
142 *
143 * @docGroup
144 *
145 * 3. Helper functions
146 */
147 fetchMore: <TFetchData = TData, TFetchVars extends OperationVariables = TVariables>(fetchMoreOptions: FetchMoreQueryOptions<TFetchVars, TFetchData> & {
148 updateQuery?: (previousQueryResult: TData, options: {
149 fetchMoreResult: TFetchData;
150 variables: TFetchVars;
151 }) => TData;
152 }) => Promise<ApolloQueryResult<TFetchData>>;
153}
154export interface QueryResult<TData = any, TVariables extends OperationVariables = OperationVariables> extends ObservableQueryFields<TData, TVariables> {
155 /**
156 * The instance of Apollo Client that executed the query. Can be useful for manually executing followup queries or writing data to the cache.
157 *
158 * @docGroup
159 *
160 * 2. Network info
161 */
162 client: ApolloClient<any>;
163 /**
164 * A reference to the internal `ObservableQuery` used by the hook.
165 */
166 observable: ObservableQuery<TData, TVariables>;
167 /**
168 * An object containing the result of your GraphQL query after it completes.
169 *
170 * This value might be `undefined` if a query results in one or more errors (depending on the query's `errorPolicy`).
171 *
172 * @docGroup
173 *
174 * 1. Operation data
175 */
176 data: TData | undefined;
177 /**
178 * An object containing the result from the most recent _previous_ execution of this query.
179 *
180 * This value is `undefined` if this is the query's first execution.
181 *
182 * @docGroup
183 *
184 * 1. Operation data
185 */
186 previousData?: TData;
187 /**
188 * If the query produces one or more errors, this object contains either an array of `graphQLErrors` or a single `networkError`. Otherwise, this value is `undefined`.
189 *
190 * For more information, see [Handling operation errors](https://www.apollographql.com/docs/react/data/error-handling/).
191 *
192 * @docGroup
193 *
194 * 1. Operation data
195 */
196 error?: ApolloError;
197 /**
198 * @deprecated This property will be removed in a future version of Apollo Client.
199 * Please use `error.graphQLErrors` instead.
200 */
201 errors?: ReadonlyArray<GraphQLFormattedError>;
202 /**
203 * If `true`, the query is still in flight and results have not yet been returned.
204 *
205 * @docGroup
206 *
207 * 2. Network info
208 */
209 loading: boolean;
210 /**
211 * 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)
212 *
213 * Used in conjunction with the [`notifyOnNetworkStatusChange`](#notifyonnetworkstatuschange) option.
214 *
215 * @docGroup
216 *
217 * 2. Network info
218 */
219 networkStatus: NetworkStatus;
220 /**
221 * If `true`, the associated lazy query has been executed.
222 *
223 * This field is only present on the result object returned by [`useLazyQuery`](/react/data/queries/#executing-queries-manually).
224 *
225 * @docGroup
226 *
227 * 2. Network info
228 */
229 called: boolean;
230}
231export interface QueryDataOptions<TData = any, TVariables extends OperationVariables = OperationVariables> extends QueryFunctionOptions<TData, TVariables> {
232 children?: (result: QueryResult<TData, TVariables>) => ReactTypes.ReactNode;
233 /**
234 * A GraphQL query string parsed into an AST with the gql template literal.
235 *
236 * @docGroup
237 *
238 * 1. Operation options
239 */
240 query: DocumentNode | TypedDocumentNode<TData, TVariables>;
241}
242export interface QueryHookOptions<TData = any, TVariables extends OperationVariables = OperationVariables> extends QueryFunctionOptions<TData, TVariables> {
243}
244export interface LazyQueryHookOptions<TData = any, TVariables extends OperationVariables = OperationVariables> extends BaseQueryOptions<TVariables, TData> {
245 /**
246 * A callback function that's called when your query successfully completes with zero errors (or if `errorPolicy` is `ignore` and partial data is returned).
247 *
248 * This function is passed the query's result `data`.
249 *
250 * @docGroup
251 *
252 * 1. Operation options
253 */
254 onCompleted?: (data: TData) => void;
255 /**
256 * A callback function that's called when the query encounters one or more errors (unless `errorPolicy` is `ignore`).
257 *
258 * This function is passed an `ApolloError` object that contains either a `networkError` object or a `graphQLErrors` array, depending on the error(s) that occurred.
259 *
260 * @docGroup
261 *
262 * 1. Operation options
263 */
264 onError?: (error: ApolloError) => void;
265 /** @internal */
266 defaultOptions?: Partial<WatchQueryOptions<TVariables, TData>>;
267}
268export interface LazyQueryHookExecOptions<TData = any, TVariables extends OperationVariables = OperationVariables> extends LazyQueryHookOptions<TData, TVariables> {
269 query?: DocumentNode | TypedDocumentNode<TData, TVariables>;
270}
271export type SuspenseQueryHookFetchPolicy = Extract<WatchQueryFetchPolicy, "cache-first" | "network-only" | "no-cache" | "cache-and-network">;
272export interface SuspenseQueryHookOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables> {
273 /**
274 * The instance of `ApolloClient` to use to execute the query.
275 *
276 * By default, the instance that's passed down via context is used, but you can provide a different instance here.
277 *
278 * @docGroup
279 *
280 * 1. Operation options
281 */
282 client?: ApolloClient<any>;
283 /**
284 * 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.
285 *
286 * @docGroup
287 *
288 * 2. Networking options
289 */
290 context?: DefaultContext;
291 /**
292 * An object containing all of the GraphQL variables your query requires to execute.
293 *
294 * Each key in the object corresponds to a variable name, and that key's value corresponds to the variable value.
295 *
296 * @docGroup
297 *
298 * 1. Operation options
299 */
300 variables?: TVariables;
301 /**
302 * Specifies how the query handles a response that returns both GraphQL errors and partial results.
303 *
304 * For details, see [GraphQL error policies](https://www.apollographql.com/docs/react/data/error-handling/#graphql-error-policies).
305 *
306 * The default value is `none`, meaning that the query result includes error details but not partial results.
307 *
308 * @docGroup
309 *
310 * 1. Operation options
311 */
312 errorPolicy?: ErrorPolicy;
313 /**
314 * Whether to canonize cache results before returning them. Canonization takes some extra time, but it speeds up future deep equality comparisons. Defaults to false.
315 *
316 * @deprecated
317 *
318 * Using `canonizeResults` can result in memory leaks so we generally do not recommend using this option anymore. A future version of Apollo Client will contain a similar feature without the risk of memory leaks.
319 */
320 canonizeResults?: boolean;
321 /**
322 * If `true`, the query can return partial results from the cache if the cache doesn't contain results for all queried fields.
323 *
324 * The default value is `false`.
325 *
326 * @docGroup
327 *
328 * 3. Caching options
329 */
330 returnPartialData?: boolean;
331 /**
332 * Watched queries must opt into overwriting existing data on refetch, by passing refetchWritePolicy: "overwrite" in their WatchQueryOptions.
333 *
334 * The default value is "overwrite".
335 *
336 * @docGroup
337 *
338 * 3. Caching options
339 */
340 refetchWritePolicy?: RefetchWritePolicy;
341 /**
342 * 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).
343 *
344 * For details, see [Setting a fetch policy](https://www.apollographql.com/docs/react/data/queries/#setting-a-fetch-policy).
345 *
346 * The default value is `cache-first`.
347 *
348 * @docGroup
349 *
350 * 3. Caching options
351 */
352 fetchPolicy?: SuspenseQueryHookFetchPolicy;
353 /**
354 * A unique identifier for the query. Each item in the array must be a stable identifier to prevent infinite fetches.
355 *
356 * This is useful when using the same query and variables combination in more than one component, otherwise the components may clobber each other. This can also be used to force the query to re-evaluate fresh.
357 *
358 * @docGroup
359 *
360 * 1. Operation options
361 */
362 queryKey?: string | number | any[];
363 /**
364 * If `true`, the query is not executed. The default value is `false`.
365 *
366 * @deprecated
367 *
368 * We recommend using `skipToken` in place of the `skip` option as it is more type-safe.
369 *
370 * This option is deprecated and only supported to ease the migration from useQuery. It will be removed in a future release.
371 *
372 * @docGroup
373 *
374 * 1. Operation options
375 *
376 *
377 * @example Recommended usage of `skipToken`:
378 * ```ts
379 * import { skipToken, useSuspenseQuery } from '@apollo/client';
380 *
381 * const { data } = useSuspenseQuery(query, id ? { variables: { id } } : skipToken);
382 * ```
383 */
384 skip?: boolean;
385}
386export type BackgroundQueryHookFetchPolicy = Extract<WatchQueryFetchPolicy, "cache-first" | "network-only" | "no-cache" | "cache-and-network">;
387export interface BackgroundQueryHookOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables> extends Pick<QueryHookOptions<TData, TVariables>, "client" | "variables" | "errorPolicy" | "context" | "canonizeResults" | "returnPartialData" | "refetchWritePolicy"> {
388 fetchPolicy?: BackgroundQueryHookFetchPolicy;
389 queryKey?: string | number | any[];
390 /**
391 * If `true`, the query is not executed. The default value is `false`.
392 *
393 * @deprecated
394 *
395 * We recommend using `skipToken` in place of the `skip` option as it is more type-safe.
396 *
397 * This option is deprecated and only supported to ease the migration from useQuery. It will be removed in a future release.
398 *
399 * @docGroup
400 *
401 * 1. Operation options
402 *
403 *
404 * @example Recommended usage of `skipToken`:
405 * ```ts
406 * import { skipToken, useBackgroundQuery } from '@apollo/client';
407 *
408 * const [queryRef] = useBackgroundQuery(query, id ? { variables: { id } } : skipToken);
409 * ```
410 */
411 skip?: boolean;
412}
413export type LoadableQueryHookFetchPolicy = Extract<WatchQueryFetchPolicy, "cache-first" | "network-only" | "no-cache" | "cache-and-network">;
414export interface LoadableQueryHookOptions {
415 /**
416 * Whether to canonize cache results before returning them. Canonization takes some extra time, but it speeds up future deep equality comparisons. Defaults to false.
417 *
418 * @deprecated
419 *
420 * Using `canonizeResults` can result in memory leaks so we generally do not recommend using this option anymore. A future version of Apollo Client will contain a similar feature without the risk of memory leaks.
421 */
422 canonizeResults?: boolean;
423 /**
424 * The instance of `ApolloClient` to use to execute the query.
425 *
426 * By default, the instance that's passed down via context is used, but you can provide a different instance here.
427 *
428 * @docGroup
429 *
430 * 1. Operation options
431 */
432 client?: ApolloClient<any>;
433 /**
434 * 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.
435 *
436 * @docGroup
437 *
438 * 2. Networking options
439 */
440 context?: DefaultContext;
441 /**
442 * Specifies how the query handles a response that returns both GraphQL errors and partial results.
443 *
444 * For details, see [GraphQL error policies](https://www.apollographql.com/docs/react/data/error-handling/#graphql-error-policies).
445 *
446 * The default value is `none`, meaning that the query result includes error details but not partial results.
447 *
448 * @docGroup
449 *
450 * 1. Operation options
451 */
452 errorPolicy?: ErrorPolicy;
453 /**
454 * 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).
455 *
456 * For details, see [Setting a fetch policy](https://www.apollographql.com/docs/react/data/queries/#setting-a-fetch-policy).
457 *
458 * The default value is `cache-first`.
459 *
460 * @docGroup
461 *
462 * 3. Caching options
463 */
464 fetchPolicy?: LoadableQueryHookFetchPolicy;
465 /**
466 * A unique identifier for the query. Each item in the array must be a stable identifier to prevent infinite fetches.
467 *
468 * This is useful when using the same query and variables combination in more than one component, otherwise the components may clobber each other. This can also be used to force the query to re-evaluate fresh.
469 *
470 * @docGroup
471 *
472 * 1. Operation options
473 */
474 queryKey?: string | number | any[];
475 /**
476 * Specifies whether a `NetworkStatus.refetch` operation should merge incoming field data with existing data, or overwrite the existing data. Overwriting is probably preferable, but merging is currently the default behavior, for backwards compatibility with Apollo Client 3.x.
477 *
478 * @docGroup
479 *
480 * 3. Caching options
481 */
482 refetchWritePolicy?: RefetchWritePolicy;
483 /**
484 * If `true`, the query can return partial results from the cache if the cache doesn't contain results for all queried fields.
485 *
486 * The default value is `false`.
487 *
488 * @docGroup
489 *
490 * 3. Caching options
491 */
492 returnPartialData?: boolean;
493}
494/**
495 * @deprecated This type will be removed in the next major version of Apollo Client
496 */
497export interface QueryLazyOptions<TVariables> {
498 /**
499 * An object containing all of the GraphQL variables your query requires to execute.
500 *
501 * Each key in the object corresponds to a variable name, and that key's value corresponds to the variable value.
502 *
503 * @docGroup
504 *
505 * 1. Operation options
506 */
507 variables?: TVariables;
508 /**
509 * 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.
510 *
511 * @docGroup
512 *
513 * 2. Networking options
514 */
515 context?: DefaultContext;
516}
517/**
518 * @deprecated This type will be removed in the next major version of Apollo Client
519 */
520export type LazyQueryResult<TData, TVariables extends OperationVariables> = QueryResult<TData, TVariables>;
521/**
522 * @deprecated This type will be removed in the next major version of Apollo Client
523 */
524export type QueryTuple<TData, TVariables extends OperationVariables> = LazyQueryResultTuple<TData, TVariables>;
525export type LazyQueryExecFunction<TData, TVariables extends OperationVariables> = (options?: Partial<LazyQueryHookExecOptions<TData, TVariables>>) => Promise<QueryResult<TData, TVariables>>;
526export type LazyQueryResultTuple<TData, TVariables extends OperationVariables> = [
527 execute: LazyQueryExecFunction<TData, TVariables>,
528 result: QueryResult<TData, TVariables>
529];
530export type RefetchQueriesFunction = (...args: any[]) => InternalRefetchQueriesInclude;
531export interface BaseMutationOptions<TData = any, TVariables = OperationVariables, TContext = DefaultContext, TCache extends ApolloCache<any> = ApolloCache<any>> extends MutationSharedOptions<TData, TVariables, TContext, TCache> {
532 /**
533 * The instance of `ApolloClient` to use to execute the mutation.
534 *
535 * By default, the instance that's passed down via context is used, but you can provide a different instance here.
536 *
537 * @docGroup
538 *
539 * 2. Networking options
540 */
541 client?: ApolloClient<object>;
542 /**
543 * If `true`, the in-progress mutation's associated component re-renders whenever the network status changes or a network error occurs.
544 *
545 * The default value is `false`.
546 *
547 * @docGroup
548 *
549 * 2. Networking options
550 */
551 notifyOnNetworkStatusChange?: boolean;
552 /**
553 * A callback function that's called when your mutation successfully completes with zero errors (or if `errorPolicy` is `ignore` and partial data is returned).
554 *
555 * This function is passed the mutation's result `data` and any options passed to the mutation.
556 *
557 * @docGroup
558 *
559 * 1. Operation options
560 */
561 onCompleted?: (data: TData, clientOptions?: BaseMutationOptions) => void;
562 /**
563 * A callback function that's called when the mutation encounters one or more errors (unless `errorPolicy` is `ignore`).
564 *
565 * This function is passed an [`ApolloError`](https://github.com/apollographql/apollo-client/blob/d96f4578f89b933c281bb775a39503f6cdb59ee8/src/errors/index.ts#L36-L39) object that contains either a `networkError` object or a `graphQLErrors` array, depending on the error(s) that occurred, as well as any options passed the mutation.
566 *
567 * @docGroup
568 *
569 * 1. Operation options
570 */
571 onError?: (error: ApolloError, clientOptions?: BaseMutationOptions) => void;
572 /**
573 * If `true`, the mutation's `data` property is not updated with the mutation's result.
574 *
575 * The default value is `false`.
576 *
577 * @docGroup
578 *
579 * 1. Operation options
580 */
581 ignoreResults?: boolean;
582}
583export interface MutationFunctionOptions<TData = any, TVariables = OperationVariables, TContext = DefaultContext, TCache extends ApolloCache<any> = ApolloCache<any>> extends BaseMutationOptions<TData, TVariables, TContext, TCache> {
584 /**
585 * A GraphQL document, often created with `gql` from the `graphql-tag` package, that contains a single mutation inside of it.
586 *
587 * @docGroup
588 *
589 * 1. Operation options
590 */
591 mutation?: DocumentNode | TypedDocumentNode<TData, TVariables>;
592}
593export interface MutationResult<TData = any> {
594 /**
595 * The data returned from your mutation. Can be `undefined` if `ignoreResults` is `true`.
596 */
597 data?: TData | null;
598 /**
599 * If the mutation produces one or more errors, this object contains either an array of `graphQLErrors` or a single `networkError`. Otherwise, this value is `undefined`.
600 *
601 * For more information, see [Handling operation errors](https://www.apollographql.com/docs/react/data/error-handling/).
602 */
603 error?: ApolloError;
604 /**
605 * If `true`, the mutation is currently in flight.
606 */
607 loading: boolean;
608 /**
609 * If `true`, the mutation's mutate function has been called.
610 */
611 called: boolean;
612 /**
613 * The instance of Apollo Client that executed the mutation.
614 *
615 * Can be useful for manually executing followup operations or writing data to the cache.
616 */
617 client: ApolloClient<object>;
618 /**
619 * A function that you can call to reset the mutation's result to its initial, uncalled state.
620 */
621 reset(): void;
622}
623export declare type MutationFunction<TData = any, TVariables = OperationVariables, TContext = DefaultContext, TCache extends ApolloCache<any> = ApolloCache<any>> = (options?: MutationFunctionOptions<TData, TVariables, TContext, TCache>) => Promise<FetchResult<TData>>;
624export interface MutationHookOptions<TData = any, TVariables = OperationVariables, TContext = DefaultContext, TCache extends ApolloCache<any> = ApolloCache<any>> extends BaseMutationOptions<TData, TVariables, TContext, TCache> {
625}
626export interface MutationDataOptions<TData = any, TVariables = OperationVariables, TContext = DefaultContext, TCache extends ApolloCache<any> = ApolloCache<any>> extends BaseMutationOptions<TData, TVariables, TContext, TCache> {
627 mutation: DocumentNode | TypedDocumentNode<TData, TVariables>;
628}
629export type MutationTuple<TData, TVariables, TContext = DefaultContext, TCache extends ApolloCache<any> = ApolloCache<any>> = [
630 mutate: (options?: MutationFunctionOptions<TData, TVariables, TContext, TCache>) => Promise<FetchResult<TData>>,
631 result: MutationResult<TData>
632];
633export interface OnDataOptions<TData = any> {
634 client: ApolloClient<object>;
635 data: SubscriptionResult<TData>;
636}
637export interface OnSubscriptionDataOptions<TData = any> {
638 client: ApolloClient<object>;
639 subscriptionData: SubscriptionResult<TData>;
640}
641export interface BaseSubscriptionOptions<TData = any, TVariables extends OperationVariables = OperationVariables> {
642 /**
643 * An object containing all of the variables your subscription needs to execute
644 */
645 variables?: TVariables;
646 /**
647 * How you want your component to interact with the Apollo cache. For details, see [Setting a fetch policy](https://www.apollographql.com/docs/react/data/queries/#setting-a-fetch-policy).
648 */
649 fetchPolicy?: FetchPolicy;
650 /**
651 * Specifies the `ErrorPolicy` to be used for this operation
652 */
653 errorPolicy?: ErrorPolicy;
654 /**
655 * Determines if your subscription should be unsubscribed and subscribed again when an input to the hook (such as `subscription` or `variables`) changes.
656 */
657 shouldResubscribe?: boolean | ((options: BaseSubscriptionOptions<TData, TVariables>) => boolean);
658 /**
659 * An `ApolloClient` instance. By default `useSubscription` / `Subscription` uses the client passed down via context, but a different client can be passed in.
660 */
661 client?: ApolloClient<object>;
662 /**
663 * Determines if the current subscription should be skipped. Useful if, for example, variables depend on previous queries and are not ready yet.
664 */
665 skip?: boolean;
666 /**
667 * Shared context between your component and your network interface (Apollo Link).
668 */
669 context?: DefaultContext;
670 /**
671 * Shared context between your component and your network interface (Apollo Link).
672 */
673 extensions?: Record<string, any>;
674 /**
675 * Allows the registration of a callback function that will be triggered each time the `useSubscription` Hook / `Subscription` component completes the subscription.
676 *
677 * @since
678 *
679 * 3.7.0
680 */
681 onComplete?: () => void;
682 /**
683 * Allows the registration of a callback function that will be triggered each time the `useSubscription` Hook / `Subscription` component receives data. The callback `options` object param consists of the current Apollo Client instance in `client`, and the received subscription data in `data`.
684 *
685 * @since
686 *
687 * 3.7.0
688 */
689 onData?: (options: OnDataOptions<TData>) => any;
690 /**
691 * Allows the registration of a callback function that will be triggered each time the `useSubscription` Hook / `Subscription` component receives data. The callback `options` object param consists of the current Apollo Client instance in `client`, and the received subscription data in `subscriptionData`.
692 *
693 * @deprecated
694 *
695 * Use `onData` instead
696 */
697 onSubscriptionData?: (options: OnSubscriptionDataOptions<TData>) => any;
698 /**
699 * Allows the registration of a callback function that will be triggered each time the `useSubscription` Hook / `Subscription` component receives an error.
700 *
701 * @since
702 *
703 * 3.7.0
704 */
705 onError?: (error: ApolloError) => void;
706 /**
707 * Allows the registration of a callback function that will be triggered when the `useSubscription` Hook / `Subscription` component completes the subscription.
708 *
709 * @deprecated
710 *
711 * Use `onComplete` instead
712 */
713 onSubscriptionComplete?: () => void;
714 /**
715 * If `true`, the hook will not cause the component to rerender. This is useful when you want to control the rendering of your component yourself with logic in the `onData` and `onError` callbacks.
716 *
717 * Changing this to `true` when the hook already has `data` will reset the `data` to `undefined`.
718 *
719 * @defaultValue `false`
720 */
721 ignoreResults?: boolean;
722}
723export interface SubscriptionResult<TData = any, TVariables = any> {
724 /**
725 * A boolean that indicates whether any initial data has been returned
726 */
727 loading: boolean;
728 /**
729 * An object containing the result of your GraphQL subscription. Defaults to an empty object.
730 */
731 data?: TData;
732 /**
733 * A runtime error with `graphQLErrors` and `networkError` properties
734 */
735 error?: ApolloError;
736 /**
737 * @internal
738 */
739 variables?: TVariables;
740}
741export interface SubscriptionHookOptions<TData = any, TVariables extends OperationVariables = OperationVariables> extends BaseSubscriptionOptions<TData, TVariables> {
742}
743/**
744 * @deprecated This type is not used anymore. It will be removed in the next major version of Apollo Client
745 */
746export interface SubscriptionDataOptions<TData = any, TVariables extends OperationVariables = OperationVariables> extends BaseSubscriptionOptions<TData, TVariables> {
747 subscription: DocumentNode | TypedDocumentNode<TData, TVariables>;
748 children?: null | ((result: SubscriptionResult<TData>) => ReactTypes.ReactNode);
749}
750export interface SubscriptionCurrentObservable {
751 query?: Observable<any>;
752 subscription?: ObservableSubscription;
753}
754/**
755Helper type that allows using a type in a way that cannot be "widened" by inference on the value it is used on.
756
757This type was first suggested [in this Github discussion](https://github.com/microsoft/TypeScript/issues/14829#issuecomment-504042546).
758
759Example usage:
760```ts
761export function useQuery<
762 TData = any,
763 TVariables extends OperationVariables = OperationVariables,
764>(
765 query: DocumentNode | TypedDocumentNode<TData, TVariables>,
766 options: QueryHookOptions<NoInfer<TData>, NoInfer<TVariables>> = Object.create(null),
767)
768```
769In this case, `TData` and `TVariables` should be inferred from `query`, but never widened from something in `options`.
770
771So, in this code example:
772```ts
773declare const typedNode: TypedDocumentNode<{ foo: string}, { bar: number }>
774const { variables } = useQuery(typedNode, { variables: { bar: 4, nonExistingVariable: "string" } });
775```
776Without the use of `NoInfer`, `variables` would now be of the type `{ bar: number, nonExistingVariable: "string" }`.
777With `NoInfer`, it will instead give an error on `nonExistingVariable`.
778 */
779export type NoInfer<T> = [T][T extends any ? 0 : never];
780//# sourceMappingURL=types.d.ts.map
\No newline at end of file