@apollo/client 4.2.0-alpha.3 → 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 (109) hide show
  1. package/CHANGELOG.md +179 -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 +43 -11
  10. package/__cjs/core/ApolloClient.cjs.map +1 -1
  11. package/__cjs/core/ApolloClient.d.cts +28 -1
  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/react/hooks/useBackgroundQuery.cjs.map +1 -1
  32. package/__cjs/react/hooks/useBackgroundQuery.d.cts +20 -1
  33. package/__cjs/react/hooks/useLazyQuery.cjs +1 -0
  34. package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
  35. package/__cjs/react/hooks/useLazyQuery.d.cts +20 -1
  36. package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
  37. package/__cjs/react/hooks/useLoadableQuery.d.cts +20 -1
  38. package/__cjs/react/hooks/useQuery.cjs.map +1 -1
  39. package/__cjs/react/hooks/useQuery.d.cts +20 -1
  40. package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
  41. package/__cjs/react/hooks/useSuspenseQuery.d.cts +20 -1
  42. package/__cjs/react/internal/cache/QueryReference.cjs +1 -0
  43. package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
  44. package/__cjs/react/internal/cache/QueryReference.d.cts +1 -1
  45. package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
  46. package/__cjs/react/query-preloader/createQueryPreloader.d.cts +20 -1
  47. package/__cjs/react/types/types.documentation.d.cts +19 -0
  48. package/__cjs/version.cjs +1 -1
  49. package/cache/core/cache.js +1 -1
  50. package/cache/inmemory/entityStore.js +3 -3
  51. package/cache/inmemory/entityStore.js.map +1 -1
  52. package/cache/inmemory/key-extractor.js +1 -1
  53. package/cache/inmemory/policies.js +4 -4
  54. package/cache/inmemory/readFromStore.js +2 -2
  55. package/cache/inmemory/writeToStore.js +4 -4
  56. package/core/ApolloClient.d.ts +28 -1
  57. package/core/ApolloClient.js +44 -12
  58. package/core/ApolloClient.js.map +1 -1
  59. package/core/ObservableQuery.d.ts +20 -1
  60. package/core/ObservableQuery.js +7 -7
  61. package/core/ObservableQuery.js.map +1 -1
  62. package/core/QueryManager.js +12 -12
  63. package/core/QueryManager.js.map +1 -1
  64. package/core/RefetchEventManager.d.ts +130 -0
  65. package/core/RefetchEventManager.js +126 -0
  66. package/core/RefetchEventManager.js.map +1 -0
  67. package/core/index.d.ts +4 -1
  68. package/core/index.js +3 -0
  69. package/core/index.js.map +1 -1
  70. package/core/refetchSources/onlineSource.d.ts +3 -0
  71. package/core/refetchSources/onlineSource.js +6 -0
  72. package/core/refetchSources/onlineSource.js.map +1 -0
  73. package/core/refetchSources/windowFocusSource.d.ts +3 -0
  74. package/core/refetchSources/windowFocusSource.js +9 -0
  75. package/core/refetchSources/windowFocusSource.js.map +1 -0
  76. package/core/types.d.ts +20 -0
  77. package/core/types.js.map +1 -1
  78. package/invariantErrorCodes.js +69 -44
  79. package/package.json +1 -1
  80. package/react/hooks/useBackgroundQuery.d.ts +20 -1
  81. package/react/hooks/useBackgroundQuery.js.map +1 -1
  82. package/react/hooks/useLazyQuery.d.ts +20 -1
  83. package/react/hooks/useLazyQuery.js +1 -0
  84. package/react/hooks/useLazyQuery.js.map +1 -1
  85. package/react/hooks/useLoadableQuery.d.ts +20 -1
  86. package/react/hooks/useLoadableQuery.js.map +1 -1
  87. package/react/hooks/useQuery.d.ts +20 -1
  88. package/react/hooks/useQuery.js.map +1 -1
  89. package/react/hooks/useSuspenseQuery.d.ts +20 -1
  90. package/react/hooks/useSuspenseQuery.js.map +1 -1
  91. package/react/hooks-compiled/useBackgroundQuery.d.ts +20 -1
  92. package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
  93. package/react/hooks-compiled/useLazyQuery.d.ts +20 -1
  94. package/react/hooks-compiled/useLazyQuery.js +1 -0
  95. package/react/hooks-compiled/useLazyQuery.js.map +1 -1
  96. package/react/hooks-compiled/useLoadableQuery.d.ts +20 -1
  97. package/react/hooks-compiled/useLoadableQuery.js.map +1 -1
  98. package/react/hooks-compiled/useQuery.d.ts +20 -1
  99. package/react/hooks-compiled/useQuery.js.map +1 -1
  100. package/react/hooks-compiled/useSuspenseQuery.d.ts +20 -1
  101. package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
  102. package/react/internal/cache/QueryReference.d.ts +1 -1
  103. package/react/internal/cache/QueryReference.js +1 -0
  104. package/react/internal/cache/QueryReference.js.map +1 -1
  105. package/react/query-preloader/createQueryPreloader.d.ts +20 -1
  106. package/react/query-preloader/createQueryPreloader.js.map +1 -1
  107. package/react/types/types.documentation.d.ts +19 -0
  108. package/react/types/types.documentation.js.map +1 -1
  109. package/version.js +1 -1
