@apollo/client 4.0.0-alpha.2 → 4.0.0-alpha.4

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.
Files changed (150) hide show
  1. package/.changeset/eighty-squids-fix.md +15 -0
  2. package/.changeset/four-ghosts-watch.md +5 -0
  3. package/.changeset/funny-jeans-invent.md +16 -0
  4. package/.changeset/khaki-spies-work.md +11 -0
  5. package/.changeset/light-apes-rescue.md +5 -0
  6. package/.changeset/odd-lemons-relax.md +5 -0
  7. package/.changeset/pre.json +7 -0
  8. package/.changeset/unlucky-kiwis-sell.md +5 -0
  9. package/CHANGELOG.md +58 -0
  10. package/__cjs/core/ApolloClient.cjs +22 -13
  11. package/__cjs/core/ApolloClient.cjs.map +1 -1
  12. package/__cjs/core/ApolloClient.d.cts +13 -1
  13. package/__cjs/core/ObservableQuery.cjs +29 -10
  14. package/__cjs/core/ObservableQuery.cjs.map +1 -1
  15. package/__cjs/core/ObservableQuery.d.cts +6 -3
  16. package/__cjs/core/QueryInfo.cjs +8 -7
  17. package/__cjs/core/QueryInfo.cjs.map +1 -1
  18. package/__cjs/core/QueryInfo.d.cts +1 -0
  19. package/__cjs/core/QueryManager.cjs +36 -10
  20. package/__cjs/core/QueryManager.cjs.map +1 -1
  21. package/__cjs/core/QueryManager.d.cts +11 -0
  22. package/__cjs/core/watchQueryOptions.d.cts +18 -25
  23. package/__cjs/react/hooks/index.cjs +13 -8
  24. package/__cjs/react/hooks/index.cjs.map +1 -1
  25. package/__cjs/react/hooks/index.d.cts +6 -12
  26. package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
  27. package/__cjs/react/hooks/useBackgroundQuery.d.cts +146 -43
  28. package/__cjs/react/hooks/useFragment.cjs.map +1 -1
  29. package/__cjs/react/hooks/useFragment.d.cts +51 -26
  30. package/__cjs/react/hooks/useLazyQuery.cjs +1 -1
  31. package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
  32. package/__cjs/react/hooks/useLazyQuery.d.cts +263 -266
  33. package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
  34. package/__cjs/react/hooks/useLoadableQuery.d.cts +105 -32
  35. package/__cjs/react/hooks/useMutation.cjs.map +1 -1
  36. package/__cjs/react/hooks/useMutation.d.cts +198 -3
  37. package/__cjs/react/hooks/useQuery.cjs +9 -12
  38. package/__cjs/react/hooks/useQuery.cjs.map +1 -1
  39. package/__cjs/react/hooks/useQuery.d.cts +279 -4
  40. package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
  41. package/__cjs/react/hooks/useQueryRefHandlers.d.cts +21 -20
  42. package/__cjs/react/hooks/useReadQuery.cjs.map +1 -1
  43. package/__cjs/react/hooks/useReadQuery.d.cts +26 -24
  44. package/__cjs/react/hooks/useSubscription.cjs.map +1 -1
  45. package/__cjs/react/hooks/useSubscription.d.cts +127 -4
  46. package/__cjs/react/hooks/useSuspenseFragment.cjs.map +1 -1
  47. package/__cjs/react/hooks/useSuspenseFragment.d.cts +40 -37
  48. package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
  49. package/__cjs/react/hooks/useSuspenseQuery.d.cts +202 -35
  50. package/__cjs/react/index.cjs.map +1 -1
  51. package/__cjs/react/index.d.cts +2 -1
  52. package/__cjs/react/internal/cache/QueryReference.cjs +2 -8
  53. package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
  54. package/__cjs/react/internal/index.cjs.map +1 -1
  55. package/__cjs/react/internal/index.d.cts +1 -0
  56. package/__cjs/react/internal/types.d.cts +46 -0
  57. package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
  58. package/__cjs/react/query-preloader/createQueryPreloader.d.cts +2 -3
  59. package/__cjs/react/ssr/RenderPromises.cjs.map +1 -1
  60. package/__cjs/react/ssr/RenderPromises.d.cts +6 -3
  61. package/__cjs/react/types/deprecated.cjs +3 -0
  62. package/__cjs/react/types/deprecated.cjs.map +1 -0
  63. package/__cjs/react/types/deprecated.d.cts +65 -0
  64. package/__cjs/react/types/types.documentation.d.cts +0 -8
  65. package/__cjs/testing/matchers/index.cjs +2 -0
  66. package/__cjs/testing/matchers/index.cjs.map +1 -1
  67. package/__cjs/testing/matchers/toEqualLazyQueryResult.cjs.map +1 -1
  68. package/__cjs/testing/matchers/toEqualLazyQueryResult.d.cts +2 -2
  69. package/__cjs/testing/matchers/toEqualQueryResult.cjs +0 -1
  70. package/__cjs/testing/matchers/toEqualQueryResult.cjs.map +1 -1
  71. package/__cjs/testing/matchers/toEqualQueryResult.d.cts +3 -3
  72. package/__cjs/testing/matchers/toEqualStrictTyped.cjs +44 -0
  73. package/__cjs/testing/matchers/toEqualStrictTyped.cjs.map +1 -0
  74. package/__cjs/testing/matchers/toEqualStrictTyped.d.cts +3 -0
  75. package/__cjs/version.cjs +1 -1
  76. package/__cjs/version.d.cts +1 -1
  77. package/core/ApolloClient.d.ts +13 -1
  78. package/core/ApolloClient.js +22 -13
  79. package/core/ApolloClient.js.map +1 -1
  80. package/core/ObservableQuery.d.ts +6 -3
  81. package/core/ObservableQuery.js +29 -10
  82. package/core/ObservableQuery.js.map +1 -1
  83. package/core/QueryInfo.d.ts +1 -0
  84. package/core/QueryInfo.js +8 -7
  85. package/core/QueryInfo.js.map +1 -1
  86. package/core/QueryManager.d.ts +11 -0
  87. package/core/QueryManager.js +36 -10
  88. package/core/QueryManager.js.map +1 -1
  89. package/core/watchQueryOptions.d.ts +18 -25
  90. package/package.json +1 -1
  91. package/react/hooks/index.d.ts +6 -12
  92. package/react/hooks/index.js +6 -6
  93. package/react/hooks/index.js.map +1 -1
  94. package/react/hooks/useBackgroundQuery.d.ts +146 -43
  95. package/react/hooks/useBackgroundQuery.js.map +1 -1
  96. package/react/hooks/useFragment.d.ts +51 -26
  97. package/react/hooks/useFragment.js.map +1 -1
  98. package/react/hooks/useLazyQuery.d.ts +263 -266
  99. package/react/hooks/useLazyQuery.js +1 -1
  100. package/react/hooks/useLazyQuery.js.map +1 -1
  101. package/react/hooks/useLoadableQuery.d.ts +105 -32
  102. package/react/hooks/useLoadableQuery.js.map +1 -1
  103. package/react/hooks/useMutation.d.ts +198 -3
  104. package/react/hooks/useMutation.js.map +1 -1
  105. package/react/hooks/useQuery.d.ts +279 -4
  106. package/react/hooks/useQuery.js +9 -12
  107. package/react/hooks/useQuery.js.map +1 -1
  108. package/react/hooks/useQueryRefHandlers.d.ts +21 -20
  109. package/react/hooks/useQueryRefHandlers.js.map +1 -1
  110. package/react/hooks/useReadQuery.d.ts +26 -24
  111. package/react/hooks/useReadQuery.js.map +1 -1
  112. package/react/hooks/useSubscription.d.ts +127 -4
  113. package/react/hooks/useSubscription.js.map +1 -1
  114. package/react/hooks/useSuspenseFragment.d.ts +40 -37
  115. package/react/hooks/useSuspenseFragment.js.map +1 -1
  116. package/react/hooks/useSuspenseQuery.d.ts +202 -35
  117. package/react/hooks/useSuspenseQuery.js.map +1 -1
  118. package/react/index.d.ts +2 -1
  119. package/react/index.js.map +1 -1
  120. package/react/internal/cache/QueryReference.js +2 -8
  121. package/react/internal/cache/QueryReference.js.map +1 -1
  122. package/react/internal/index.d.ts +1 -0
  123. package/react/internal/index.js.map +1 -1
  124. package/react/internal/types.d.ts +46 -0
  125. package/react/query-preloader/createQueryPreloader.d.ts +2 -3
  126. package/react/query-preloader/createQueryPreloader.js.map +1 -1
  127. package/react/ssr/RenderPromises.d.ts +6 -3
  128. package/react/ssr/RenderPromises.js.map +1 -1
  129. package/react/types/deprecated.d.ts +65 -0
  130. package/react/types/deprecated.js +2 -0
  131. package/react/types/deprecated.js.map +1 -0
  132. package/react/types/types.documentation.d.ts +0 -8
  133. package/testing/matchers/index.js +2 -0
  134. package/testing/matchers/index.js.map +1 -1
  135. package/testing/matchers/toEqualLazyQueryResult.d.ts +2 -2
  136. package/testing/matchers/toEqualLazyQueryResult.js.map +1 -1
  137. package/testing/matchers/toEqualQueryResult.d.ts +3 -3
  138. package/testing/matchers/toEqualQueryResult.js +0 -1
  139. package/testing/matchers/toEqualQueryResult.js.map +1 -1
  140. package/testing/matchers/toEqualStrictTyped.d.ts +3 -0
  141. package/testing/matchers/toEqualStrictTyped.js +40 -0
  142. package/testing/matchers/toEqualStrictTyped.js.map +1 -0
  143. package/version.d.ts +1 -1
  144. package/version.js +1 -1
  145. package/__cjs/react/types/types.d.cts +0 -671
  146. package/react/types/types.d.ts +0 -671
  147. /package/__cjs/react/{types → internal}/types.cjs +0 -0
  148. /package/__cjs/react/{types → internal}/types.cjs.map +0 -0
  149. /package/react/{types → internal}/types.js +0 -0
  150. /package/react/{types → internal}/types.js.map +0 -0
