@apollo/client 4.2.0-alpha.2 → 4.2.0-alpha.3

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 (78) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/__cjs/core/ApolloClient.cjs +9 -9
  3. package/__cjs/core/ApolloClient.cjs.map +1 -1
  4. package/__cjs/core/ApolloClient.d.cts +131 -21
  5. package/__cjs/link/ws/index.cjs +9 -1
  6. package/__cjs/link/ws/index.cjs.map +1 -1
  7. package/__cjs/link/ws/index.d.cts +1 -1
  8. package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
  9. package/__cjs/react/hooks/useBackgroundQuery.d.cts +1466 -65
  10. package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
  11. package/__cjs/react/hooks/useLazyQuery.d.cts +346 -39
  12. package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
  13. package/__cjs/react/hooks/useLoadableQuery.d.cts +492 -49
  14. package/__cjs/react/hooks/useMutation.cjs +5 -48
  15. package/__cjs/react/hooks/useMutation.cjs.map +1 -1
  16. package/__cjs/react/hooks/useMutation.d.cts +239 -130
  17. package/__cjs/react/hooks/useQuery.cjs.map +1 -1
  18. package/__cjs/react/hooks/useQuery.d.cts +570 -40
  19. package/__cjs/react/hooks/useSubscription.cjs +1 -1
  20. package/__cjs/react/hooks/useSubscription.cjs.map +1 -1
  21. package/__cjs/react/hooks/useSubscription.d.cts +2 -2
  22. package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
  23. package/__cjs/react/hooks/useSuspenseQuery.d.cts +734 -45
  24. package/__cjs/version.cjs +1 -1
  25. package/core/ApolloClient.d.ts +131 -21
  26. package/core/ApolloClient.js +9 -9
  27. package/core/ApolloClient.js.map +1 -1
  28. package/link/ws/index.d.ts +1 -1
  29. package/link/ws/index.js +9 -1
  30. package/link/ws/index.js.map +1 -1
  31. package/package.json +3 -7
  32. package/react/hooks/useBackgroundQuery.d.ts +1466 -65
  33. package/react/hooks/useBackgroundQuery.js.map +1 -1
  34. package/react/hooks/useLazyQuery.d.ts +346 -39
  35. package/react/hooks/useLazyQuery.js.map +1 -1
  36. package/react/hooks/useLoadableQuery.d.ts +492 -49
  37. package/react/hooks/useLoadableQuery.js.map +1 -1
  38. package/react/hooks/useMutation.d.ts +239 -130
  39. package/react/hooks/useMutation.js +5 -48
  40. package/react/hooks/useMutation.js.map +1 -1
  41. package/react/hooks/useQuery.d.ts +570 -40
  42. package/react/hooks/useQuery.js.map +1 -1
  43. package/react/hooks/useSubscription.d.ts +2 -2
  44. package/react/hooks/useSubscription.js +1 -1
  45. package/react/hooks/useSubscription.js.map +1 -1
  46. package/react/hooks/useSuspenseQuery.d.ts +734 -45
  47. package/react/hooks/useSuspenseQuery.js.map +1 -1
  48. package/react/hooks-compiled/useBackgroundQuery.d.ts +1466 -65
  49. package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
  50. package/react/hooks-compiled/useLazyQuery.d.ts +346 -39
  51. package/react/hooks-compiled/useLazyQuery.js.map +1 -1
  52. package/react/hooks-compiled/useLoadableQuery.d.ts +492 -49
  53. package/react/hooks-compiled/useLoadableQuery.js.map +1 -1
  54. package/react/hooks-compiled/useMutation.d.ts +239 -130
  55. package/react/hooks-compiled/useMutation.js +4 -47
  56. package/react/hooks-compiled/useMutation.js.map +1 -1
  57. package/react/hooks-compiled/useQuery.d.ts +570 -40
  58. package/react/hooks-compiled/useQuery.js.map +1 -1
  59. package/react/hooks-compiled/useSubscription.d.ts +2 -2
  60. package/react/hooks-compiled/useSubscription.js +1 -1
  61. package/react/hooks-compiled/useSubscription.js.map +1 -1
  62. package/react/hooks-compiled/useSuspenseQuery.d.ts +734 -45
  63. package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
  64. package/skills/apollo-client/SKILL.md +168 -0
  65. package/skills/apollo-client/references/caching.md +560 -0
  66. package/skills/apollo-client/references/error-handling.md +350 -0
  67. package/skills/apollo-client/references/fragments.md +804 -0
  68. package/skills/apollo-client/references/integration-client.md +336 -0
  69. package/skills/apollo-client/references/integration-nextjs.md +325 -0
  70. package/skills/apollo-client/references/integration-react-router.md +256 -0
  71. package/skills/apollo-client/references/integration-tanstack-start.md +378 -0
  72. package/skills/apollo-client/references/mutations.md +549 -0
  73. package/skills/apollo-client/references/queries.md +416 -0
  74. package/skills/apollo-client/references/state-management.md +428 -0
  75. package/skills/apollo-client/references/suspense-hooks.md +773 -0
  76. package/skills/apollo-client/references/troubleshooting.md +487 -0
  77. package/skills/apollo-client/references/typescript-codegen.md +133 -0
  78. package/version.js +1 -1
