@apollo/client 4.2.0-alpha.2 → 4.2.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 (147) hide show
  1. package/CHANGELOG.md +240 -0
  2. package/__cjs/cache/core/cache.cjs +1 -1
  3. package/__cjs/cache/inmemory/entityStore.cjs +3 -3
  4. package/__cjs/cache/inmemory/entityStore.cjs.map +1 -1
  5. package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
  6. package/__cjs/cache/inmemory/policies.cjs +4 -4
  7. package/__cjs/cache/inmemory/readFromStore.cjs +2 -2
  8. package/__cjs/cache/inmemory/writeToStore.cjs +4 -4
  9. package/__cjs/core/ApolloClient.cjs +52 -20
  10. package/__cjs/core/ApolloClient.cjs.map +1 -1
  11. package/__cjs/core/ApolloClient.d.cts +159 -22
  12. package/__cjs/core/ObservableQuery.cjs +7 -7
  13. package/__cjs/core/ObservableQuery.cjs.map +1 -1
  14. package/__cjs/core/ObservableQuery.d.cts +20 -1
  15. package/__cjs/core/QueryManager.cjs +12 -12
  16. package/__cjs/core/QueryManager.cjs.map +1 -1
  17. package/__cjs/core/RefetchEventManager.cjs +134 -0
  18. package/__cjs/core/RefetchEventManager.cjs.map +1 -0
  19. package/__cjs/core/RefetchEventManager.d.cts +130 -0
  20. package/__cjs/core/index.cjs +7 -1
  21. package/__cjs/core/index.cjs.map +1 -1
  22. package/__cjs/core/index.d.cts +4 -1
  23. package/__cjs/core/refetchSources/onlineSource.cjs +10 -0
  24. package/__cjs/core/refetchSources/onlineSource.cjs.map +1 -0
  25. package/__cjs/core/refetchSources/onlineSource.d.cts +3 -0
  26. package/__cjs/core/refetchSources/windowFocusSource.cjs +13 -0
  27. package/__cjs/core/refetchSources/windowFocusSource.cjs.map +1 -0
  28. package/__cjs/core/refetchSources/windowFocusSource.d.cts +3 -0
  29. package/__cjs/core/types.d.cts +20 -0
  30. package/__cjs/invariantErrorCodes.cjs +69 -44
  31. package/__cjs/link/ws/index.cjs +9 -1
  32. package/__cjs/link/ws/index.cjs.map +1 -1
  33. package/__cjs/link/ws/index.d.cts +1 -1
  34. package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
  35. package/__cjs/react/hooks/useBackgroundQuery.d.cts +1486 -66
  36. package/__cjs/react/hooks/useLazyQuery.cjs +1 -0
  37. package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
  38. package/__cjs/react/hooks/useLazyQuery.d.cts +366 -40
  39. package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
  40. package/__cjs/react/hooks/useLoadableQuery.d.cts +512 -50
  41. package/__cjs/react/hooks/useMutation.cjs +5 -48
  42. package/__cjs/react/hooks/useMutation.cjs.map +1 -1
  43. package/__cjs/react/hooks/useMutation.d.cts +239 -130
  44. package/__cjs/react/hooks/useQuery.cjs.map +1 -1
  45. package/__cjs/react/hooks/useQuery.d.cts +590 -41
  46. package/__cjs/react/hooks/useSubscription.cjs +1 -1
  47. package/__cjs/react/hooks/useSubscription.cjs.map +1 -1
  48. package/__cjs/react/hooks/useSubscription.d.cts +2 -2
  49. package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
  50. package/__cjs/react/hooks/useSuspenseQuery.d.cts +754 -46
  51. package/__cjs/react/internal/cache/QueryReference.cjs +1 -0
  52. package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
  53. package/__cjs/react/internal/cache/QueryReference.d.cts +1 -1
  54. package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
  55. package/__cjs/react/query-preloader/createQueryPreloader.d.cts +20 -1
  56. package/__cjs/react/types/types.documentation.d.cts +19 -0
  57. package/__cjs/version.cjs +1 -1
  58. package/cache/core/cache.js +1 -1
  59. package/cache/inmemory/entityStore.js +3 -3
  60. package/cache/inmemory/entityStore.js.map +1 -1
  61. package/cache/inmemory/key-extractor.js +1 -1
  62. package/cache/inmemory/policies.js +4 -4
  63. package/cache/inmemory/readFromStore.js +2 -2
  64. package/cache/inmemory/writeToStore.js +4 -4
  65. package/core/ApolloClient.d.ts +159 -22
  66. package/core/ApolloClient.js +53 -21
  67. package/core/ApolloClient.js.map +1 -1
  68. package/core/ObservableQuery.d.ts +20 -1
  69. package/core/ObservableQuery.js +7 -7
  70. package/core/ObservableQuery.js.map +1 -1
  71. package/core/QueryManager.js +12 -12
  72. package/core/QueryManager.js.map +1 -1
  73. package/core/RefetchEventManager.d.ts +130 -0
  74. package/core/RefetchEventManager.js +126 -0
  75. package/core/RefetchEventManager.js.map +1 -0
  76. package/core/index.d.ts +4 -1
  77. package/core/index.js +3 -0
  78. package/core/index.js.map +1 -1
  79. package/core/refetchSources/onlineSource.d.ts +3 -0
  80. package/core/refetchSources/onlineSource.js +6 -0
  81. package/core/refetchSources/onlineSource.js.map +1 -0
  82. package/core/refetchSources/windowFocusSource.d.ts +3 -0
  83. package/core/refetchSources/windowFocusSource.js +9 -0
  84. package/core/refetchSources/windowFocusSource.js.map +1 -0
  85. package/core/types.d.ts +20 -0
  86. package/core/types.js.map +1 -1
  87. package/invariantErrorCodes.js +69 -44
  88. package/link/ws/index.d.ts +1 -1
  89. package/link/ws/index.js +9 -1
  90. package/link/ws/index.js.map +1 -1
  91. package/package.json +3 -7
  92. package/react/hooks/useBackgroundQuery.d.ts +1486 -66
  93. package/react/hooks/useBackgroundQuery.js.map +1 -1
  94. package/react/hooks/useLazyQuery.d.ts +366 -40
  95. package/react/hooks/useLazyQuery.js +1 -0
  96. package/react/hooks/useLazyQuery.js.map +1 -1
  97. package/react/hooks/useLoadableQuery.d.ts +512 -50
  98. package/react/hooks/useLoadableQuery.js.map +1 -1
  99. package/react/hooks/useMutation.d.ts +239 -130
  100. package/react/hooks/useMutation.js +5 -48
  101. package/react/hooks/useMutation.js.map +1 -1
  102. package/react/hooks/useQuery.d.ts +590 -41
  103. package/react/hooks/useQuery.js.map +1 -1
  104. package/react/hooks/useSubscription.d.ts +2 -2
  105. package/react/hooks/useSubscription.js +1 -1
  106. package/react/hooks/useSubscription.js.map +1 -1
  107. package/react/hooks/useSuspenseQuery.d.ts +754 -46
  108. package/react/hooks/useSuspenseQuery.js.map +1 -1
  109. package/react/hooks-compiled/useBackgroundQuery.d.ts +1486 -66
  110. package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
  111. package/react/hooks-compiled/useLazyQuery.d.ts +366 -40
  112. package/react/hooks-compiled/useLazyQuery.js +1 -0
  113. package/react/hooks-compiled/useLazyQuery.js.map +1 -1
  114. package/react/hooks-compiled/useLoadableQuery.d.ts +512 -50
  115. package/react/hooks-compiled/useLoadableQuery.js.map +1 -1
  116. package/react/hooks-compiled/useMutation.d.ts +239 -130
  117. package/react/hooks-compiled/useMutation.js +4 -47
  118. package/react/hooks-compiled/useMutation.js.map +1 -1
  119. package/react/hooks-compiled/useQuery.d.ts +590 -41
  120. package/react/hooks-compiled/useQuery.js.map +1 -1
  121. package/react/hooks-compiled/useSubscription.d.ts +2 -2
  122. package/react/hooks-compiled/useSubscription.js +1 -1
  123. package/react/hooks-compiled/useSubscription.js.map +1 -1
  124. package/react/hooks-compiled/useSuspenseQuery.d.ts +754 -46
  125. package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
  126. package/react/internal/cache/QueryReference.d.ts +1 -1
  127. package/react/internal/cache/QueryReference.js +1 -0
  128. package/react/internal/cache/QueryReference.js.map +1 -1
  129. package/react/query-preloader/createQueryPreloader.d.ts +20 -1
  130. package/react/query-preloader/createQueryPreloader.js.map +1 -1
  131. package/react/types/types.documentation.d.ts +19 -0
  132. package/react/types/types.documentation.js.map +1 -1
  133. package/skills/apollo-client/SKILL.md +168 -0
  134. package/skills/apollo-client/references/caching.md +560 -0
  135. package/skills/apollo-client/references/error-handling.md +350 -0
  136. package/skills/apollo-client/references/fragments.md +804 -0
  137. package/skills/apollo-client/references/integration-client.md +336 -0
  138. package/skills/apollo-client/references/integration-nextjs.md +325 -0
  139. package/skills/apollo-client/references/integration-react-router.md +256 -0
  140. package/skills/apollo-client/references/integration-tanstack-start.md +378 -0
  141. package/skills/apollo-client/references/mutations.md +549 -0
  142. package/skills/apollo-client/references/queries.md +416 -0
  143. package/skills/apollo-client/references/state-management.md +428 -0
  144. package/skills/apollo-client/references/suspense-hooks.md +773 -0
  145. package/skills/apollo-client/references/troubleshooting.md +487 -0
  146. package/skills/apollo-client/references/typescript-codegen.md +133 -0
  147. package/version.js +1 -1
