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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/.changeset/eighty-squids-fix.md +15 -0
  2. package/.changeset/funny-jeans-invent.md +16 -0
  3. package/.changeset/khaki-spies-work.md +11 -0
  4. package/.changeset/light-apes-rescue.md +5 -0
  5. package/.changeset/odd-lemons-relax.md +5 -0
  6. package/.changeset/pre.json +5 -0
  7. package/CHANGELOG.md +44 -0
  8. package/__cjs/core/ApolloClient.cjs +22 -13
  9. package/__cjs/core/ApolloClient.cjs.map +1 -1
  10. package/__cjs/core/ApolloClient.d.cts +13 -1
  11. package/__cjs/core/ObservableQuery.cjs +29 -10
  12. package/__cjs/core/ObservableQuery.cjs.map +1 -1
  13. package/__cjs/core/ObservableQuery.d.cts +6 -3
  14. package/__cjs/core/QueryManager.cjs +15 -0
  15. package/__cjs/core/QueryManager.cjs.map +1 -1
  16. package/__cjs/core/QueryManager.d.cts +11 -0
  17. package/__cjs/core/watchQueryOptions.d.cts +18 -25
  18. package/__cjs/react/hooks/index.cjs +13 -8
  19. package/__cjs/react/hooks/index.cjs.map +1 -1
  20. package/__cjs/react/hooks/index.d.cts +6 -12
  21. package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
  22. package/__cjs/react/hooks/useBackgroundQuery.d.cts +146 -43
  23. package/__cjs/react/hooks/useFragment.cjs.map +1 -1
  24. package/__cjs/react/hooks/useFragment.d.cts +51 -26
  25. package/__cjs/react/hooks/useLazyQuery.cjs +1 -1
  26. package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
  27. package/__cjs/react/hooks/useLazyQuery.d.cts +263 -262
  28. package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
  29. package/__cjs/react/hooks/useLoadableQuery.d.cts +105 -32
  30. package/__cjs/react/hooks/useMutation.cjs.map +1 -1
  31. package/__cjs/react/hooks/useMutation.d.cts +198 -3
  32. package/__cjs/react/hooks/useQuery.cjs +9 -11
  33. package/__cjs/react/hooks/useQuery.cjs.map +1 -1
  34. package/__cjs/react/hooks/useQuery.d.cts +279 -4
  35. package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
  36. package/__cjs/react/hooks/useQueryRefHandlers.d.cts +21 -20
  37. package/__cjs/react/hooks/useReadQuery.cjs.map +1 -1
  38. package/__cjs/react/hooks/useReadQuery.d.cts +26 -24
  39. package/__cjs/react/hooks/useSubscription.cjs.map +1 -1
  40. package/__cjs/react/hooks/useSubscription.d.cts +127 -4
  41. package/__cjs/react/hooks/useSuspenseFragment.cjs.map +1 -1
  42. package/__cjs/react/hooks/useSuspenseFragment.d.cts +40 -37
  43. package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
  44. package/__cjs/react/hooks/useSuspenseQuery.d.cts +202 -35
  45. package/__cjs/react/index.cjs.map +1 -1
  46. package/__cjs/react/index.d.cts +2 -1
  47. package/__cjs/react/internal/index.cjs.map +1 -1
  48. package/__cjs/react/internal/index.d.cts +1 -0
  49. package/__cjs/react/internal/types.d.cts +46 -0
  50. package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
  51. package/__cjs/react/query-preloader/createQueryPreloader.d.cts +2 -3
  52. package/__cjs/react/ssr/RenderPromises.cjs.map +1 -1
  53. package/__cjs/react/ssr/RenderPromises.d.cts +6 -3
  54. package/__cjs/react/types/deprecated.cjs +3 -0
  55. package/__cjs/react/types/deprecated.cjs.map +1 -0
  56. package/__cjs/react/types/deprecated.d.cts +65 -0
  57. package/__cjs/testing/matchers/index.cjs +2 -0
  58. package/__cjs/testing/matchers/index.cjs.map +1 -1
  59. package/__cjs/testing/matchers/toEqualLazyQueryResult.cjs.map +1 -1
  60. package/__cjs/testing/matchers/toEqualLazyQueryResult.d.cts +2 -2
  61. package/__cjs/testing/matchers/toEqualQueryResult.cjs.map +1 -1
  62. package/__cjs/testing/matchers/toEqualQueryResult.d.cts +2 -2
  63. package/__cjs/testing/matchers/toEqualStrictTyped.cjs +44 -0
  64. package/__cjs/testing/matchers/toEqualStrictTyped.cjs.map +1 -0
  65. package/__cjs/testing/matchers/toEqualStrictTyped.d.cts +3 -0
  66. package/__cjs/version.cjs +1 -1
  67. package/__cjs/version.d.cts +1 -1
  68. package/core/ApolloClient.d.ts +13 -1
  69. package/core/ApolloClient.js +22 -13
  70. package/core/ApolloClient.js.map +1 -1
  71. package/core/ObservableQuery.d.ts +6 -3
  72. package/core/ObservableQuery.js +29 -10
  73. package/core/ObservableQuery.js.map +1 -1
  74. package/core/QueryManager.d.ts +11 -0
  75. package/core/QueryManager.js +15 -0
  76. package/core/QueryManager.js.map +1 -1
  77. package/core/watchQueryOptions.d.ts +18 -25
  78. package/package.json +1 -1
  79. package/react/hooks/index.d.ts +6 -12
  80. package/react/hooks/index.js +6 -6
  81. package/react/hooks/index.js.map +1 -1
  82. package/react/hooks/useBackgroundQuery.d.ts +146 -43
  83. package/react/hooks/useBackgroundQuery.js.map +1 -1
  84. package/react/hooks/useFragment.d.ts +51 -26
  85. package/react/hooks/useFragment.js.map +1 -1
  86. package/react/hooks/useLazyQuery.d.ts +263 -262
  87. package/react/hooks/useLazyQuery.js +1 -1
  88. package/react/hooks/useLazyQuery.js.map +1 -1
  89. package/react/hooks/useLoadableQuery.d.ts +105 -32
  90. package/react/hooks/useLoadableQuery.js.map +1 -1
  91. package/react/hooks/useMutation.d.ts +198 -3
  92. package/react/hooks/useMutation.js.map +1 -1
  93. package/react/hooks/useQuery.d.ts +279 -4
  94. package/react/hooks/useQuery.js +9 -11
  95. package/react/hooks/useQuery.js.map +1 -1
  96. package/react/hooks/useQueryRefHandlers.d.ts +21 -20
  97. package/react/hooks/useQueryRefHandlers.js.map +1 -1
  98. package/react/hooks/useReadQuery.d.ts +26 -24
  99. package/react/hooks/useReadQuery.js.map +1 -1
  100. package/react/hooks/useSubscription.d.ts +127 -4
  101. package/react/hooks/useSubscription.js.map +1 -1
  102. package/react/hooks/useSuspenseFragment.d.ts +40 -37
  103. package/react/hooks/useSuspenseFragment.js.map +1 -1
  104. package/react/hooks/useSuspenseQuery.d.ts +202 -35
  105. package/react/hooks/useSuspenseQuery.js.map +1 -1
  106. package/react/index.d.ts +2 -1
  107. package/react/index.js.map +1 -1
  108. package/react/internal/index.d.ts +1 -0
  109. package/react/internal/index.js.map +1 -1
  110. package/react/internal/types.d.ts +46 -0
  111. package/react/query-preloader/createQueryPreloader.d.ts +2 -3
  112. package/react/query-preloader/createQueryPreloader.js.map +1 -1
  113. package/react/ssr/RenderPromises.d.ts +6 -3
  114. package/react/ssr/RenderPromises.js.map +1 -1
  115. package/react/types/deprecated.d.ts +65 -0
  116. package/react/types/deprecated.js +2 -0
  117. package/react/types/deprecated.js.map +1 -0
  118. package/testing/matchers/index.js +2 -0
  119. package/testing/matchers/index.js.map +1 -1
  120. package/testing/matchers/toEqualLazyQueryResult.d.ts +2 -2
  121. package/testing/matchers/toEqualLazyQueryResult.js.map +1 -1
  122. package/testing/matchers/toEqualQueryResult.d.ts +2 -2
  123. package/testing/matchers/toEqualQueryResult.js.map +1 -1
  124. package/testing/matchers/toEqualStrictTyped.d.ts +3 -0
  125. package/testing/matchers/toEqualStrictTyped.js +40 -0
  126. package/testing/matchers/toEqualStrictTyped.js.map +1 -0
  127. package/version.d.ts +1 -1
  128. package/version.js +1 -1
  129. package/__cjs/react/types/types.d.cts +0 -661
  130. package/react/types/types.d.ts +0 -661
  131. /package/__cjs/react/{types → internal}/types.cjs +0 -0
  132. /package/__cjs/react/{types → internal}/types.cjs.map +0 -0
  133. /package/react/{types → internal}/types.js +0 -0
  134. /package/react/{types → internal}/types.js.map +0 -0