@@ -114,108 +114,551 @@ export declare namespace useLoadableQuery {
114
114
  }
115
115
  type ResultForOptions<TData, TVariables extends OperationVariables, TOptions extends Record<string, never> | Options> = Result<TData, TVariables, "complete" | "streaming" | (OptionWithFallback<TOptions, DefaultOptions, "errorPolicy"> extends ("none") ? never : "empty") | (OptionWithFallback<TOptions, DefaultOptions, "returnPartialData"> extends false ? never : "partial")>;
116
116
  namespace DocumentationTypes {
117
- /**
118
- * A hook for imperatively loading a query, such as responding to a user
119
- * interaction.
120
- *
121
- * > Refer to the [Suspense - Fetching in response to user interaction](https://www.apollographql.com/docs/react/data/suspense#fetching-in-response-to-user-interaction) section for a more in-depth overview of `useLoadableQuery`.
122
- *
123
- * @example
124
- *
125
- * ```jsx
126
- * import { gql, useLoadableQuery } from "@apollo/client";
127
- *
128
- * const GET_GREETING = gql`
129
- * query GetGreeting($language: String!) {
130
- * greeting(language: $language) {
131
- * message
132
- * }
133
- * }
134
- * `;
135
- *
136
- * function App() {
137
- * const [loadGreeting, queryRef] = useLoadableQuery(GET_GREETING);
138
- *
139
- * return (
140
- * <>
141
- * <button onClick={() => loadGreeting({ language: "english" })}>
142
- * Load greeting
143
- * </button>
144
- * <Suspense fallback={<div>Loading...</div>}>
145
- * {queryRef && <Hello queryRef={queryRef} />}
146
- * </Suspense>
147
- * </>
148
- * );
149
- * }
150
- *
151
- * function Hello({ queryRef }) {
152
- * const { data } = useReadQuery(queryRef);
153
- *
154
- * return <div>{data.greeting.message}</div>;
155
- * }
156
- * ```
157
- *
158
- * @param query - A GraphQL query document parsed into an AST by `gql`.
159
- * @param options - Options to control how the query is executed.
160
- * @returns A tuple in the form of `[loadQuery, queryRef, handlers]`
161
- */
162
117
  interface useLoadableQuery {
118
+ /**
119
+ * A hook for imperatively loading a query, such as responding to a user
120
+ * interaction.
121
+ *
122
+ * > Refer to the [Suspense - Fetching in response to user interaction](https://www.apollographql.com/docs/react/data/suspense#fetching-in-response-to-user-interaction) section for a more in-depth overview of `useLoadableQuery`.
123
+ *
124
+ * @example
125
+ *
126
+ * ```jsx
127
+ * import { gql, useLoadableQuery } from "@apollo/client";
128
+ *
129
+ * const GET_GREETING = gql`
130
+ * query GetGreeting($language: String!) {
131
+ * greeting(language: $language) {
132
+ * message
133
+ * }
134
+ * }
135
+ * `;
136
+ *
137
+ * function App() {
138
+ * const [loadGreeting, queryRef] = useLoadableQuery(GET_GREETING);
139
+ *
140
+ * return (
141
+ * <>
142
+ * <button onClick={() => loadGreeting({ language: "english" })}>
143
+ * Load greeting
144
+ * </button>
145
+ * <Suspense fallback={<div>Loading...</div>}>
146
+ * {queryRef && <Hello queryRef={queryRef} />}
147
+ * </Suspense>
148
+ * </>
149
+ * );
150
+ * }
151
+ *
152
+ * function Hello({ queryRef }) {
153
+ * const { data } = useReadQuery(queryRef);
154
+ *
155
+ * return <div>{data.greeting.message}</div>;
156
+ * }
157
+ * ```
158
+ *
159
+ * @param query - A GraphQL query document parsed into an AST by `gql`.
160
+ * @param options - Options to control how the query is executed.
161
+ * @returns A tuple in the form of `[loadQuery, queryRef, handlers]`
162
+ */
163
163
  <TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useLoadableQuery.Options): useLoadableQuery.Result<TData, TVariables>;
164
164
  }