@@ -363,7 +363,7 @@ const client = new ApolloClient({
363
363
  "For more information, please visit: https://go.apollo.dev/c/docs"
364
364
  },
365
365
 
366
- 70: {
366
+ 72: {
367
367
  file: "@apollo/client/core/ApolloClient.js",
368
368
  condition: "options.fetchPolicy !== \"cache-and-network\"",
369
369
 
@@ -373,7 +373,7 @@ const client = new ApolloClient({
373
373
  "using a different fetchPolicy, such as cache-first or network-only."
374
374
  },
375
375
 
376
- 71: {
376
+ 73: {
377
377
  file: "@apollo/client/core/ApolloClient.js",
378
378
  condition: "options.fetchPolicy !== \"standby\"",
379
379
 
@@ -382,7 +382,7 @@ const client = new ApolloClient({
382
382
  "as cache-first or network-only."
383
383
  },
384
384
 
385
- 72: {
385
+ 74: {
386
386
  file: "@apollo/client/core/ApolloClient.js",
387
387
  condition: "options.query",
388
388
 
@@ -390,164 +390,164 @@ const client = new ApolloClient({
390
390
  "in the query option."
391
391
  },
392
392
 
393
- 73: {
393
+ 75: {
394
394
  file: "@apollo/client/core/ApolloClient.js",
395
395
  condition: "options.query.kind === \"Document\"",
396
396
  message: 'You must wrap the query string in a "gql" tag.'
397
397
  },
398
398
 
399
- 74: {
399
+ 76: {
400
400
  file: "@apollo/client/core/ApolloClient.js",
401
401
  condition: "!options.returnPartialData",
402
402
  message: "returnPartialData option only supported on watchQuery."
403
403
  },
404
404
 
405
- 75: {
405
+ 77: {
406
406
  file: "@apollo/client/core/ApolloClient.js",
407
407
  condition: "!options.pollInterval",
408
408
  message: "pollInterval option only supported on watchQuery."
409
409
  },
410
410
 
411
- 76: {
411
+ 78: {
412
412
  file: "@apollo/client/core/ApolloClient.js",
413
413
  condition: "!options.notifyOnNetworkStatusChange",
414
414
  message: "notifyOnNetworkStatusChange option only supported on watchQuery."
415
415
  },
416
416
 
417
- 77: {
417
+ 79: {
418
418
  file: "@apollo/client/core/ApolloClient.js",
419
419
  condition: "optionsWithDefaults.mutation",
420
420
  message: "The `mutation` option is required. Please provide a GraphQL document in the `mutation` option."
421
421
  },
422
422
 
423
- 78: {
423
+ 80: {
424
424
  file: "@apollo/client/core/ApolloClient.js",
425
425
  condition: "optionsWithDefaults.fetchPolicy === \"network-only\" ||\n optionsWithDefaults.fetchPolicy === \"no-cache\"",
426
426
  message: "Mutations only support 'network-only' or 'no-cache' fetch policies. The default 'network-only' behavior automatically writes mutation results to the cache. Passing 'no-cache' skips the cache write."
427
427
  },
428
428
 
429
- 80: {
429
+ 82: {
430
430
  file: "@apollo/client/core/ObservableQuery.js",
431
431
  condition: "fetchPolicy === \"standby\"",
432
432
  message: "The `variablesUnknown` option can only be used together with a `standby` fetch policy."
433
433
  },
434
434
 
435
- 82: {
435
+ 84: {
436
436
  file: "@apollo/client/core/ObservableQuery.js",
437
437
  condition: "this.options.fetchPolicy !== \"cache-only\"",
438
438
  message: "Cannot execute `fetchMore` for 'cache-only' query '%s'. Please use a different fetch policy."
439
439
  },
440
440
 
441
- 83: {
441
+ 85: {
442
442
  file: "@apollo/client/core/ObservableQuery.js",
443
443
  condition: "updateQuery",
444
444
  message: "You must provide an `updateQuery` function when using `fetchMore` with a `no-cache` fetch policy."
445
445
  },
446
446
 
447
- 87: {
447
+ 89: {
448
448
  file: "@apollo/client/core/QueryManager.js",
449
449
  message: "QueryManager stopped while query was in flight"
450
450
  },
451
451
 
452
- 88: {
452
+ 90: {
453
453
  file: "@apollo/client/core/QueryManager.js",
454
454
  condition: "this.localState",
455
455
  message: "Mutation '%s' contains `@client` fields with variables provided by `@export` but local state has not been configured."
456
456
  },
457
457
 
458
- 89: {
458
+ 91: {
459
459
  file: "@apollo/client/core/QueryManager.js",
460
460
  message: "Store reset while query was in flight (not completed in link chain)"
461
461
  },
462
462
 
463
- 92: {
463
+ 94: {
464
464
  file: "@apollo/client/core/QueryManager.js",
465
465
  condition: "!this.getDocumentInfo(query).hasClientExports || this.localState",
466
466
  message: "Subscription '%s' contains `@client` fields with variables provided by `@export` but local state has not been configured."
467
467
  },
468
468
 
469
- 93: {
469
+ 95: {
470
470
  file: "@apollo/client/core/QueryManager.js",
471
471
  condition: "this.localState",
472
472
  message: "%s '%s' contains `@client` fields but local state has not been configured."
473
473
  },
474
474
 
475
- 94: {
475
+ 96: {
476
476
  file: "@apollo/client/core/QueryManager.js",
477
477
  condition: "!hasIncrementalDirective",
478
478
  message: "%s '%s' contains `@client` and `@defer` directives. These cannot be used together."
479
479
  },
480
480
 
481
- 95: {
481
+ 97: {
482
482
  file: "@apollo/client/core/QueryManager.js",
483
483
  condition: "this.localState",
484
484
  message: "Query '%s' contains `@client` fields with variables provided by `@export` but local state has not been configured."
485
485
  },
486
486
 
487
- 97: {
487
+ 99: {
488
488
  file: "@apollo/client/core/QueryManager.js",
489
489
  condition: "this.localState",
490
490
  message: "Query '%s' contains `@client` fields but local state has not been configured."
491
491
  },
492
492
 
493
- 98: {
493
+ 100: {
494
494
  file: "@apollo/client/core/QueryManager.js",
495
495
  condition: "didEmitValue",
496
496
  message: "The link chain completed without emitting a value. This is likely unintentional and should be updated to emit a value before completing."
497
497
  },
498
498
 
499
- 99: {
499
+ 104: {
500
500
  file: "@apollo/client/cache/inmemory/entityStore.js",
501
501
  condition: "typeof dataId === \"string\"",
502
502
  message: "store.merge expects a string ID"
503
503
  },
504
504
 
505
- 102: {
505
+ 107: {
506
506
  file: "@apollo/client/cache/inmemory/key-extractor.js",
507
507
  condition: "extracted !== void 0",
508
508
  message: `Missing field '%s' while extracting keyFields from %s`
509
509
  },
510
510
 
511
- 103: {
511
+ 108: {
512
512
  file: "@apollo/client/cache/inmemory/policies.js",
513
513
  condition: "!old || old === which",
514
514
  message: `Cannot change root %s __typename more than once`
515
515
  },
516
516
 
517
- 106: {
517
+ 111: {
518
518
  file: "@apollo/client/cache/inmemory/policies.js",
519
519
  message: "Cannot automatically merge arrays"
520
520
  },
521
521
 
522
- 107: {
522
+ 112: {
523
523
  file: "@apollo/client/cache/inmemory/readFromStore.js",
524
524
  message: `No fragment named %s`
525
525
  },
526
526
 
527
- 108: {
527
+ 113: {
528
528
  file: "@apollo/client/cache/inmemory/readFromStore.js",
529
529
  condition: "!isReference(value)",
530
530
  message: `Missing selection set for object of type %s returned for query field %s`
531
531
  },
532
532
 
533
- 109: {
533
+ 114: {
534
534
  file: "@apollo/client/cache/inmemory/writeToStore.js",
535
535
  message: `Could not identify object %s`
536
536
  },
537
537
 
538
- 111: {
538
+ 116: {
539
539
  file: "@apollo/client/cache/inmemory/writeToStore.js",
540
540
  message: `No fragment named %s`
541
541
  }
542
542
  };
543
543
 
544
544
  export const devDebug = {
545
- 79: {
545
+ 81: {
546
546
  file: "@apollo/client/core/ApolloClient.js",
547
547
  message: `In client.refetchQueries, Promise.all promise rejected with error %o`
548
548
  },
549
549
 
550
- 86: {
550
+ 88: {
551
551
  file: "@apollo/client/core/ObservableQuery.js",
552
552
  message: `Missing cache result fields: %o`
553
553
  }
@@ -625,34 +625,59 @@ export const devWarn = {
625
625
  "If you are using a split link, ensure each branch contains a terminating link that handles the request."
626
626
  },
627
627
 
628
- 81: {
628
+ 70: {
629
+ file: "@apollo/client/core/ApolloClient.js",
630
+ message: "`refetchOn` was set on query '%s' but no `RefetchEventManager` is configured on this `ApolloClient` instance. This option has no effect. Pass a `RefetchEventManager` instance to the `refetchEventManager` option on the `ApolloClient` constructor."
631
+ },
632
+
633
+ 71: {
634
+ file: "@apollo/client/core/ApolloClient.js",
635
+ message: "`refetchOn` references the '%s' event on query '%s' but no source is configured for it on the `RefetchEventManager`. This event will never fire. Add a source for the event to the `sources` option or call `setEventSource` on the refetch event manager."
636
+ },
637
+
638
+ 83: {
629
639
  file: "@apollo/client/core/ObservableQuery.js",
630
640
 
631
641
  message: `Called refetch(%o) for query %o, which does not declare a $variables variable.
632
642
  Did you mean to call refetch(variables) instead of refetch({ variables })?`
633
643
  },
634
644
 
635
- 85: {
645
+ 87: {
636
646
  file: "@apollo/client/core/ObservableQuery.js",
637
647
  message: "Cannot poll on 'cache-only' query '%s' and as such, polling is disabled. Please use a different fetch policy."
638
648
  },
639
649
 
640
- 90: {
650
+ 92: {
641
651
  file: "@apollo/client/core/QueryManager.js",
642
652
  message: `Unknown query named "%s" requested in refetchQueries options.include array`
643
653
  },
644
654
 
645
- 91: {
655
+ 93: {
646
656
  file: "@apollo/client/core/QueryManager.js",
647
657
  message: `Unknown anonymous query requested in refetchQueries options.include array`
648
658
  },
649
659
 
650
- 96: {
660
+ 98: {
651
661
  file: "@apollo/client/core/QueryManager.js",
652
662
  message: '[%s]: Fragments masked by data masking are inaccessible when using fetch policy "no-cache". Please add `@unmask` to each fragment spread to access the data.'
653
663
  },
654
664
 
655
- 100: {
665
+ 101: {
666
+ file: "@apollo/client/core/RefetchEventManager.js",
667
+ message: "Connected an `ApolloClient` instance to a `RefetchEventManager` that was already connected to a different `ApolloClient`. The previous client has been disconnected and will no longer receive refetch events from this manager."
668
+ },
669
+
670
+ 102: {
671
+ file: "@apollo/client/core/RefetchEventManager.js",
672
+ message: "Received '%s' event but an `ApolloClient` instance is not connected to the `RefetchEventManager`. No queries will refetch. Pass the manager to the `refetchEventManager` option on the `ApolloClient` constructor."
673
+ },
674
+
675
+ 103: {
676
+ file: "@apollo/client/core/RefetchEventManager.js",
677
+ message: "Received '%s' event but no source is configured for it on the `RefetchEventManager`. No queries will refetch. Add the event to the `sources` option or call `setEventSource`."
678
+ },
679
+
680
+ 105: {
656
681
  file: "@apollo/client/cache/inmemory/entityStore.js",
657
682
 
658
683
  message: "cache.modify: You are trying to write a Reference that is not part of the store: %o\n" +
@@ -660,24 +685,24 @@ Did you mean to call refetch(variables) instead of refetch({ variables })?`
660
685
  "`toReference(object, true)`"
661
686
  },
662
687
 
663
- 101: {
688
+ 106: {
664
689
  file: "@apollo/client/cache/inmemory/entityStore.js",
665
690
 
666
691
  message: "cache.modify: Writing an array with a mix of both References and Objects will not result in the Objects being normalized correctly.\n" +
667
692
  "Please convert the object instance %o to a Reference before writing it to the cache by calling `toReference(object, true)`."
668
693
  },
669
694
 
670
- 104: {
695
+ 109: {
671
696
  file: "@apollo/client/cache/inmemory/policies.js",
672
697
  message: `Inferring subtype %s of supertype %s`
673
698
  },
674
699
 
675
- 105: {
700
+ 110: {
676
701
  file: "@apollo/client/cache/inmemory/policies.js",
677
702
  message: `Undefined 'from' passed to readField with arguments %s`
678
703
  },
679
704
 
680
- 112: {
705
+ 117: {
681
706
  file: "@apollo/client/cache/inmemory/writeToStore.js",
682
707
 
683
708
  message: `Cache data may be lost when replacing the %s field of a %s object.
@@ -696,7 +721,7 @@ For more information about these options, please refer to the documentation:
696
721
  `
697
722
  },
698
723
 
699
- 113: {
724
+ 118: {
700
725
  file: "@apollo/client/cache/core/cache.js",
701
726
  message: "Could not identify object passed to `from` for '%s' fragment, either because the object is non-normalized or the key fields are missing. If you are masking this object, please ensure the key fields are requested by the parent object."
702
727
  }
@@ -713,12 +738,12 @@ export const devError = {
713
738
  message: "The result of getSnapshot should be cached to avoid an infinite loop"
714
739
  },
715
740
 
716
- 84: {
741
+ 86: {
717
742
  file: "@apollo/client/core/ObservableQuery.js",
718
743
  message: "Unhandled GraphQL subscription error"
719
744
  },
720
745
 
721
- 110: {
746
+ 115: {
722
747
  file: "@apollo/client/cache/inmemory/writeToStore.js",
723
748
  message: `Missing field '%s' while writing result %o`
724
749
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apollo/client",
3
- "version": "4.2.0-alpha.3",
3
+ "version": "4.2.0-alpha.4",
4
4
  "description": "A fully-featured caching GraphQL client.",
5
5
  "private": false,
6
6
  "keywords": [
@@ -1,4 +1,4 @@
1
- import type { ApolloClient, DefaultContext, DocumentNode, ErrorPolicy, OperationVariables, RefetchWritePolicy, TypedDocumentNode, WatchQueryFetchPolicy } from "@apollo/client";
1
+ import type { ApolloClient, DefaultContext, DocumentNode, ErrorPolicy, OperationVariables, RefetchOn, RefetchWritePolicy, TypedDocumentNode, WatchQueryFetchPolicy } from "@apollo/client";
2
2
  import type { SubscribeToMoreFunction } from "@apollo/client";
3
3
  import type { QueryRef } from "@apollo/client/react";
4
4
  import type { FetchMoreFunction, RefetchFunction } from "@apollo/client/react/internal";
@@ -72,6 +72,25 @@ export declare namespace useBackgroundQuery {
72
72
  */
73
73
  queryKey?: string | number | any[];
74
74
  /**
75
+ * Determines whether events trigger refetches for the query. Provide an
76
+ * object mapping each refetch event to `true` (enable), `false` (disable)
77
+ * or a callback function that returns `true`/`false` to control individual
78
+ * events. Provide `false` to disable all automatic refetch events for this
79
+ * query. Provide `true` to enable all automatic refetch events for this query.
80
+ * Provide a callback function to perform additional logic to determine
81
+ * whether to enable or disable a refetch for a query.
82
+ *
83
+ * `@remarks`
84
+ * `refetchOn` inherits from `defaultOptions.watchQuery.refetchOn`. If
85
+ * `defaultOptions.watchQuery.refetchOn` is not set, all refetch events are
86
+ * enabled by default.
87
+ *
88
+ * This option only has an effect when the client is configured with a
89
+ * `refetchEventManager`.
90
+ * @docGroup 1. Operation options
91
+ */
92
+ refetchOn?: RefetchOn.Option;
93
+ /**
75
94
  * If `true`, the query is not executed. The default value is `false`.
76
95
  *
77
96
  * @deprecated We recommend using `skipToken` in place of the `skip` option as
@@ -1 +1 @@
1
- {"version":3,"file":"useBackgroundQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useBackgroundQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAmB/B,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EACrB,YAAY,GACb,MAAM,+BAA+B,CAAC;AAUvC,OAAO,EAAE,uBAAuB,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD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,CAAC,QAAQ,CAAC,CAAC,CAAC;QAE3C,OAAO,OAAO,CAAC;IACjB,CAAC,EACD,CAAC,QAAQ,CAAC,CACX,CAAC;IAEF,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEzD,OAAO;QACL,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,KAAK,CAAC;QACjD;YACE,SAAS;YACT,OAAO;YACP,kGAAkG;YAClG,eAAe,EAAE,QAAQ,CAAC,UAAU;iBACjC,eAA6D;SACjE;KACF,CAAC;AACJ,CAAC","sourcesContent":["import * as React from \"react\";\n\nimport type {\n ApolloClient,\n DataState,\n DefaultContext,\n DocumentNode,\n ErrorPolicy,\n OperationVariables,\n RefetchWritePolicy,\n TypedDocumentNode,\n WatchQueryFetchPolicy,\n} from \"@apollo/client\";\nimport type { SubscribeToMoreFunction } from \"@apollo/client\";\nimport type { QueryRef } from \"@apollo/client/react\";\nimport type {\n FetchMoreFunction,\n RefetchFunction,\n} from \"@apollo/client/react/internal\";\nimport {\n getSuspenseCache,\n unwrapQueryRef,\n updateWrappedQueryRef,\n wrapQueryRef,\n} from \"@apollo/client/react/internal\";\nimport type {\n DocumentationTypes as UtilityDocumentationTypes,\n NoInfer,\n OptionWithFallback,\n SignatureStyle,\n VariablesOption,\n} from \"@apollo/client/utilities/internal\";\n\nimport type { SkipToken } from \"./constants.js\";\nimport { useSuspenseHookCacheKey, wrapHook } from \"./internal/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport { useWatchQueryOptions } from \"./useSuspenseQuery.js\";\n\nexport declare namespace useBackgroundQuery {\n import _self = useBackgroundQuery;\n export type FetchPolicy = Extract<\n WatchQueryFetchPolicy,\n \"cache-first\" | \"network-only\" | \"no-cache\" | \"cache-and-network\"\n >;\n\n export namespace Base {\n export interface Options {\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#client:member} */\n client?: ApolloClient;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#refetchWritePolicy_suspense:member} */\n refetchWritePolicy?: RefetchWritePolicy;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#errorPolicy:member} */\n errorPolicy?: ErrorPolicy;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#context:member} */\n context?: DefaultContext;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#returnPartialData:member} */\n returnPartialData?: boolean;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#fetchPolicy:member} */\n fetchPolicy?: FetchPolicy;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#queryKey:member} */\n queryKey?: string | number | any[];\n\n /**\n * {@inheritDoc @apollo/client!QueryOptionsDocumentation#skip_deprecated:member}\n *\n * @example Recommended usage of `skipToken`:\n *\n * ```ts\n * import { skipToken, useBackgroundQuery } from \"@apollo/client\";\n *\n * const [queryRef] = useBackgroundQuery(\n * query,\n * id ? { variables: { id } } : skipToken\n * );\n * ```\n */\n skip?: boolean;\n }\n }\n\n export type Options<\n TVariables extends OperationVariables = OperationVariables,\n > = Base.Options & VariablesOption<TVariables>;\n\n export namespace DocumentationTypes {\n namespace useBackgroundQuery {\n export interface Options<\n TVariables extends OperationVariables = OperationVariables,\n > extends Base.Options,\n UtilityDocumentationTypes.VariableOptions<TVariables> {}\n }\n }\n\n export interface Result<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > {\n /** {@inheritDoc @apollo/client!ObservableQuery#subscribeToMore:member(1)} */\n subscribeToMore: SubscribeToMoreFunction<TData, TVariables>;\n\n /**\n * {@inheritDoc @apollo/client!ObservableQuery#fetchMore:member(1)}\n *\n * @remarks\n * Calling this function will cause the component to re-suspend, unless the call site is wrapped in [`startTransition`](https://react.dev/reference/react/startTransition).\n */\n fetchMore: FetchMoreFunction<TData, TVariables>;\n\n /**\n * {@inheritDoc @apollo/client!QueryResultDocumentation#refetch:member}\n *\n * @remarks\n * Calling this function will cause the component to re-suspend, unless the call site is wrapped in [`startTransition`](https://react.dev/reference/react/startTransition).\n */\n refetch: RefetchFunction<TData, TVariables>;\n }\n\n namespace DocumentationTypes {\n namespace useBackgroundQuery {\n export interface Result<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > extends _self.Result<TData, TVariables> {}\n }\n }\n\n export interface DefaultOptions\n extends ApolloClient.DefaultOptions.WatchQuery.Calculated {\n skip: false;\n }\n\n export type ResultForOptions<\n TData,\n TVariables extends OperationVariables,\n TOptions extends Record<string, never> | Options<TVariables> | SkipToken,\n > = [\n queryRef: TOptions extends any ?\n TOptions extends SkipToken ?\n undefined\n : | QueryRef<\n TData,\n TVariables,\n | \"complete\"\n | \"streaming\"\n | (\n | (OptionWithFallback<\n TOptions,\n DefaultOptions,\n \"errorPolicy\"\n > extends \"none\" ?\n never\n : \"empty\")\n | (OptionWithFallback<\n TOptions,\n DefaultOptions,\n \"returnPartialData\"\n > extends false ?\n never\n : \"partial\")\n )\n >\n | (OptionWithFallback<TOptions, DefaultOptions, \"skip\"> extends false ?\n never\n : undefined)\n : never,\n result: useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n export namespace DocumentationTypes {\n export interface useBackgroundQuery {\n /**\n * For a detailed explanation of useBackgroundQuery, see the [fetching with Suspense reference](https://www.apollographql.com/docs/react/data/suspense).\n *\n * @returns A tuple containing:\n *\n * 1. A `QueryRef` that can be passed to `useReadQuery` to read the query result. The `queryRef` is `undefined` if the query is skipped.\n * 2. An object containing helper functions for the query:\n * - `refetch`: A function to re-execute the query\n * - `fetchMore`: A function to fetch more results for pagination\n * - `subscribeToMore`: A function to subscribe to updates\n *\n * @example\n *\n * ```jsx\n * import { Suspense } from \"react\";\n * import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\";\n * import { useBackgroundQuery, useReadQuery } from \"@apollo/client/react\";\n *\n * const query = gql`\n * foo {\n * bar\n * }\n * `;\n *\n * const client = new ApolloClient({\n * link: new HttpLink({ uri: \"http://localhost:4000/graphql\" }),\n * cache: new InMemoryCache(),\n * });\n *\n * function SuspenseFallback() {\n * return <div>Loading...</div>;\n * }\n *\n * function Child({ queryRef }) {\n * const { data } = useReadQuery(queryRef);\n *\n * return <div>{data.foo.bar}</div>;\n * }\n *\n * function Parent() {\n * const [queryRef] = useBackgroundQuery(query);\n *\n * return (\n * <Suspense fallback={<SuspenseFallback />}>\n * <Child queryRef={queryRef} />\n * </Suspense>\n * );\n * }\n *\n * function App() {\n * return (\n * <ApolloProvider client={client}>\n * <Parent />\n * </ApolloProvider>\n * );\n * }\n * ```\n *\n * @param query - A GraphQL query document parsed into an AST by `gql`.\n * @param options - An optional object containing options for the query. Instead of passing a `useBackgroundQuery.Options` object into the hook, you can also pass a [`skipToken`](#skiptoken) to prevent the `useBackgroundQuery` hook from executing the query or suspending.\n */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SkipToken | useBackgroundQuery.Options<TVariables>\n ): [\n QueryRef<TData, TVariables> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n }\n\n export interface useBackgroundQuery_Deprecated {\n /**\n * @deprecated Avoid manually specifying generics on `useBackgroundQuery`.\n * Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.\n *\n * {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery:call(1)}\n */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SkipToken | useBackgroundQuery.Options<TVariables>\n ): [\n QueryRef<TData, TVariables> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n }\n }\n\n export namespace Signatures {\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n export interface Classic {\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n /** @deprecated `returnPartialData` has no effect on `no-cache` queries */\n returnPartialData: boolean;\n fetchPolicy: \"no-cache\";\n }\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\">,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: false;\n errorPolicy: \"ignore\" | \"all\";\n }\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"empty\">,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: boolean;\n errorPolicy: \"ignore\" | \"all\";\n }\n ): [\n QueryRef<\n TData,\n TVariables,\n \"complete\" | \"streaming\" | \"partial\" | \"empty\"\n >,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n errorPolicy: \"ignore\" | \"all\";\n }\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"empty\">,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n skip: boolean;\n returnPartialData: false;\n }\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n skip: boolean;\n returnPartialData: boolean;\n }\n ): [\n (\n | QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"partial\">\n | undefined\n ),\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: false;\n }\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\">,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: boolean;\n }\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"partial\">,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n skip: boolean;\n }\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SkipToken\n ): [undefined, useBackgroundQuery.Result<TData, TVariables>];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | SkipToken\n | (useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: false;\n })\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | SkipToken\n | (useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: boolean;\n })\n ): [\n (\n | QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"partial\">\n | undefined\n ),\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n ...[options]: {} extends TVariables ?\n [options?: useBackgroundQuery.Options<NoInfer<TVariables>>]\n : [options: useBackgroundQuery.Options<NoInfer<TVariables>>]\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\">,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n ...[options]: {} extends TVariables ?\n [\n options?:\n | SkipToken\n | useBackgroundQuery.Options<NoInfer<TVariables>>,\n ]\n : [options: SkipToken | useBackgroundQuery.Options<NoInfer<TVariables>>]\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SkipToken | useBackgroundQuery.Options<NoInfer<TVariables>>\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n }\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery:call(1)} */\n export interface Modern {\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery:call(1)} */\n <\n TData,\n TVariables extends OperationVariables,\n // this overload should never be manually defined, it should always be inferred\n TOptions extends never,\n >(\n query: {} extends TVariables ?\n DocumentNode | TypedDocumentNode<TData, TVariables>\n : // this overload should only be accessible if all `TVariables` are optional\n never\n ): useBackgroundQuery.ResultForOptions<\n TData,\n TVariables,\n Record<string, never>\n >;\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery:call(1)} */\n <\n TData,\n TVariables extends OperationVariables,\n // this overload should never be manually defined, it should always be inferred\n TOptions extends never,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n skipToken: SkipToken\n ): useBackgroundQuery.ResultForOptions<TData, TVariables, SkipToken>;\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery:call(1)} */\n <\n TData,\n TVariables extends OperationVariables,\n // this overload should never be manually defined, it should always be inferred\n TOptions extends useBackgroundQuery.Options<NoInfer<TVariables>> &\n VariablesOption<\n TVariables & {\n [K in Exclude<\n keyof TOptions[\"variables\"],\n keyof TVariables\n >]?: never;\n }\n >,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n ...[options]: {} extends TVariables ? [options?: TOptions]\n : [options: TOptions]\n ): useBackgroundQuery.ResultForOptions<TData, TVariables, TOptions>;\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery:call(1)} */\n <\n TData,\n TVariables extends OperationVariables,\n // this overload should never be manually defined, it should always be inferred\n TOptions extends useBackgroundQuery.Options<NoInfer<TVariables>> &\n VariablesOption<\n TVariables & {\n [K in Exclude<\n keyof TOptions[\"variables\"],\n keyof TVariables\n >]?: never;\n }\n >,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n ...[options]: {} extends TVariables ? [options?: TOptions | SkipToken]\n : [options: TOptions | SkipToken]\n ): useBackgroundQuery.ResultForOptions<\n TData,\n TVariables,\n TOptions | SkipToken\n >;\n }\n\n export type Evaluated = SignatureStyle extends \"classic\" ? Classic : Modern;\n }\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery:call(1)} */\n export interface Signature extends Signatures.Evaluated {}\n}\n\nexport const useBackgroundQuery: useBackgroundQuery.Signature =\n function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: SkipToken | useBackgroundQuery.Options<NoInfer<TVariables>>\n ): [\n QueryRef<TData, TVariables, DataState<TData>[\"dataState\"]> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n ] {\n \"use no memo\";\n return wrapHook(\n \"useBackgroundQuery\",\n useBackgroundQuery_,\n useApolloClient(typeof options === \"object\" ? options.client : undefined)\n )(query, options ?? ({} as any));\n } as any;\n\nfunction useBackgroundQuery_<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n TStates extends DataState<TData>[\"dataState\"] = DataState<TData>[\"dataState\"],\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | (SkipToken & Partial<useBackgroundQuery.Options<NoInfer<TVariables>>>)\n | useBackgroundQuery.Options<NoInfer<TVariables>>\n): [\n QueryRef<TData, TVariables, TStates> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n] {\n const client = useApolloClient(options.client);\n const suspenseCache = getSuspenseCache(client);\n const watchQueryOptions = useWatchQueryOptions({ client, query, options });\n const { fetchPolicy } = watchQueryOptions;\n const cacheKey = useSuspenseHookCacheKey(query, options);\n\n // This ref tracks the first time query execution is enabled to determine\n // whether to return a query ref or `undefined`. When initialized\n // in a skipped state (either via `skip: true` or `skipToken`) we return\n // `undefined` for the `queryRef` until the query has been enabled. Once\n // enabled, a query ref is always returned regardless of whether the query is\n // skipped again later.\n const didFetchResult = React.useRef(fetchPolicy !== \"standby\");\n didFetchResult.current ||= fetchPolicy !== \"standby\";\n\n const queryRef = suspenseCache.getQueryRef<TData, TStates>(cacheKey, () =>\n client.watchQuery(\n watchQueryOptions as ApolloClient.WatchQueryOptions<any, any>\n )\n );\n\n const [wrappedQueryRef, setWrappedQueryRef] = React.useState(\n wrapQueryRef(queryRef)\n );\n if (unwrapQueryRef(wrappedQueryRef) !== queryRef) {\n setWrappedQueryRef(wrapQueryRef(queryRef));\n }\n if (queryRef.didChangeOptions(watchQueryOptions)) {\n const promise = queryRef.applyOptions(watchQueryOptions);\n updateWrappedQueryRef(wrappedQueryRef, promise);\n }\n\n // This prevents issues where rerendering useBackgroundQuery after the\n // queryRef has been disposed would cause the hook to return a new queryRef\n // instance since disposal also removes it from the suspense cache. We add\n // the queryRef back in the suspense cache so that the next render will reuse\n // this queryRef rather than initializing a new instance.\n React.useEffect(() => {\n // Since the queryRef is disposed async via `setTimeout`, we have to wait a\n // tick before checking it and adding back to the suspense cache.\n const id = setTimeout(() => {\n if (queryRef.disposed) {\n suspenseCache.add(cacheKey, queryRef);\n }\n });\n\n return () => clearTimeout(id);\n // Omitting the deps is intentional. This avoids stale closures and the\n // conditional ensures we aren't running the logic on each render.\n });\n\n const fetchMore: FetchMoreFunction<TData, TVariables> = React.useCallback(\n (options) => {\n const promise = queryRef.fetchMore(options);\n\n setWrappedQueryRef(wrapQueryRef(queryRef));\n\n return promise;\n },\n [queryRef]\n );\n\n const refetch: RefetchFunction<TData, TVariables> = React.useCallback(\n (variables) => {\n const promise = queryRef.refetch(variables);\n\n setWrappedQueryRef(wrapQueryRef(queryRef));\n\n return promise;\n },\n [queryRef]\n );\n\n React.useEffect(() => queryRef.softRetain(), [queryRef]);\n\n return [\n didFetchResult.current ? wrappedQueryRef : void 0,\n {\n fetchMore,\n refetch,\n // TODO: The internalQueryRef doesn't have TVariables' type information so we have to cast it here\n subscribeToMore: queryRef.observable\n .subscribeToMore as SubscribeToMoreFunction<TData, TVariables>,\n },\n ];\n}\n"]}
1
+ {"version":3,"file":"useBackgroundQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useBackgroundQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAoB/B,OAAO,EACL,gBA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AAQ,CAAC,CACX,CAAC;IAEF,MAAM,OAAO,GAAuC,KAAK,CAAC,WAAW,CACnE,CAAC,SAAS,EAAE,EAAE;QACZ,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAE5C,kBAAkB,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC;QAE3C,OAAO,OAAO,CAAC;IACjB,CAAC,EACD,CAAC,QAAQ,CAAC,CACX,CAAC;IAEF,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEzD,OAAO;QACL,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,KAAK,CAAC;QACjD;YACE,SAAS;YACT,OAAO;YACP,kGAAkG;YAClG,eAAe,EAAE,QAAQ,CAAC,UAAU;iBACjC,eAA6D;SACjE;KACF,CAAC;AACJ,CAAC","sourcesContent":["import * as React from \"react\";\n\nimport type {\n ApolloClient,\n DataState,\n DefaultContext,\n DocumentNode,\n ErrorPolicy,\n OperationVariables,\n RefetchOn,\n RefetchWritePolicy,\n TypedDocumentNode,\n WatchQueryFetchPolicy,\n} from \"@apollo/client\";\nimport type { SubscribeToMoreFunction } from \"@apollo/client\";\nimport type { QueryRef } from \"@apollo/client/react\";\nimport type {\n FetchMoreFunction,\n RefetchFunction,\n} from \"@apollo/client/react/internal\";\nimport {\n getSuspenseCache,\n unwrapQueryRef,\n updateWrappedQueryRef,\n wrapQueryRef,\n} from \"@apollo/client/react/internal\";\nimport type {\n DocumentationTypes as UtilityDocumentationTypes,\n NoInfer,\n OptionWithFallback,\n SignatureStyle,\n VariablesOption,\n} from \"@apollo/client/utilities/internal\";\n\nimport type { SkipToken } from \"./constants.js\";\nimport { useSuspenseHookCacheKey, wrapHook } from \"./internal/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport { useWatchQueryOptions } from \"./useSuspenseQuery.js\";\n\nexport declare namespace useBackgroundQuery {\n import _self = useBackgroundQuery;\n export type FetchPolicy = Extract<\n WatchQueryFetchPolicy,\n \"cache-first\" | \"network-only\" | \"no-cache\" | \"cache-and-network\"\n >;\n\n export namespace Base {\n export interface Options {\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#client:member} */\n client?: ApolloClient;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#refetchWritePolicy_suspense:member} */\n refetchWritePolicy?: RefetchWritePolicy;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#errorPolicy:member} */\n errorPolicy?: ErrorPolicy;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#context:member} */\n context?: DefaultContext;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#returnPartialData:member} */\n returnPartialData?: boolean;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#fetchPolicy:member} */\n fetchPolicy?: FetchPolicy;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#queryKey:member} */\n queryKey?: string | number | any[];\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#refetchOn:member} */\n refetchOn?: RefetchOn.Option;\n\n /**\n * {@inheritDoc @apollo/client!QueryOptionsDocumentation#skip_deprecated:member}\n *\n * @example Recommended usage of `skipToken`:\n *\n * ```ts\n * import { skipToken, useBackgroundQuery } from \"@apollo/client\";\n *\n * const [queryRef] = useBackgroundQuery(\n * query,\n * id ? { variables: { id } } : skipToken\n * );\n * ```\n */\n skip?: boolean;\n }\n }\n\n export type Options<\n TVariables extends OperationVariables = OperationVariables,\n > = Base.Options & VariablesOption<TVariables>;\n\n export namespace DocumentationTypes {\n namespace useBackgroundQuery {\n export interface Options<\n TVariables extends OperationVariables = OperationVariables,\n > extends Base.Options,\n UtilityDocumentationTypes.VariableOptions<TVariables> {}\n }\n }\n\n export interface Result<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > {\n /** {@inheritDoc @apollo/client!ObservableQuery#subscribeToMore:member(1)} */\n subscribeToMore: SubscribeToMoreFunction<TData, TVariables>;\n\n /**\n * {@inheritDoc @apollo/client!ObservableQuery#fetchMore:member(1)}\n *\n * @remarks\n * Calling this function will cause the component to re-suspend, unless the call site is wrapped in [`startTransition`](https://react.dev/reference/react/startTransition).\n */\n fetchMore: FetchMoreFunction<TData, TVariables>;\n\n /**\n * {@inheritDoc @apollo/client!QueryResultDocumentation#refetch:member}\n *\n * @remarks\n * Calling this function will cause the component to re-suspend, unless the call site is wrapped in [`startTransition`](https://react.dev/reference/react/startTransition).\n */\n refetch: RefetchFunction<TData, TVariables>;\n }\n\n namespace DocumentationTypes {\n namespace useBackgroundQuery {\n export interface Result<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > extends _self.Result<TData, TVariables> {}\n }\n }\n\n export interface DefaultOptions\n extends ApolloClient.DefaultOptions.WatchQuery.Calculated {\n skip: false;\n }\n\n export type ResultForOptions<\n TData,\n TVariables extends OperationVariables,\n TOptions extends Record<string, never> | Options<TVariables> | SkipToken,\n > = [\n queryRef: TOptions extends any ?\n TOptions extends SkipToken ?\n undefined\n : | QueryRef<\n TData,\n TVariables,\n | \"complete\"\n | \"streaming\"\n | (\n | (OptionWithFallback<\n TOptions,\n DefaultOptions,\n \"errorPolicy\"\n > extends \"none\" ?\n never\n : \"empty\")\n | (OptionWithFallback<\n TOptions,\n DefaultOptions,\n \"returnPartialData\"\n > extends false ?\n never\n : \"partial\")\n )\n >\n | (OptionWithFallback<TOptions, DefaultOptions, \"skip\"> extends false ?\n never\n : undefined)\n : never,\n result: useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n export namespace DocumentationTypes {\n export interface useBackgroundQuery {\n /**\n * For a detailed explanation of useBackgroundQuery, see the [fetching with Suspense reference](https://www.apollographql.com/docs/react/data/suspense).\n *\n * @returns A tuple containing:\n *\n * 1. A `QueryRef` that can be passed to `useReadQuery` to read the query result. The `queryRef` is `undefined` if the query is skipped.\n * 2. An object containing helper functions for the query:\n * - `refetch`: A function to re-execute the query\n * - `fetchMore`: A function to fetch more results for pagination\n * - `subscribeToMore`: A function to subscribe to updates\n *\n * @example\n *\n * ```jsx\n * import { Suspense } from \"react\";\n * import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\";\n * import { useBackgroundQuery, useReadQuery } from \"@apollo/client/react\";\n *\n * const query = gql`\n * foo {\n * bar\n * }\n * `;\n *\n * const client = new ApolloClient({\n * link: new HttpLink({ uri: \"http://localhost:4000/graphql\" }),\n * cache: new InMemoryCache(),\n * });\n *\n * function SuspenseFallback() {\n * return <div>Loading...</div>;\n * }\n *\n * function Child({ queryRef }) {\n * const { data } = useReadQuery(queryRef);\n *\n * return <div>{data.foo.bar}</div>;\n * }\n *\n * function Parent() {\n * const [queryRef] = useBackgroundQuery(query);\n *\n * return (\n * <Suspense fallback={<SuspenseFallback />}>\n * <Child queryRef={queryRef} />\n * </Suspense>\n * );\n * }\n *\n * function App() {\n * return (\n * <ApolloProvider client={client}>\n * <Parent />\n * </ApolloProvider>\n * );\n * }\n * ```\n *\n * @param query - A GraphQL query document parsed into an AST by `gql`.\n * @param options - An optional object containing options for the query. Instead of passing a `useBackgroundQuery.Options` object into the hook, you can also pass a [`skipToken`](#skiptoken) to prevent the `useBackgroundQuery` hook from executing the query or suspending.\n */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SkipToken | useBackgroundQuery.Options<TVariables>\n ): [\n QueryRef<TData, TVariables> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n }\n\n export interface useBackgroundQuery_Deprecated {\n /**\n * @deprecated Avoid manually specifying generics on `useBackgroundQuery`.\n * Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.\n *\n * {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery:call(1)}\n */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SkipToken | useBackgroundQuery.Options<TVariables>\n ): [\n QueryRef<TData, TVariables> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n }\n }\n\n export namespace Signatures {\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n export interface Classic {\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n /** @deprecated `returnPartialData` has no effect on `no-cache` queries */\n returnPartialData: boolean;\n fetchPolicy: \"no-cache\";\n }\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\">,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: false;\n errorPolicy: \"ignore\" | \"all\";\n }\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"empty\">,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: boolean;\n errorPolicy: \"ignore\" | \"all\";\n }\n ): [\n QueryRef<\n TData,\n TVariables,\n \"complete\" | \"streaming\" | \"partial\" | \"empty\"\n >,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n errorPolicy: \"ignore\" | \"all\";\n }\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"empty\">,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n skip: boolean;\n returnPartialData: false;\n }\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n skip: boolean;\n returnPartialData: boolean;\n }\n ): [\n (\n | QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"partial\">\n | undefined\n ),\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: false;\n }\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\">,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: boolean;\n }\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"partial\">,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n skip: boolean;\n }\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SkipToken\n ): [undefined, useBackgroundQuery.Result<TData, TVariables>];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | SkipToken\n | (useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: false;\n })\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | SkipToken\n | (useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: boolean;\n })\n ): [\n (\n | QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"partial\">\n | undefined\n ),\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n ...[options]: {} extends TVariables ?\n [options?: useBackgroundQuery.Options<NoInfer<TVariables>>]\n : [options: useBackgroundQuery.Options<NoInfer<TVariables>>]\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\">,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n ...[options]: {} extends TVariables ?\n [\n options?:\n | SkipToken\n | useBackgroundQuery.Options<NoInfer<TVariables>>,\n ]\n : [options: SkipToken | useBackgroundQuery.Options<NoInfer<TVariables>>]\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SkipToken | useBackgroundQuery.Options<NoInfer<TVariables>>\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n }\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery:call(1)} */\n export interface Modern {\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery:call(1)} */\n <\n TData,\n TVariables extends OperationVariables,\n // this overload should never be manually defined, it should always be inferred\n TOptions extends never,\n >(\n query: {} extends TVariables ?\n DocumentNode | TypedDocumentNode<TData, TVariables>\n : // this overload should only be accessible if all `TVariables` are optional\n never\n ): useBackgroundQuery.ResultForOptions<\n TData,\n TVariables,\n Record<string, never>\n >;\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery:call(1)} */\n <\n TData,\n TVariables extends OperationVariables,\n // this overload should never be manually defined, it should always be inferred\n TOptions extends never,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n skipToken: SkipToken\n ): useBackgroundQuery.ResultForOptions<TData, TVariables, SkipToken>;\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery:call(1)} */\n <\n TData,\n TVariables extends OperationVariables,\n // this overload should never be manually defined, it should always be inferred\n TOptions extends useBackgroundQuery.Options<NoInfer<TVariables>> &\n VariablesOption<\n TVariables & {\n [K in Exclude<\n keyof TOptions[\"variables\"],\n keyof TVariables\n >]?: never;\n }\n >,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n ...[options]: {} extends TVariables ? [options?: TOptions]\n : [options: TOptions]\n ): useBackgroundQuery.ResultForOptions<TData, TVariables, TOptions>;\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery:call(1)} */\n <\n TData,\n TVariables extends OperationVariables,\n // this overload should never be manually defined, it should always be inferred\n TOptions extends useBackgroundQuery.Options<NoInfer<TVariables>> &\n VariablesOption<\n TVariables & {\n [K in Exclude<\n keyof TOptions[\"variables\"],\n keyof TVariables\n >]?: never;\n }\n >,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n ...[options]: {} extends TVariables ? [options?: TOptions | SkipToken]\n : [options: TOptions | SkipToken]\n ): useBackgroundQuery.ResultForOptions<\n TData,\n TVariables,\n TOptions | SkipToken\n >;\n }\n\n export type Evaluated = SignatureStyle extends \"classic\" ? Classic : Modern;\n }\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery:call(1)} */\n export interface Signature extends Signatures.Evaluated {}\n}\n\nexport const useBackgroundQuery: useBackgroundQuery.Signature =\n function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: SkipToken | useBackgroundQuery.Options<NoInfer<TVariables>>\n ): [\n QueryRef<TData, TVariables, DataState<TData>[\"dataState\"]> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n ] {\n \"use no memo\";\n return wrapHook(\n \"useBackgroundQuery\",\n useBackgroundQuery_,\n useApolloClient(typeof options === \"object\" ? options.client : undefined)\n )(query, options ?? ({} as any));\n } as any;\n\nfunction useBackgroundQuery_<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n TStates extends DataState<TData>[\"dataState\"] = DataState<TData>[\"dataState\"],\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | (SkipToken & Partial<useBackgroundQuery.Options<NoInfer<TVariables>>>)\n | useBackgroundQuery.Options<NoInfer<TVariables>>\n): [\n QueryRef<TData, TVariables, TStates> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n] {\n const client = useApolloClient(options.client);\n const suspenseCache = getSuspenseCache(client);\n const watchQueryOptions = useWatchQueryOptions({ client, query, options });\n const { fetchPolicy } = watchQueryOptions;\n const cacheKey = useSuspenseHookCacheKey(query, options);\n\n // This ref tracks the first time query execution is enabled to determine\n // whether to return a query ref or `undefined`. When initialized\n // in a skipped state (either via `skip: true` or `skipToken`) we return\n // `undefined` for the `queryRef` until the query has been enabled. Once\n // enabled, a query ref is always returned regardless of whether the query is\n // skipped again later.\n const didFetchResult = React.useRef(fetchPolicy !== \"standby\");\n didFetchResult.current ||= fetchPolicy !== \"standby\";\n\n const queryRef = suspenseCache.getQueryRef<TData, TStates>(cacheKey, () =>\n client.watchQuery(\n watchQueryOptions as ApolloClient.WatchQueryOptions<any, any>\n )\n );\n\n const [wrappedQueryRef, setWrappedQueryRef] = React.useState(\n wrapQueryRef(queryRef)\n );\n if (unwrapQueryRef(wrappedQueryRef) !== queryRef) {\n setWrappedQueryRef(wrapQueryRef(queryRef));\n }\n if (queryRef.didChangeOptions(watchQueryOptions)) {\n const promise = queryRef.applyOptions(watchQueryOptions);\n updateWrappedQueryRef(wrappedQueryRef, promise);\n }\n\n // This prevents issues where rerendering useBackgroundQuery after the\n // queryRef has been disposed would cause the hook to return a new queryRef\n // instance since disposal also removes it from the suspense cache. We add\n // the queryRef back in the suspense cache so that the next render will reuse\n // this queryRef rather than initializing a new instance.\n React.useEffect(() => {\n // Since the queryRef is disposed async via `setTimeout`, we have to wait a\n // tick before checking it and adding back to the suspense cache.\n const id = setTimeout(() => {\n if (queryRef.disposed) {\n suspenseCache.add(cacheKey, queryRef);\n }\n });\n\n return () => clearTimeout(id);\n // Omitting the deps is intentional. This avoids stale closures and the\n // conditional ensures we aren't running the logic on each render.\n });\n\n const fetchMore: FetchMoreFunction<TData, TVariables> = React.useCallback(\n (options) => {\n const promise = queryRef.fetchMore(options);\n\n setWrappedQueryRef(wrapQueryRef(queryRef));\n\n return promise;\n },\n [queryRef]\n );\n\n const refetch: RefetchFunction<TData, TVariables> = React.useCallback(\n (variables) => {\n const promise = queryRef.refetch(variables);\n\n setWrappedQueryRef(wrapQueryRef(queryRef));\n\n return promise;\n },\n [queryRef]\n );\n\n React.useEffect(() => queryRef.softRetain(), [queryRef]);\n\n return [\n didFetchResult.current ? wrappedQueryRef : void 0,\n {\n fetchMore,\n refetch,\n // TODO: The internalQueryRef doesn't have TVariables' type information so we have to cast it here\n subscribeToMore: queryRef.observable\n .subscribeToMore as SubscribeToMoreFunction<TData, TVariables>,\n },\n ];\n}\n"]}
@@ -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 {
@@ -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,