@@ -15,6 +15,7 @@ const invariant_1 = require("@apollo/client/utilities/invariant");
15
15
  const equalByQuery_js_1 = require("./equalByQuery.cjs");
16
16
  const networkStatus_js_1 = require("./networkStatus.cjs");
17
17
  const { assign, hasOwnProperty } = Object;
18
+ const newNetworkStatusSymbol = Symbol();
18
19
  class ObservableQuery {
19
20
  options;
20
21
  queryId;
@@ -84,6 +85,7 @@ class ObservableQuery {
84
85
  this.options.notifyOnNetworkStatusChange) ||
85
86
  // TODO: Remove this behavior when unifying loading state for notifyOnNetworkStatusChange
86
87
  (this.options.fetchPolicy === "network-only" &&
88
+ !this.queryManager.prioritizeCacheValues &&
87
89
  this.queryInfo.getDiff().complete) ||
88
90
  result !== this.initialResult));
89
91
  this["@@observable"] = () => this;
@@ -141,7 +143,11 @@ class ObservableQuery {
141
143
  loading: (0, networkStatus_js_1.isNetworkRequestInFlight)(networkStatus),
142
144
  networkStatus,
143
145
  };
144
- const { fetchPolicy = "cache-first" } = this.options;
146
+ let { fetchPolicy = "cache-first" } = this.options;
147
+ const { prioritizeCacheValues } = this.queryManager;
148
+ if (prioritizeCacheValues) {
149
+ fetchPolicy = "cache-first";
150
+ }
145
151
  if (
146
152
  // These fetch policies should never deliver data from the cache, unless
147
153
  // redelivering a previously delivered result.
@@ -153,7 +159,7 @@ class ObservableQuery {
153
159
  this.queryManager.getDocumentInfo(this.query).hasForcedResolvers) {
154
160
  // Fall through.
155
161
  }
156
- else if (this.waitForOwnResult) {
162
+ else if (this.waitForOwnResult && !prioritizeCacheValues) {
157
163
  // This would usually be a part of `QueryInfo.getDiff()`.
158
164
  // which we skip in the waitForOwnResult case since we are not
159
165
  // interested in the diff.
@@ -276,7 +282,10 @@ class ObservableQuery {
276
282
  };
277
283
  }
278
284
  this.queryInfo.resetLastWrite();
279
- return this.reobserve(reobserveOptions, networkStatus_js_1.NetworkStatus.refetch);
285
+ return this.reobserve({
286
+ ...reobserveOptions,
287
+ [newNetworkStatusSymbol]: networkStatus_js_1.NetworkStatus.refetch,
288
+ });
280
289
  }
281
290
  /**
282
291
  * A function that helps you fetch the next set of results for a [paginated list field](https://www.apollographql.com/docs/react/pagination/core-api/).
@@ -450,9 +459,7 @@ class ObservableQuery {
450
459
  }
451
460
  };
452
461
  }
453
- setOptions(newOptions) {
454
- return this.reobserve(newOptions);
455
- }
462
+ /** @internal */
456
463
  silentSetOptions(newOptions) {
457
464
  const mergedOptions = (0, utilities_1.compact)(this.options, newOptions || {});
458
465
  assign(this.options, mergedOptions);
@@ -491,7 +498,8 @@ class ObservableQuery {
491
498
  // Reset options.fetchPolicy to its original value.
492
499
  fetchPolicy: this.options.initialFetchPolicy,
493
500
  variables,
494
- }, networkStatus_js_1.NetworkStatus.setVariables);
501
+ [newNetworkStatusSymbol]: networkStatus_js_1.NetworkStatus.setVariables,
502
+ });
495
503
  }