165
- /**
166
- * @deprecated Avoid manually specifying generics on `useLoadableQuery`.
167
- * Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
168
- */
169
165
  interface useLoadableQuery_Deprecated {
166
+ /**
167
+ * @deprecated Avoid manually specifying generics on `useLoadableQuery`.
168
+ * Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
169
+ *
170
+ *
171
+ * A hook for imperatively loading a query, such as responding to a user
172
+ * interaction.
173
+ *
174
+ * > Refer to the [Suspense - Fetching in response to user interaction](https://www.apollographql.com/docs/react/data/suspense#fetching-in-response-to-user-interaction) section for a more in-depth overview of `useLoadableQuery`.
175
+ *
176
+ * @example
177
+ *
178
+ * ```jsx
179
+ * import { gql, useLoadableQuery } from "@apollo/client";
180
+ *
181
+ * const GET_GREETING = gql`
182
+ * query GetGreeting($language: String!) {
183
+ * greeting(language: $language) {
184
+ * message
185
+ * }
186
+ * }
187
+ * `;
188
+ *
189
+ * function App() {
190
+ * const [loadGreeting, queryRef] = useLoadableQuery(GET_GREETING);
191
+ *
192
+ * return (
193
+ * <>
194
+ * <button onClick={() => loadGreeting({ language: "english" })}>
195
+ * Load greeting
196
+ * </button>
197
+ * <Suspense fallback={<div>Loading...</div>}>
198
+ * {queryRef && <Hello queryRef={queryRef} />}
199
+ * </Suspense>
200
+ * </>
201
+ * );
202
+ * }
203
+ *
204
+ * function Hello({ queryRef }) {
205
+ * const { data } = useReadQuery(queryRef);
206
+ *
207
+ * return <div>{data.greeting.message}</div>;
208
+ * }
209
+ * ```
210
+ *
211
+ * @param query - A GraphQL query document parsed into an AST by `gql`.
212
+ * @param options - Options to control how the query is executed.
213
+ * @returns A tuple in the form of `[loadQuery, queryRef, handlers]`
214
+ */
170
215
  <TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useLoadableQuery.Options): useLoadableQuery.Result<TData, TVariables>;
171
216
  }
172
217
  }