@@ -1,671 +0,0 @@
1
- import type { TypedDocumentNode } from "@graphql-typed-document-node/core";
2
- import type { DocumentNode } from "graphql";
3
- import type * as ReactTypes from "react";
4
- import type { ApolloCache, ApolloClient, ApolloQueryResult, DefaultContext, ErrorLike, ErrorPolicy, FetchMoreQueryOptions, FetchPolicy, InternalRefetchQueriesInclude, NetworkStatus, ObservableQuery, OperationVariables, RefetchWritePolicy, SubscribeToMoreFunction, UpdateQueryMapFn, WatchQueryFetchPolicy, WatchQueryOptions } from "@apollo/client/core";
5
- import type { FetchResult } from "@apollo/client/link/core";
6
- import type { MaybeMasked, Unmasked } from "@apollo/client/masking";
7
- import type { OnlyRequiredProperties } from "@apollo/client/utilities";
8
- import type { MutationSharedOptions, SharedWatchQueryOptions } from "../../core/watchQueryOptions.cjs";
9
- export type { PreloadedQueryRef, QueryRef, QueryReference, } from "../internal/index.cjs";
10
- export type { DefaultContext as Context } from "../../core/index.cjs";
11
- export type CommonOptions<TOptions> = TOptions & {
12
- client?: ApolloClient;
13
- };
14
- export interface BaseQueryOptions<TVariables extends OperationVariables = OperationVariables, TData = unknown> 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;
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
- }
42
- export interface QueryFunctionOptions<TData = unknown, 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
- export interface ObservableQueryFields<TData, TVariables extends OperationVariables> {
55
- /**
56
- * A function that instructs the query to begin re-executing at a specified interval (in milliseconds).
57
- *
58
- *
59
- * @docGroup
60
- *
61
- * 3. Helper functions
62
- */
63
- startPolling: (pollInterval: number) => void;
64
- /**
65
- * A function that instructs the query to stop polling after a previous call to `startPolling`.
66
- *
67
- *
68
- * @docGroup
69
- *
70
- * 3. Helper functions
71
- */
72
- stopPolling: () => void;
73
- /**
74
- * 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.
75
- *
76
- * This function returns _another_ function that you can call to terminate the subscription.
77
- *
78
- *
79
- * @docGroup
80
- *
81
- * 3. Helper functions
82
- */
83
- subscribeToMore: SubscribeToMoreFunction<TData, TVariables>;
84
- /**
85
- * A function that enables you to update the query's cached result without executing a followup GraphQL operation.
86
- *
87
- * See [using updateQuery and updateFragment](https://www.apollographql.com/docs/react/caching/cache-interaction/#using-updatequery-and-updatefragment) for additional information.
88
- *
89
- *
90
- * @docGroup
91
- *
92
- * 3. Helper functions
93
- */
94
- updateQuery: (mapFn: UpdateQueryMapFn<TData, TVariables>) => void;
95
- /**
96
- * A function that enables you to re-execute the query, optionally passing in new `variables`.
97
- *
98
- * 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).
99
- *
100
- * See also [Refetching](https://www.apollographql.com/docs/react/data/queries/#refetching).
101
- *
102
- * @docGroup
103
- *
104
- * 3. Helper functions
105
- */
106
- refetch: (variables?: Partial<TVariables>) => Promise<ApolloQueryResult<MaybeMasked<TData>>>;
107
- /** @internal */
108
- reobserve: (newOptions?: Partial<WatchQueryOptions<TVariables, TData>>, newNetworkStatus?: NetworkStatus) => Promise<ApolloQueryResult<MaybeMasked<TData>>>;
109
- /**
110
- * An object containing the variables that were provided for the query.
111
- *
112
- * @docGroup
113
- *
114
- * 1. Operation data
115
- */
116
- variables: TVariables | undefined;
117
- /**
118
- * 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/).
119
- *
120
- *
121
- * @docGroup
122
- *
123
- * 3. Helper functions
124
- */
125
- fetchMore: <TFetchData = TData, TFetchVars extends OperationVariables = TVariables>(fetchMoreOptions: FetchMoreQueryOptions<TFetchVars, TFetchData> & {
126
- updateQuery?: (previousQueryResult: Unmasked<TData>, options: {
127
- fetchMoreResult: Unmasked<TFetchData>;
128
- variables: TFetchVars;
129
- }) => Unmasked<TData>;
130
- }) => Promise<ApolloQueryResult<MaybeMasked<TFetchData>>>;
131
- }
132
- export interface QueryResult<TData = unknown, TVariables extends OperationVariables = OperationVariables> extends ObservableQueryFields<TData, TVariables> {
133
- /**
134
- * The instance of Apollo Client that executed the query. Can be useful for manually executing followup queries or writing data to the cache.
135
- *
136
- * @docGroup
137
- *
138
- * 2. Network info
139
- */
140
- client: ApolloClient;
141
- /**
142
- * A reference to the internal `ObservableQuery` used by the hook.
143
- */
144
- observable: ObservableQuery<TData, TVariables>;
145
- /**
146
- * An object containing the result of your GraphQL query after it completes.
147
- *
148
- * This value might be `undefined` if a query results in one or more errors (depending on the query's `errorPolicy`).
149
- *
150
- * @docGroup
151
- *
152
- * 1. Operation data
153
- */
154
- data: MaybeMasked<TData> | undefined;
155
- /**
156
- * An object containing the result from the most recent _previous_ execution of this query.
157
- *
158
- * This value is `undefined` if this is the query's first execution.
159
- *
160
- * @docGroup
161
- *
162
- * 1. Operation data
163
- */
164
- previousData?: MaybeMasked<TData>;
165
- /**
166
- * 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`.
167
- *
168
- * For more information, see [Handling operation errors](https://www.apollographql.com/docs/react/data/error-handling/).
169
- *
170
- * @docGroup
171
- *
172
- * 1. Operation data
173
- */
174
- error?: ErrorLike;
175
- /**
176
- * If `true`, the query is still in flight and results have not yet been returned.
177
- *
178
- * @docGroup
179
- *
180
- * 2. Network info
181
- */
182
- loading: boolean;
183
- /**
184
- * 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)
185
- *
186
- * Used in conjunction with the [`notifyOnNetworkStatusChange`](#notifyonnetworkstatuschange) option.
187
- *
188
- * @docGroup
189
- *
190
- * 2. Network info
191
- */
192
- networkStatus: NetworkStatus;
193
- /**
194
- * If `true`, the associated lazy query has been executed.
195
- *
196
- * This field is only present on the result object returned by [`useLazyQuery`](/react/data/queries/#executing-queries-manually).
197
- *
198
- * @docGroup
199
- *
200
- * 2. Network info
201
- */
202
- called: boolean;
203
- }
204
- export interface QueryDataOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables> extends QueryFunctionOptions<TData, TVariables> {
205
- children?: (result: QueryResult<TData, TVariables>) => ReactTypes.ReactNode;
206
- /**
207
- * A GraphQL query string parsed into an AST with the gql template literal.
208
- *
209
- * @docGroup
210
- *
211
- * 1. Operation options
212
- */
213
- query: DocumentNode | TypedDocumentNode<TData, TVariables>;
214
- }
215
- export interface QueryHookOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables> extends QueryFunctionOptions<TData, TVariables> {
216
- }
217
- export type SuspenseQueryHookFetchPolicy = Extract<WatchQueryFetchPolicy, "cache-first" | "network-only" | "no-cache" | "cache-and-network">;
218
- export interface SuspenseQueryHookOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables> {
219
- /**
220
- * The instance of `ApolloClient` to use to execute the query.
221
- *
222
- * By default, the instance that's passed down via context is used, but you can provide a different instance here.
223
- *
224
- * @docGroup
225
- *
226
- * 1. Operation options
227
- */
228
- client?: ApolloClient;
229
- /**
230
- * 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.
231
- *
232
- * @docGroup
233
- *
234
- * 2. Networking options
235
- */
236
- context?: DefaultContext;
237
- /**
238
- * An object containing all of the GraphQL variables your query requires to execute.
239
- *
240
- * Each key in the object corresponds to a variable name, and that key's value corresponds to the variable value.
241
- *
242
- * @docGroup
243
- *
244
- * 1. Operation options
245
- */
246
- variables?: TVariables;
247
- /**
248
- * Specifies how the query handles a response that returns both GraphQL errors and partial results.
249
- *
250
- * For details, see [GraphQL error policies](https://www.apollographql.com/docs/react/data/error-handling/#graphql-error-policies).
251
- *
252
- * The default value is `none`, meaning that the query result includes error details but not partial results.
253
- *
254
- * @docGroup
255
- *
256
- * 1. Operation options
257
- */
258
- errorPolicy?: ErrorPolicy;
259
- /**
260
- * If `true`, the query can return partial results from the cache if the cache doesn't contain results for all queried fields.
261
- *
262
- * The default value is `false`.
263
- *
264
- * @docGroup
265
- *
266
- * 3. Caching options
267
- */
268
- returnPartialData?: boolean;
269
- /**
270
- * Watched queries must opt into overwriting existing data on refetch, by passing refetchWritePolicy: "overwrite" in their WatchQueryOptions.
271
- *
272
- * The default value is "overwrite".
273
- *
274
- * @docGroup
275
- *
276
- * 3. Caching options
277
- */
278
- refetchWritePolicy?: RefetchWritePolicy;
279
- /**
280
- * 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).
281
- *
282
- * For details, see [Setting a fetch policy](https://www.apollographql.com/docs/react/data/queries/#setting-a-fetch-policy).
283
- *
284
- * The default value is `cache-first`.
285
- *
286
- * @docGroup
287
- *
288
- * 3. Caching options
289
- */
290
- fetchPolicy?: SuspenseQueryHookFetchPolicy;
291
- /**
292
- * A unique identifier for the query. Each item in the array must be a stable identifier to prevent infinite fetches.
293
- *
294
- * 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.
295
- *
296
- * @docGroup
297
- *
298
- * 1. Operation options
299
- */
300
- queryKey?: string | number | any[];
301
- /**
302
- * If `true`, the query is not executed. The default value is `false`.
303
- *
304
- * @deprecated
305
- *
306
- * We recommend using `skipToken` in place of the `skip` option as it is more type-safe.
307
- *
308
- * This option is deprecated and only supported to ease the migration from useQuery. It will be removed in a future release.
309
- *
310
- * @docGroup
311
- *
312
- * 1. Operation options
313
- *
314
- *
315
- * @example Recommended usage of `skipToken`:
316
- * ```ts
317
- * import { skipToken, useSuspenseQuery } from '@apollo/client';
318
- *
319
- * const { data } = useSuspenseQuery(query, id ? { variables: { id } } : skipToken);
320
- * ```
321
- */
322
- skip?: boolean;
323
- }
324
- export type BackgroundQueryHookFetchPolicy = Extract<WatchQueryFetchPolicy, "cache-first" | "network-only" | "no-cache" | "cache-and-network">;
325
- export interface BackgroundQueryHookOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables> extends Pick<QueryHookOptions<TData, TVariables>, "client" | "variables" | "errorPolicy" | "context" | "returnPartialData" | "refetchWritePolicy"> {
326
- fetchPolicy?: BackgroundQueryHookFetchPolicy;
327
- queryKey?: string | number | any[];
328
- /**
329
- * If `true`, the query is not executed. The default value is `false`.
330
- *
331
- * @deprecated
332
- *
333
- * We recommend using `skipToken` in place of the `skip` option as it is more type-safe.
334
- *
335
- * This option is deprecated and only supported to ease the migration from useQuery. It will be removed in a future release.
336
- *
337
- * @docGroup
338
- *
339
- * 1. Operation options
340
- *
341
- *
342
- * @example Recommended usage of `skipToken`:
343
- * ```ts
344
- * import { skipToken, useBackgroundQuery } from '@apollo/client';
345
- *
346
- * const [queryRef] = useBackgroundQuery(query, id ? { variables: { id } } : skipToken);
347
- * ```
348
- */
349
- skip?: boolean;
350
- }
351
- export type LoadableQueryHookFetchPolicy = Extract<WatchQueryFetchPolicy, "cache-first" | "network-only" | "no-cache" | "cache-and-network">;
352
- export interface LoadableQueryHookOptions {
353
- /**
354
- * The instance of `ApolloClient` to use to execute the query.
355
- *
356
- * By default, the instance that's passed down via context is used, but you can provide a different instance here.
357
- *
358
- * @docGroup
359
- *
360
- * 1. Operation options
361
- */
362
- client?: ApolloClient;
363
- /**
364
- * 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.
365
- *
366
- * @docGroup
367
- *
368
- * 2. Networking options
369
- */
370
- context?: DefaultContext;
371
- /**
372
- * Specifies how the query handles a response that returns both GraphQL errors and partial results.
373
- *
374
- * For details, see [GraphQL error policies](https://www.apollographql.com/docs/react/data/error-handling/#graphql-error-policies).
375
- *
376
- * The default value is `none`, meaning that the query result includes error details but not partial results.
377
- *
378
- * @docGroup
379
- *
380
- * 1. Operation options
381
- */
382
- errorPolicy?: ErrorPolicy;
383
- /**
384
- * 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).
385
- *
386
- * For details, see [Setting a fetch policy](https://www.apollographql.com/docs/react/data/queries/#setting-a-fetch-policy).
387
- *
388
- * The default value is `cache-first`.
389
- *
390
- * @docGroup
391
- *
392
- * 3. Caching options
393
- */
394
- fetchPolicy?: LoadableQueryHookFetchPolicy;
395
- /**
396
- * A unique identifier for the query. Each item in the array must be a stable identifier to prevent infinite fetches.
397
- *
398
- * 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.
399
- *
400
- * @docGroup
401
- *
402
- * 1. Operation options
403
- */
404
- queryKey?: string | number | any[];
405
- /**
406
- * 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.
407
- *
408
- * @docGroup
409
- *
410
- * 3. Caching options
411
- */
412
- refetchWritePolicy?: RefetchWritePolicy;
413
- /**
414
- * If `true`, the query can return partial results from the cache if the cache doesn't contain results for all queried fields.
415
- *
416
- * The default value is `false`.
417
- *
418
- * @docGroup
419
- *
420
- * 3. Caching options
421
- */
422
- returnPartialData?: boolean;
423
- }
424
- export type RefetchQueriesFunction = (...args: any[]) => InternalRefetchQueriesInclude;
425
- export interface BaseMutationOptions<TData = unknown, TVariables = OperationVariables, TContext = DefaultContext, TCache extends ApolloCache = ApolloCache> extends MutationSharedOptions<TData, TVariables, TContext, TCache> {
426
- /**
427
- * The instance of `ApolloClient` to use to execute the mutation.
428
- *
429
- * By default, the instance that's passed down via context is used, but you can provide a different instance here.
430
- *
431
- * @docGroup
432
- *
433
- * 2. Networking options
434
- */
435
- client?: ApolloClient;
436
- /**
437
- * If `true`, the in-progress mutation's associated component re-renders whenever the network status changes or a network error occurs.
438
- *
439
- * The default value is `false`.
440
- *
441
- * @docGroup
442
- *
443
- * 2. Networking options
444
- */
445
- notifyOnNetworkStatusChange?: boolean;
446
- /**
447
- * A callback function that's called when your mutation successfully completes with zero errors (or if `errorPolicy` is `ignore` and partial data is returned).
448
- *
449
- * This function is passed the mutation's result `data` and any options passed to the mutation.
450
- *
451
- * @docGroup
452
- *
453
- * 1. Operation options
454
- */
455
- onCompleted?: (data: MaybeMasked<TData>, clientOptions?: BaseMutationOptions<TData, TVariables, TContext, TCache>) => void;
456
- /**
457
- * A callback function that's called when the mutation encounters one or more errors (unless `errorPolicy` is `ignore`).
458
- *
459
- * 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.
460
- *
461
- * @docGroup
462
- *
463
- * 1. Operation options
464
- */
465
- onError?: (error: ErrorLike, clientOptions?: BaseMutationOptions<TData, TVariables, TContext, TCache>) => void;
466
- }
467
- export interface MutationFunctionOptions<TData = unknown, TVariables = OperationVariables, TContext = DefaultContext, TCache extends ApolloCache = ApolloCache> extends BaseMutationOptions<TData, TVariables, TContext, TCache> {
468
- /**
469
- * A GraphQL document, often created with `gql` from the `graphql-tag` package, that contains a single mutation inside of it.
470
- *
471
- * @docGroup
472
- *
473
- * 1. Operation options
474
- */
475
- mutation?: DocumentNode | TypedDocumentNode<TData, TVariables>;
476
- }
477
- export interface MutationResult<TData = unknown> {
478
- /**
479
- * The data returned from your mutation. Can be `undefined` if `ignoreResults` is `true`.
480
- */
481
- data?: MaybeMasked<TData> | null;
482
- /**
483
- * 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`.
484
- *
485
- * For more information, see [Handling operation errors](https://www.apollographql.com/docs/react/data/error-handling/).
486
- */
487
- error?: ErrorLike;
488
- /**
489
- * If `true`, the mutation is currently in flight.
490
- */
491
- loading: boolean;
492
- /**
493
- * If `true`, the mutation's mutate function has been called.
494
- */
495
- called: boolean;
496
- /**
497
- * The instance of Apollo Client that executed the mutation.
498
- *
499
- * Can be useful for manually executing followup operations or writing data to the cache.
500
- */
501
- client: ApolloClient;
502
- /**
503
- * A function that you can call to reset the mutation's result to its initial, uncalled state.
504
- */
505
- reset: () => void;
506
- }
507
- export declare type MutationFunction<TData = unknown, TVariables = OperationVariables, TContext = DefaultContext, TCache extends ApolloCache = ApolloCache> = (options?: MutationFunctionOptions<TData, TVariables, TContext, TCache>) => Promise<FetchResult<MaybeMasked<TData>>>;
508
- export interface MutationHookOptions<TData = unknown, TVariables = OperationVariables, TContext = DefaultContext, TCache extends ApolloCache = ApolloCache> extends BaseMutationOptions<TData, TVariables, TContext, TCache> {
509
- }
510
- export interface MutationDataOptions<TData = unknown, TVariables = OperationVariables, TContext = DefaultContext, TCache extends ApolloCache = ApolloCache> extends BaseMutationOptions<TData, TVariables, TContext, TCache> {
511
- mutation: DocumentNode | TypedDocumentNode<TData, TVariables>;
512
- }
513
- export type MutationTuple<TData, TVariables, TContext = DefaultContext, TCache extends ApolloCache = ApolloCache> = [
514
- mutate: (options?: MutationFunctionOptions<TData, TVariables, TContext, TCache>) => Promise<FetchResult<MaybeMasked<TData>>>,
515
- result: MutationResult<TData>
516
- ];
517
- export interface OnDataOptions<TData = unknown> {
518
- client: ApolloClient;
519
- data: SubscriptionResult<TData>;
520
- }
521
- export interface OnSubscriptionDataOptions<TData = unknown> {
522
- client: ApolloClient;
523
- subscriptionData: SubscriptionResult<TData>;
524
- }
525
- export interface BaseSubscriptionOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables> {
526
- /**
527
- * An object containing all of the variables your subscription needs to execute
528
- */
529
- variables?: TVariables;
530
- /**
531
- * 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).
532
- */
533
- fetchPolicy?: FetchPolicy;
534
- /**
535
- * Specifies the `ErrorPolicy` to be used for this operation
536
- */
537
- errorPolicy?: ErrorPolicy;
538
- /**
539
- * Determines if your subscription should be unsubscribed and subscribed again when an input to the hook (such as `subscription` or `variables`) changes.
540
- */
541
- shouldResubscribe?: boolean | ((options: BaseSubscriptionOptions<TData, TVariables>) => boolean);
542
- /**
543
- * An `ApolloClient` instance. By default `useSubscription` / `Subscription` uses the client passed down via context, but a different client can be passed in.
544
- */
545
- client?: ApolloClient;
546
- /**
547
- * Determines if the current subscription should be skipped. Useful if, for example, variables depend on previous queries and are not ready yet.
548
- */
549
- skip?: boolean;
550
- /**
551
- * Shared context between your component and your network interface (Apollo Link).
552
- */
553
- context?: DefaultContext;
554
- /**
555
- * Shared context between your component and your network interface (Apollo Link).
556
- */
557
- extensions?: Record<string, any>;
558
- /**
559
- * Allows the registration of a callback function that will be triggered each time the `useSubscription` Hook / `Subscription` component completes the subscription.
560
- *
561
- * @since
562
- *
563
- * 3.7.0
564
- */
565
- onComplete?: () => void;
566
- /**
567
- * 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`.
568
- *
569
- * @since
570
- *
571
- * 3.7.0
572
- */
573
- onData?: (options: OnDataOptions<TData>) => any;
574
- /**
575
- * 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`.
576
- *
577
- * @deprecated
578
- *
579
- * Use `onData` instead
580
- */
581
- onSubscriptionData?: (options: OnSubscriptionDataOptions<TData>) => any;
582
- /**
583
- * Allows the registration of a callback function that will be triggered each time the `useSubscription` Hook / `Subscription` component receives an error.
584
- *
585
- * @since
586
- *
587
- * 3.7.0
588
- */
589
- onError?: (error: ErrorLike) => void;
590
- /**
591
- * Allows the registration of a callback function that will be triggered when the `useSubscription` Hook / `Subscription` component completes the subscription.
592
- *
593
- * @deprecated
594
- *
595
- * Use `onComplete` instead
596
- */
597
- onSubscriptionComplete?: () => void;
598
- /**
599
- * 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.
600
- *
601
- * Changing this to `true` when the hook already has `data` will reset the `data` to `undefined`.
602
- *
603
- * @defaultValue `false`
604
- */
605
- ignoreResults?: boolean;
606
- }
607
- export interface SubscriptionResult<TData = unknown, TVariables = OperationVariables> {
608
- /**
609
- * A boolean that indicates whether any initial data has been returned
610
- */
611
- loading: boolean;
612
- /**
613
- * An object containing the result of your GraphQL subscription. Defaults to an empty object.
614
- */
615
- data?: MaybeMasked<TData>;
616
- /**
617
- * A runtime error with `graphQLErrors` and `networkError` properties
618
- */
619
- error?: ErrorLike;
620
- /**
621
- * @internal
622
- */
623
- variables?: TVariables;
624
- }
625
- export interface SubscriptionHookOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables> extends BaseSubscriptionOptions<TData, TVariables> {
626
- }
627
- /**
628
- * @deprecated This type is not used anymore. It will be removed in the next major version of Apollo Client
629
- */
630
- export interface SubscriptionDataOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables> extends BaseSubscriptionOptions<TData, TVariables> {
631
- subscription: DocumentNode | TypedDocumentNode<TData, TVariables>;
632
- children?: null | ((result: SubscriptionResult<TData>) => ReactTypes.ReactNode);
633
- }
634
- export type VariablesOption<TVariables extends OperationVariables> = [
635
- TVariables
636
- ] extends [never] ? {
637
- /**
638
- * An object containing all of the GraphQL variables your query requires to execute.
639
- *
640
- * Each key in the object corresponds to a variable name, and that key's value corresponds to the variable value.
641
- *
642
- * @docGroup
643
- *
644
- * 1. Operation options
645
- */
646
- variables?: Record<string, never>;
647
- } : Record<string, never> extends OnlyRequiredProperties<TVariables> ? {
648
- /**
649
- * An object containing all of the GraphQL variables your query requires to execute.
650
- *
651
- * Each key in the object corresponds to a variable name, and that key's value corresponds to the variable value.
652
- *
653
- * @docGroup
654
- *
655
- * 1. Operation options
656
- */
657
- variables?: TVariables;
658
- } : {
659
- /**
660
- * An object containing all of the GraphQL variables your query requires to execute.
661
- *
662
- * Each key in the object corresponds to a variable name, and that key's value corresponds to the variable value.
663
- *
664
- * @docGroup
665
- *
666
- * 1. Operation options
667
- */
668
- variables: TVariables;
669
- };
670
- export type { NoInfer } from "../../utilities/index.cjs";
671
- //# sourceMappingURL=types.d.cts.map