@@ -1,6 +1,6 @@
1
1
  import type { TypedDocumentNode } from "@graphql-typed-document-node/core";
2
2
  import type { DocumentNode } from "graphql";
3
- import type { ApolloClient, DataState, DefaultContext, ErrorLike, ErrorPolicy, GetDataState, InternalTypes, MaybeMasked, ObservableQuery, OperationVariables, RefetchWritePolicy, SubscribeToMoreFunction, UpdateQueryMapFn, WatchQueryFetchPolicy } from "@apollo/client";
3
+ import type { ApolloClient, DataState, DefaultContext, ErrorLike, ErrorPolicy, GetDataState, InternalTypes, MaybeMasked, ObservableQuery, OperationVariables, RefetchOn, RefetchWritePolicy, SubscribeToMoreFunction, UpdateQueryMapFn, WatchQueryFetchPolicy } from "@apollo/client";
4
4
  import { NetworkStatus } from "@apollo/client";
5
5
  import type { DocumentationTypes as UtilityDocumentationTypes, NoInfer, OptionWithFallback, SignatureStyle, VariablesOption } from "@apollo/client/utilities/internal";
6
6
  export declare namespace useLazyQuery {
@@ -82,6 +82,25 @@ export declare namespace useLazyQuery {
82
82
  * @docGroup 1. Operation options
83
83
  */
84
84
  client?: ApolloClient;
85
+ /**
86
+ * Determines whether events trigger refetches for the query. Provide an
87
+ * object mapping each refetch event to `true` (enable), `false` (disable)
88
+ * or a callback function that returns `true`/`false` to control individual
89
+ * events. Provide `false` to disable all automatic refetch events for this
90
+ * query. Provide `true` to enable all automatic refetch events for this query.
91
+ * Provide a callback function to perform additional logic to determine
92
+ * whether to enable or disable a refetch for a query.
93
+ *
94
+ * `@remarks`
95
+ * `refetchOn` inherits from `defaultOptions.watchQuery.refetchOn`. If
96
+ * `defaultOptions.watchQuery.refetchOn` is not set, all refetch events are
97
+ * enabled by default.
98
+ *
99
+ * This option only has an effect when the client is configured with a
100
+ * `refetchEventManager`.
101
+ * @docGroup 1. Operation options
102
+ */
103
+ refetchOn?: RefetchOn.Option;
85
104
  }
86
105
  namespace DocumentationTypes {
87
106
  namespace useLazyQuery {
@@ -286,84 +305,359 @@ export declare namespace useLazyQuery {
286
305
  }
287
306
  type ResultForOptions<TData, TVariables extends OperationVariables, TOptions extends Record<string, never> | Options<TData, TVariables>> = ResultTuple<TData, TVariables, "complete" | "streaming" | "empty" | (OptionWithFallback<TOptions, DefaultOptions, "returnPartialData"> extends false ? never : "partial")>;
288
307
  namespace DocumentationTypes {
289
- /**
290
- * A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
291
- *
292
- * > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
293
- *
294
- * @example
295
- *
296
- * ```jsx
297
- * import { gql } from "@apollo/client";
298
- * import { useLazyQuery } from "@apollo/client/react";
299
- *
300
- * const GET_GREETING = gql`
301
- * query GetGreeting($language: String!) {
302
- * greeting(language: $language) {
303
- * message
304
- * }
305
- * }
306
- * `;
307
- *
308
- * function Hello() {
309
- * const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
310
- * variables: { language: "english" },
311
- * });
312
- * if (called && loading) return <p>Loading ...</p>;
313
- * if (!called) {
314
- * return <button onClick={() => loadGreeting()}>Load greeting</button>;
315
- * }
316
- * return <h1>Hello {data.greeting.message}!</h1>;
317
- * }
318
- * ```
319
- *
320
- * @param query - A GraphQL query document parsed into an AST by `gql`.
321
- * @param options - Default options to control how the query is executed.
322
- * @returns A tuple in the form of `[execute, result]`
323
- */
324
308
  interface useLazyQuery {
309
+ /**
310
+ * A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
311
+ *
312
+ * > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
313
+ *
314
+ * @example
315
+ *
316
+ * ```jsx
317
+ * import { gql } from "@apollo/client";
318
+ * import { useLazyQuery } from "@apollo/client/react";
319
+ *
320
+ * const GET_GREETING = gql`
321
+ * query GetGreeting($language: String!) {
322
+ * greeting(language: $language) {
323
+ * message
324
+ * }
325
+ * }
326
+ * `;
327
+ *
328
+ * function Hello() {
329
+ * const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
330
+ * variables: { language: "english" },
331
+ * });
332
+ * if (called && loading) return <p>Loading ...</p>;
333
+ * if (!called) {
334
+ * return <button onClick={() => loadGreeting()}>Load greeting</button>;
335
+ * }
336
+ * return <h1>Hello {data.greeting.message}!</h1>;
337
+ * }
338
+ * ```
339
+ *
340
+ * @param query - A GraphQL query document parsed into an AST by `gql`.
341
+ * @param options - Default options to control how the query is executed.
342
+ * @returns A tuple in the form of `[execute, result]`
343
+ */
325
344
  <TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useLazyQuery.Options<TData, TVariables>): useLazyQuery.ResultTuple<TData, TVariables>;
326
345
  }
327
- /**
328
- * @deprecated Avoid manually specifying generics on `useLazyQuery`.
329
- * Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
330
- */
331
346
  interface useLazyQuery_Deprecated {
347
+ /**
348
+ * @deprecated Avoid manually specifying generics on `useLazyQuery`.
349
+ * Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
350
+ *
351
+ *
352
+ * A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
353
+ *
354
+ * > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
355
+ *
356
+ * @example
357
+ *
358
+ * ```jsx
359
+ * import { gql } from "@apollo/client";
360
+ * import { useLazyQuery } from "@apollo/client/react";
361
+ *
362
+ * const GET_GREETING = gql`
363
+ * query GetGreeting($language: String!) {
364
+ * greeting(language: $language) {
365
+ * message
366
+ * }
367
+ * }
368
+ * `;
369
+ *
370
+ * function Hello() {
371
+ * const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
372
+ * variables: { language: "english" },
373
+ * });
374
+ * if (called && loading) return <p>Loading ...</p>;
375
+ * if (!called) {
376
+ * return <button onClick={() => loadGreeting()}>Load greeting</button>;
377
+ * }
378
+ * return <h1>Hello {data.greeting.message}!</h1>;
379
+ * }
380
+ * ```
381
+ *
382
+ * @param query - A GraphQL query document parsed into an AST by `gql`.
383
+ * @param options - Default options to control how the query is executed.
384
+ * @returns A tuple in the form of `[execute, result]`
385
+ */
332
386
  <TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useLazyQuery.Options<TData, TVariables>): useLazyQuery.ResultTuple<TData, TVariables>;
333
387
  }
334
388
  }
335
389
  namespace Signatures {
336
390
  /**
391
+ * @deprecated Avoid manually specifying generics on `useLazyQuery`.
392
+ * Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
393
+ *
337
394
  *
395
+ * A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
396
+ *
397
+ * > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
398
+ *
399
+ * @example
400
+ *
401
+ * ```jsx
402
+ * import { gql } from "@apollo/client";
403
+ * import { useLazyQuery } from "@apollo/client/react";
404
+ *
405
+ * const GET_GREETING = gql`
406
+ * query GetGreeting($language: String!) {
407
+ * greeting(language: $language) {
408
+ * message
409
+ * }
410
+ * }
411
+ * `;
412
+ *
413
+ * function Hello() {
414
+ * const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
415
+ * variables: { language: "english" },
416
+ * });
417
+ * if (called && loading) return <p>Loading ...</p>;
418
+ * if (!called) {
419
+ * return <button onClick={() => loadGreeting()}>Load greeting</button>;
420
+ * }
421
+ * return <h1>Hello {data.greeting.message}!</h1>;
422
+ * }
423
+ * ```
424
+ *
425
+ * @param query - A GraphQL query document parsed into an AST by `gql`.
426
+ * @param options - Default options to control how the query is executed.
427
+ * @returns A tuple in the form of `[execute, result]`
338
428
  */
339
429
  interface Classic {
340
430
  /**
431
+ * @deprecated Avoid manually specifying generics on `useLazyQuery`.
432
+ * Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
433
+ *
434
+ *
435
+ * A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
436
+ *
437
+ * > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
341
438
  *
439
+ * @example
440
+ *
441
+ * ```jsx
442
+ * import { gql } from "@apollo/client";
443
+ * import { useLazyQuery } from "@apollo/client/react";
444
+ *
445
+ * const GET_GREETING = gql`
446
+ * query GetGreeting($language: String!) {
447
+ * greeting(language: $language) {
448
+ * message
449
+ * }
450
+ * }
451
+ * `;
452
+ *
453
+ * function Hello() {
454
+ * const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
455
+ * variables: { language: "english" },
456
+ * });
457
+ * if (called && loading) return <p>Loading ...</p>;
458
+ * if (!called) {
459
+ * return <button onClick={() => loadGreeting()}>Load greeting</button>;
460
+ * }
461
+ * return <h1>Hello {data.greeting.message}!</h1>;
462
+ * }
463
+ * ```
464
+ *
465
+ * @param query - A GraphQL query document parsed into an AST by `gql`.
466
+ * @param options - Default options to control how the query is executed.
467
+ * @returns A tuple in the form of `[execute, result]`
342
468
  */
343
469
  <TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useLazyQuery.Options<NoInfer<TData>, NoInfer<TVariables>> & {
344
470
  returnPartialData: true;
345
471
  }): useLazyQuery.ResultTuple<TData, TVariables, "empty" | "complete" | "streaming" | "partial">;
346
472
  /**
473
+ * @deprecated Avoid manually specifying generics on `useLazyQuery`.
474
+ * Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
475
+ *
476
+ *
477
+ * A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
478
+ *
479
+ * > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
480
+ *
481
+ * @example
482
+ *
483
+ * ```jsx
484
+ * import { gql } from "@apollo/client";
485
+ * import { useLazyQuery } from "@apollo/client/react";
486
+ *
487
+ * const GET_GREETING = gql`
488
+ * query GetGreeting($language: String!) {
489
+ * greeting(language: $language) {
490
+ * message
491
+ * }
492
+ * }
493
+ * `;
347
494
  *
495
+ * function Hello() {
496
+ * const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
497
+ * variables: { language: "english" },
498
+ * });
499
+ * if (called && loading) return <p>Loading ...</p>;
500
+ * if (!called) {
501
+ * return <button onClick={() => loadGreeting()}>Load greeting</button>;
502
+ * }
503
+ * return <h1>Hello {data.greeting.message}!</h1>;
504
+ * }
505
+ * ```
506
+ *
507
+ * @param query - A GraphQL query document parsed into an AST by `gql`.
508
+ * @param options - Default options to control how the query is executed.
509
+ * @returns A tuple in the form of `[execute, result]`
348
510
  */
349
511
  <TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useLazyQuery.Options<NoInfer<TData>, NoInfer<TVariables>> & {
350
512
  returnPartialData: boolean;
351
513
  }): useLazyQuery.ResultTuple<TData, TVariables, "empty" | "complete" | "streaming" | "partial">;
352
514
  /**
515
+ * @deprecated Avoid manually specifying generics on `useLazyQuery`.
516
+ * Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
517
+ *
518
+ *
519
+ * A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
520
+ *
521
+ * > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
522
+ *
523
+ * @example
353
524
  *
525
+ * ```jsx
526
+ * import { gql } from "@apollo/client";
527
+ * import { useLazyQuery } from "@apollo/client/react";
528
+ *
529
+ * const GET_GREETING = gql`
530
+ * query GetGreeting($language: String!) {
531
+ * greeting(language: $language) {
532
+ * message
533
+ * }
534
+ * }
535
+ * `;
536
+ *
537
+ * function Hello() {
538
+ * const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
539
+ * variables: { language: "english" },
540
+ * });
541
+ * if (called && loading) return <p>Loading ...</p>;
542
+ * if (!called) {
543
+ * return <button onClick={() => loadGreeting()}>Load greeting</button>;
544
+ * }
545
+ * return <h1>Hello {data.greeting.message}!</h1>;
546
+ * }
547
+ * ```
548
+ *
549
+ * @param query - A GraphQL query document parsed into an AST by `gql`.
550
+ * @param options - Default options to control how the query is executed.
551
+ * @returns A tuple in the form of `[execute, result]`
354
552
  */
355
553
  <TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: useLazyQuery.Options<NoInfer<TData>, NoInfer<TVariables>>): useLazyQuery.ResultTuple<TData, TVariables, "empty" | "complete" | "streaming">;