173
218
  namespace Signatures {
174
219
  /**
220
+ * @deprecated Avoid manually specifying generics on `useLoadableQuery`.
221
+ * Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
222
+ *
223
+ *
224
+ * A hook for imperatively loading a query, such as responding to a user
225
+ * interaction.
226
+ *
227
+ * > Refer to the [Suspense - Fetching in response to user interaction](https://www.apollographql.com/docs/react/data/suspense#fetching-in-response-to-user-interaction) section for a more in-depth overview of `useLoadableQuery`.
228
+ *
229
+ * @example
230
+ *
231
+ * ```jsx
232
+ * import { gql, useLoadableQuery } from "@apollo/client";
233
+ *
234
+ * const GET_GREETING = gql`
235
+ * query GetGreeting($language: String!) {
236
+ * greeting(language: $language) {
237
+ * message
238
+ * }
239
+ * }
240
+ * `;
175
241
  *
242
+ * function App() {
243
+ * const [loadGreeting, queryRef] = useLoadableQuery(GET_GREETING);
244
+ *
245
+ * return (
246
+ * <>
247
+ * <button onClick={() => loadGreeting({ language: "english" })}>
248
+ * Load greeting
249
+ * </button>
250
+ * <Suspense fallback={<div>Loading...</div>}>
251
+ * {queryRef && <Hello queryRef={queryRef} />}
252
+ * </Suspense>
253
+ * </>
254
+ * );
255
+ * }
256
+ *
257
+ * function Hello({ queryRef }) {
258
+ * const { data } = useReadQuery(queryRef);
259
+ *
260
+ * return <div>{data.greeting.message}</div>;
261
+ * }
262
+ * ```
263
+ *
264
+ * @param query - A GraphQL query document parsed into an AST by `gql`.
265
+ * @param options - Options to control how the query is executed.
266
+ * @returns A tuple in the form of `[loadQuery, queryRef, handlers]`
176
267
  */
177
268
  interface Classic {
178
269
  /**
270
+ * @deprecated Avoid manually specifying generics on `useLoadableQuery`.
271
+ * Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
272
+ *
273
+ *
274
+ * A hook for imperatively loading a query, such as responding to a user
275
+ * interaction.
276
+ *
277
+ * > Refer to the [Suspense - Fetching in response to user interaction](https://www.apollographql.com/docs/react/data/suspense#fetching-in-response-to-user-interaction) section for a more in-depth overview of `useLoadableQuery`.
278
+ *
279
+ * @example
280
+ *
281
+ * ```jsx
282
+ * import { gql, useLoadableQuery } from "@apollo/client";
283
+ *
284
+ * const GET_GREETING = gql`
285
+ * query GetGreeting($language: String!) {
286
+ * greeting(language: $language) {
287
+ * message
288
+ * }
289
+ * }
290
+ * `;
291
+ *
292
+ * function App() {
293
+ * const [loadGreeting, queryRef] = useLoadableQuery(GET_GREETING);
294
+ *
295
+ * return (
296
+ * <>
297
+ * <button onClick={() => loadGreeting({ language: "english" })}>
298
+ * Load greeting
299
+ * </button>
300
+ * <Suspense fallback={<div>Loading...</div>}>
301
+ * {queryRef && <Hello queryRef={queryRef} />}
302
+ * </Suspense>
303
+ * </>
304
+ * );
305
+ * }
306
+ *
307
+ * function Hello({ queryRef }) {
308
+ * const { data } = useReadQuery(queryRef);
179
309
  *
310
+ * return <div>{data.greeting.message}</div>;
311
+ * }
312
+ * ```
313
+ *
314
+ * @param query - A GraphQL query document parsed into an AST by `gql`.
315
+ * @param options - Options to control how the query is executed.
316
+ * @returns A tuple in the form of `[loadQuery, queryRef, handlers]`
180
317
  */
181
318
  <TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useLoadableQuery.Options & {
182
319
  returnPartialData: true;
183
320
  errorPolicy: "ignore" | "all";
184
321
  }): useLoadableQuery.Result<TData, TVariables, "complete" | "streaming" | "partial" | "empty">;
185
322
  /**
323
+ * @deprecated Avoid manually specifying generics on `useLoadableQuery`.
324
+ * Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
325
+ *
326
+ *
327
+ * A hook for imperatively loading a query, such as responding to a user
328
+ * interaction.
329
+ *
330
+ * > Refer to the [Suspense - Fetching in response to user interaction](https://www.apollographql.com/docs/react/data/suspense#fetching-in-response-to-user-interaction) section for a more in-depth overview of `useLoadableQuery`.
331
+ *
332
+ * @example
333
+ *
334
+ * ```jsx
335
+ * import { gql, useLoadableQuery } from "@apollo/client";
186
336
  *
337
+ * const GET_GREETING = gql`
338
+ * query GetGreeting($language: String!) {
339
+ * greeting(language: $language) {
340
+ * message
341
+ * }
342
+ * }
343
+ * `;
344
+ *
345
+ * function App() {
346
+ * const [loadGreeting, queryRef] = useLoadableQuery(GET_GREETING);
347
+ *
348
+ * return (
349
+ * <>
350
+ * <button onClick={() => loadGreeting({ language: "english" })}>
351
+ * Load greeting
352
+ * </button>
353
+ * <Suspense fallback={<div>Loading...</div>}>
354
+ * {queryRef && <Hello queryRef={queryRef} />}
355
+ * </Suspense>
356
+ * </>
357
+ * );
358
+ * }
359
+ *
360
+ * function Hello({ queryRef }) {
361
+ * const { data } = useReadQuery(queryRef);
362
+ *
363
+ * return <div>{data.greeting.message}</div>;
364
+ * }
365
+ * ```
366
+ *
367
+ * @param query - A GraphQL query document parsed into an AST by `gql`.
368
+ * @param options - Options to control how the query is executed.
369
+ * @returns A tuple in the form of `[loadQuery, queryRef, handlers]`
187
370
  */
188
371
  <TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useLoadableQuery.Options & {
189
372
  errorPolicy: "ignore" | "all";
190
373
  }): useLoadableQuery.Result<TData, TVariables, "complete" | "streaming" | "empty">;