496
504
  /**
497
505
  * A function that enables you to update the query's cached result without executing a followup GraphQL operation.
@@ -556,7 +564,7 @@ class ObservableQuery {
556
564
  // requests to be triggered only if the cache result is incomplete. To
557
565
  // that end, the options.nextFetchPolicy option provides an easy way to
558
566
  // update options.fetchPolicy after the initial network request, without
559
- // having to call observableQuery.setOptions.
567
+ // having to call observableQuery.reobserve.
560
568
  options.fetchPolicy = options.nextFetchPolicy(fetchPolicy, {
561
569
  reason,
562
570
  options,
@@ -611,7 +619,8 @@ class ObservableQuery {
611
619
  fetchPolicy: this.options.initialFetchPolicy === "no-cache" ?
612
620
  "no-cache"
613
621
  : "network-only",
614
- }, networkStatus_js_1.NetworkStatus.poll).then(poll, poll);
622
+ [newNetworkStatusSymbol]: networkStatus_js_1.NetworkStatus.poll,
623
+ }).then(poll, poll);
615
624
  }
616
625
  else {
617
626
  poll();
@@ -641,10 +650,20 @@ class ObservableQuery {
641
650
  ...(error ? { error } : null),
642
651
  });
643
652
  }
653
+ /**
654
+ * Reevaluate the query, optionally against new options. New options will be
655
+ * merged with the current options when given.
656
+ */
644
657
  // TODO: catch `EmptyError` and rethrow as network error if `complete`
645
658
  // notification is emitted without a value.
646
- reobserve(newOptions, newNetworkStatus) {
659
+ reobserve(newOptions) {
647
660
  this.isTornDown = false;
661
+ let newNetworkStatus;
662
+ if (newOptions) {
663
+ newNetworkStatus = newOptions[newNetworkStatusSymbol];
664
+ // Avoid setting the symbol option in this.options
665
+ delete newOptions[newNetworkStatusSymbol];
666
+ }
648
667
  const useDisposableObservable =
649
668
  // Refetching uses a disposable Observable to allow refetches using different
650
669
  // options/variables, without permanently altering the options of the