356
554
  }
357
555
  /**
556
+ * A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
557
+ *
558
+ * > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
358
559
  *
560
+ * @example
561
+ *
562
+ * ```jsx
563
+ * import { gql } from "@apollo/client";
564
+ * import { useLazyQuery } from "@apollo/client/react";
565
+ *
566
+ * const GET_GREETING = gql`
567
+ * query GetGreeting($language: String!) {
568
+ * greeting(language: $language) {
569
+ * message
570
+ * }
571
+ * }
572
+ * `;
573
+ *
574
+ * function Hello() {
575
+ * const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
576
+ * variables: { language: "english" },
577
+ * });
578
+ * if (called && loading) return <p>Loading ...</p>;
579
+ * if (!called) {
580
+ * return <button onClick={() => loadGreeting()}>Load greeting</button>;
581
+ * }
582
+ * return <h1>Hello {data.greeting.message}!</h1>;
583
+ * }
584
+ * ```
585
+ *
586
+ * @param query - A GraphQL query document parsed into an AST by `gql`.
587
+ * @param options - Default options to control how the query is executed.
588
+ * @returns A tuple in the form of `[execute, result]`
359
589
  */
360
590
  interface Modern {
361
591
  /**
592
+ * A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
593
+ *
594
+ * > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
362
595
  *
596
+ * @example
597
+ *
598
+ * ```jsx
599
+ * import { gql } from "@apollo/client";
600
+ * import { useLazyQuery } from "@apollo/client/react";
601
+ *
602
+ * const GET_GREETING = gql`
603
+ * query GetGreeting($language: String!) {
604
+ * greeting(language: $language) {
605
+ * message
606
+ * }
607
+ * }
608
+ * `;
609
+ *
610
+ * function Hello() {
611
+ * const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
612
+ * variables: { language: "english" },
613
+ * });
614
+ * if (called && loading) return <p>Loading ...</p>;
615
+ * if (!called) {
616
+ * return <button onClick={() => loadGreeting()}>Load greeting</button>;
617
+ * }
618
+ * return <h1>Hello {data.greeting.message}!</h1>;
619
+ * }
620
+ * ```
621
+ *
622
+ * @param query - A GraphQL query document parsed into an AST by `gql`.
623
+ * @param options - Default options to control how the query is executed.
624
+ * @returns A tuple in the form of `[execute, result]`
363
625
  */
364
626
  <TData, TVariables extends OperationVariables, TOptions extends never>(query: DocumentNode | TypedDocumentNode<TData, TVariables>): useLazyQuery.ResultForOptions<TData, TVariables, Record<string, never>>;
365
627
  /**
628
+ * A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
629
+ *
630
+ * > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
366
631
  *
632
+ * @example
633
+ *
634
+ * ```jsx
635
+ * import { gql } from "@apollo/client";
636
+ * import { useLazyQuery } from "@apollo/client/react";
637
+ *
638
+ * const GET_GREETING = gql`
639
+ * query GetGreeting($language: String!) {
640
+ * greeting(language: $language) {
641
+ * message
642
+ * }
643
+ * }
644
+ * `;
645
+ *
646
+ * function Hello() {
647
+ * const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
648
+ * variables: { language: "english" },
649
+ * });
650
+ * if (called && loading) return <p>Loading ...</p>;
651
+ * if (!called) {
652
+ * return <button onClick={() => loadGreeting()}>Load greeting</button>;
653
+ * }
654
+ * return <h1>Hello {data.greeting.message}!</h1>;
655
+ * }
656
+ * ```
657
+ *
658
+ * @param query - A GraphQL query document parsed into an AST by `gql`.
659
+ * @param options - Default options to control how the query is executed.
660
+ * @returns A tuple in the form of `[execute, result]`
367
661
  */
368
662
  <TData, TVariables extends OperationVariables, TOptions extends useLazyQuery.Options<NoInfer<TData>, NoInfer<TVariables>> & {
369
663
  variables?: {
@@ -374,7 +668,39 @@ export declare namespace useLazyQuery {
374
668
  type Evaluated = SignatureStyle extends "classic" ? Classic : Modern;
375
669
  }
376
670
  /**
671
+ * A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
672
+ *
673
+ * > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
674
+ *
675
+ * @example
676
+ *
677
+ * ```jsx
678
+ * import { gql } from "@apollo/client";
679
+ * import { useLazyQuery } from "@apollo/client/react";
680
+ *
681
+ * const GET_GREETING = gql`
682
+ * query GetGreeting($language: String!) {
683
+ * greeting(language: $language) {
684
+ * message
685
+ * }
686
+ * }
687
+ * `;
688
+ *
689
+ * function Hello() {
690
+ * const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
691
+ * variables: { language: "english" },
692
+ * });
693
+ * if (called && loading) return <p>Loading ...</p>;
694
+ * if (!called) {
695
+ * return <button onClick={() => loadGreeting()}>Load greeting</button>;
696
+ * }
697
+ * return <h1>Hello {data.greeting.message}!</h1>;
698
+ * }
699
+ * ```
377
700
  *
701
+ * @param query - A GraphQL query document parsed into an AST by `gql`.
702
+ * @param options - Default options to control how the query is executed.
703
+ * @returns A tuple in the form of `[execute, result]`
378
704
  */
379
705
  interface Signature extends Signatures.Evaluated {
380
706
  }
@@ -76,6 +76,7 @@ export const useLazyQuery = function useLazyQuery(query, options) {
76
76
  const updatedOptions = {
77
77
  query,
78
78
  errorPolicy: stableOptions?.errorPolicy,
79
+ refetchOn: stableOptions?.refetchOn,
79
80
  refetchWritePolicy: stableOptions?.refetchWritePolicy,
80
81
  returnPartialData: stableOptions?.returnPartialData,
81
82
  notifyOnNetworkStatusChange: stableOptions?.notifyOnNetworkStatusChange,