191
374
  /**
375
+ * @deprecated Avoid manually specifying generics on `useLoadableQuery`.
376
+ * Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
377
+ *
192
378
  *
379
+ * A hook for imperatively loading a query, such as responding to a user
380
+ * interaction.
381
+ *
382
+ * > Refer to the [Suspense - Fetching in response to user interaction](https://www.apollographql.com/docs/react/data/suspense#fetching-in-response-to-user-interaction) section for a more in-depth overview of `useLoadableQuery`.
383
+ *
384
+ * @example
385
+ *
386
+ * ```jsx
387
+ * import { gql, useLoadableQuery } from "@apollo/client";
388
+ *
389
+ * const GET_GREETING = gql`
390
+ * query GetGreeting($language: String!) {
391
+ * greeting(language: $language) {
392
+ * message
393
+ * }
394
+ * }
395
+ * `;
396
+ *
397
+ * function App() {
398
+ * const [loadGreeting, queryRef] = useLoadableQuery(GET_GREETING);
399
+ *
400
+ * return (
401
+ * <>
402
+ * <button onClick={() => loadGreeting({ language: "english" })}>
403
+ * Load greeting
404
+ * </button>
405
+ * <Suspense fallback={<div>Loading...</div>}>
406
+ * {queryRef && <Hello queryRef={queryRef} />}
407
+ * </Suspense>
408
+ * </>
409
+ * );
410
+ * }
411
+ *
412
+ * function Hello({ queryRef }) {
413
+ * const { data } = useReadQuery(queryRef);
414
+ *
415
+ * return <div>{data.greeting.message}</div>;
416
+ * }
417
+ * ```
418
+ *
419
+ * @param query - A GraphQL query document parsed into an AST by `gql`.
420
+ * @param options - Options to control how the query is executed.
421
+ * @returns A tuple in the form of `[loadQuery, queryRef, handlers]`
193
422
  */
194
423
  <TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useLoadableQuery.Options & {
195
424
  returnPartialData: true;
196
425
  }): useLoadableQuery.Result<TData, TVariables, "complete" | "streaming" | "partial">;
197
426
  /**
427
+ * @deprecated Avoid manually specifying generics on `useLoadableQuery`.
428
+ * Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
429
+ *
430
+ *
431
+ * A hook for imperatively loading a query, such as responding to a user
432
+ * interaction.
433
+ *
434
+ * > Refer to the [Suspense - Fetching in response to user interaction](https://www.apollographql.com/docs/react/data/suspense#fetching-in-response-to-user-interaction) section for a more in-depth overview of `useLoadableQuery`.
435
+ *
436
+ * @example
198
437
  *
438
+ * ```jsx
439
+ * import { gql, useLoadableQuery } from "@apollo/client";
440
+ *
441
+ * const GET_GREETING = gql`
442
+ * query GetGreeting($language: String!) {
443
+ * greeting(language: $language) {
444
+ * message
445
+ * }
446
+ * }
447
+ * `;
448
+ *
449
+ * function App() {
450
+ * const [loadGreeting, queryRef] = useLoadableQuery(GET_GREETING);
451
+ *
452
+ * return (
453
+ * <>
454
+ * <button onClick={() => loadGreeting({ language: "english" })}>
455
+ * Load greeting
456
+ * </button>
457
+ * <Suspense fallback={<div>Loading...</div>}>
458
+ * {queryRef && <Hello queryRef={queryRef} />}
459
+ * </Suspense>
460
+ * </>
461
+ * );
462
+ * }
463
+ *
464
+ * function Hello({ queryRef }) {
465
+ * const { data } = useReadQuery(queryRef);
466
+ *
467
+ * return <div>{data.greeting.message}</div>;
468
+ * }
469
+ * ```
470
+ *
471
+ * @param query - A GraphQL query document parsed into an AST by `gql`.
472
+ * @param options - Options to control how the query is executed.
473
+ * @returns A tuple in the form of `[loadQuery, queryRef, handlers]`
199
474
  */
200
475
  <TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: useLoadableQuery.Options): useLoadableQuery.Result<TData, TVariables, "complete" | "streaming">;
201
476
  }
202
477
  /**
478
+ * A hook for imperatively loading a query, such as responding to a user
479
+ * interaction.
480
+ *
481
+ * > Refer to the [Suspense - Fetching in response to user interaction](https://www.apollographql.com/docs/react/data/suspense#fetching-in-response-to-user-interaction) section for a more in-depth overview of `useLoadableQuery`.
482
+ *
483
+ * @example
484
+ *
485
+ * ```jsx
486
+ * import { gql, useLoadableQuery } from "@apollo/client";
487
+ *
488
+ * const GET_GREETING = gql`
489
+ * query GetGreeting($language: String!) {
490
+ * greeting(language: $language) {
491
+ * message
492
+ * }
493
+ * }
494
+ * `;
495
+ *
496
+ * function App() {
497
+ * const [loadGreeting, queryRef] = useLoadableQuery(GET_GREETING);
498
+ *
499
+ * return (
500
+ * <>
501
+ * <button onClick={() => loadGreeting({ language: "english" })}>
502
+ * Load greeting
503
+ * </button>
504
+ * <Suspense fallback={<div>Loading...</div>}>
505
+ * {queryRef && <Hello queryRef={queryRef} />}
506
+ * </Suspense>
507
+ * </>
508
+ * );
509
+ * }
510
+ *
511
+ * function Hello({ queryRef }) {
512
+ * const { data } = useReadQuery(queryRef);
203
513
  *
514
+ * return <div>{data.greeting.message}</div>;
515
+ * }
516
+ * ```
517
+ *
518
+ * @param query - A GraphQL query document parsed into an AST by `gql`.
519
+ * @param options - Options to control how the query is executed.
520
+ * @returns A tuple in the form of `[loadQuery, queryRef, handlers]`
204
521
  */
205
522
  interface Modern {
206
523
  /**
524
+ * A hook for imperatively loading a query, such as responding to a user
525
+ * interaction.
526
+ *
527
+ * > Refer to the [Suspense - Fetching in response to user interaction](https://www.apollographql.com/docs/react/data/suspense#fetching-in-response-to-user-interaction) section for a more in-depth overview of `useLoadableQuery`.
528
+ *
529
+ * @example
530
+ *
531
+ * ```jsx
532
+ * import { gql, useLoadableQuery } from "@apollo/client";
533
+ *
534
+ * const GET_GREETING = gql`
535
+ * query GetGreeting($language: String!) {
536
+ * greeting(language: $language) {
537
+ * message
538
+ * }
539
+ * }
540
+ * `;
541
+ *
542
+ * function App() {
543
+ * const [loadGreeting, queryRef] = useLoadableQuery(GET_GREETING);
544
+ *
545
+ * return (
546
+ * <>
547
+ * <button onClick={() => loadGreeting({ language: "english" })}>
548
+ * Load greeting
549
+ * </button>
550
+ * <Suspense fallback={<div>Loading...</div>}>
551
+ * {queryRef && <Hello queryRef={queryRef} />}
552
+ * </Suspense>
553
+ * </>
554
+ * );
555
+ * }
207
556
  *
557
+ * function Hello({ queryRef }) {
558
+ * const { data } = useReadQuery(queryRef);
559
+ *
560
+ * return <div>{data.greeting.message}</div>;
561
+ * }
562
+ * ```
563
+ *
564
+ * @param query - A GraphQL query document parsed into an AST by `gql`.
565
+ * @param options - Options to control how the query is executed.
566
+ * @returns A tuple in the form of `[loadQuery, queryRef, handlers]`
208
567
  */
209
568
  <TData, TVariables extends OperationVariables, TOptions extends never>(query: DocumentNode | TypedDocumentNode<TData, TVariables>): useLoadableQuery.ResultForOptions<TData, TVariables, Record<string, never>>;
210
569
  /**
570
+ * A hook for imperatively loading a query, such as responding to a user
571
+ * interaction.
572
+ *
573
+ * > Refer to the [Suspense - Fetching in response to user interaction](https://www.apollographql.com/docs/react/data/suspense#fetching-in-response-to-user-interaction) section for a more in-depth overview of `useLoadableQuery`.
574
+ *
575
+ * @example
576
+ *
577
+ * ```jsx
578
+ * import { gql, useLoadableQuery } from "@apollo/client";
579
+ *
580
+ * const GET_GREETING = gql`
581
+ * query GetGreeting($language: String!) {
582
+ * greeting(language: $language) {
583
+ * message
584
+ * }
585
+ * }
586
+ * `;
211
587
  *
588
+ * function App() {
589
+ * const [loadGreeting, queryRef] = useLoadableQuery(GET_GREETING);
590
+ *
591
+ * return (
592
+ * <>
593
+ * <button onClick={() => loadGreeting({ language: "english" })}>
594
+ * Load greeting
595
+ * </button>
596
+ * <Suspense fallback={<div>Loading...</div>}>
597
+ * {queryRef && <Hello queryRef={queryRef} />}
598
+ * </Suspense>
599
+ * </>
600
+ * );
601
+ * }
602
+ *
603
+ * function Hello({ queryRef }) {
604
+ * const { data } = useReadQuery(queryRef);
605
+ *
606
+ * return <div>{data.greeting.message}</div>;
607
+ * }
608
+ * ```
609
+ *
610
+ * @param query - A GraphQL query document parsed into an AST by `gql`.
611
+ * @param options - Options to control how the query is executed.
612
+ * @returns A tuple in the form of `[loadQuery, queryRef, handlers]`
212
613
  */
213
614
  <TData, TVariables extends OperationVariables, TOptions extends useLoadableQuery.Options>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: TOptions): useLoadableQuery.ResultForOptions<TData, TVariables, TOptions>;
214
615
  }
215
616
  type Evaluated = SignatureStyle extends "classic" ? Classic : Modern;
216
617
  }
217
618
  /**
619
+ * A hook for imperatively loading a query, such as responding to a user
620
+ * interaction.
621
+ *
622
+ * > Refer to the [Suspense - Fetching in response to user interaction](https://www.apollographql.com/docs/react/data/suspense#fetching-in-response-to-user-interaction) section for a more in-depth overview of `useLoadableQuery`.
623
+ *
624
+ * @example
625
+ *
626
+ * ```jsx
627
+ * import { gql, useLoadableQuery } from "@apollo/client";
628
+ *
629
+ * const GET_GREETING = gql`
630
+ * query GetGreeting($language: String!) {
631
+ * greeting(language: $language) {
632
+ * message
633
+ * }
634
+ * }
635
+ * `;
636
+ *
637
+ * function App() {
638
+ * const [loadGreeting, queryRef] = useLoadableQuery(GET_GREETING);
639
+ *
640
+ * return (
641
+ * <>
642
+ * <button onClick={() => loadGreeting({ language: "english" })}>
643
+ * Load greeting
644
+ * </button>
645
+ * <Suspense fallback={<div>Loading...</div>}>
646
+ * {queryRef && <Hello queryRef={queryRef} />}
647
+ * </Suspense>
648
+ * </>
649
+ * );
650
+ * }
651
+ *
652
+ * function Hello({ queryRef }) {
653
+ * const { data } = useReadQuery(queryRef);
654
+ *
655
+ * return <div>{data.greeting.message}</div>;
656
+ * }
657
+ * ```
218
658
  *
659
+ * @param query - A GraphQL query document parsed into an AST by `gql`.
660
+ * @param options - Options to control how the query is executed.
661
+ * @returns A tuple in the form of `[loadQuery, queryRef, handlers]`
219
662
  */
220
663
  interface Signature extends Signatures.Evaluated {
221
664
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useMutation = useMutation;
3
+ exports.useMutation = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const equality_1 = require("@wry/equality");
6
6
  const React = tslib_1.__importStar(require("react"));
@@ -8,52 +8,9 @@ const internal_1 = require("@apollo/client/utilities/internal");
8
8
  const useIsomorphicLayoutEffect_js_1 = require("./internal/useIsomorphicLayoutEffect.cjs");
9
9
  const useApolloClient_js_1 = require("./useApolloClient.cjs");
10
10
  /**
11
- * > Refer to the [Mutations](https://www.apollographql.com/docs/react/data/mutations/) section for a more in-depth overview of `useMutation`.
12
- *
13
- * @example
14
- *
15
- * ```jsx
16
- * import { gql, useMutation } from "@apollo/client";
17
- *
18
- * const ADD_TODO = gql`
19
- * mutation AddTodo($type: String!) {
20
- * addTodo(type: $type) {
21
- * id
22
- * type
23
- * }
24
- * }
25
- * `;
26
- *
27
- * function AddTodo() {
28
- * let input;
29
- * const [addTodo, { data }] = useMutation(ADD_TODO);
30
- *
31
- * return (
32
- * <div>
33
- * <form
34
- * onSubmit={(e) => {
35
- * e.preventDefault();
36
- * addTodo({ variables: { type: input.value } });
37
- * input.value = "";
38
- * }}
39
- * >
40
- * <input
41
- * ref={(node) => {
42
- * input = node;
43
- * }}
44
- * />
45
- * <button type="submit">Add Todo</button>
46
- * </form>
47
- * </div>
48
- * );
49
- * }
50
- * ```
51
- *
52
- * @param mutation - A GraphQL mutation document parsed into an AST by `gql`.
53
- * @param options - Options to control how the mutation is executed.
54
- * @returns A tuple in the form of `[mutate, result]`
55
- */
56
- function useMutation(mutation, options) {
11
+ *
12
+ */
13
+ exports.useMutation = function useMutation(mutation, options) {
57
14
  const client = (0, useApolloClient_js_1.useApolloClient)(options?.client);
58
15
  const [result, setResult] = React.useState(() => createInitialResult(client));
59
16
  const ref = React.useRef({
@@ -150,7 +107,7 @@ function useMutation(mutation, options) {
150
107
  };
151
108
  }, []);
152
109
  return [execute, { reset, ...result }];
153
- }
110
+ };
154
111
  function createInitialResult(client) {
155
112
  return {
156
113
  data: undefined,