@apollo/client 3.9.0-beta.0 → 3.9.0-rc.0

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 (152) hide show
  1. package/.changeset/chatty-comics-yawn.md +8 -0
  2. package/.changeset/curvy-seas-hope.md +13 -0
  3. package/.changeset/late-rabbits-protect.md +7 -0
  4. package/.changeset/pink-apricots-yawn.md +5 -0
  5. package/.changeset/pre.json +8 -1
  6. package/.changeset/smooth-plums-shout.md +5 -0
  7. package/.changeset/spicy-drinks-camp.md +5 -0
  8. package/.changeset/wise-news-grab.md +7 -0
  9. package/CHANGELOG.md +51 -0
  10. package/apollo-client.cjs +60 -52
  11. package/apollo-client.cjs.map +1 -1
  12. package/apollo-client.min.cjs +1 -1
  13. package/cache/cache.cjs +2 -2
  14. package/cache/cache.cjs.map +1 -1
  15. package/cache/cache.cjs.native.js +2 -2
  16. package/cache/inmemory/readFromStore.js +2 -2
  17. package/cache/inmemory/readFromStore.js.map +1 -1
  18. package/core/ApolloClient.d.ts +74 -1
  19. package/core/ApolloClient.js.map +1 -1
  20. package/core/ObservableQuery.js +8 -4
  21. package/core/ObservableQuery.js.map +1 -1
  22. package/core/core.cjs +11 -7
  23. package/core/core.cjs.map +1 -1
  24. package/core/core.cjs.native.js +11 -7
  25. package/dev/dev.cjs +1 -1
  26. package/dev/dev.cjs.map +1 -1
  27. package/dev/dev.cjs.native.js +1 -1
  28. package/link/http/checkFetcher.d.ts +1 -1
  29. package/link/http/checkFetcher.js.map +1 -1
  30. package/link/http/http.cjs +0 -3
  31. package/link/http/http.cjs.map +1 -1
  32. package/link/http/http.cjs.native.js +0 -3
  33. package/link/http/parseAndCheckHttpResponse.js +0 -4
  34. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  35. package/link/http/selectHttpOptionsAndBody.d.ts +1 -1
  36. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  37. package/link/retry/retry.cjs +15 -74
  38. package/link/retry/retry.cjs.map +1 -1
  39. package/link/retry/retry.cjs.native.js +15 -74
  40. package/link/retry/retryLink.js +15 -93
  41. package/link/retry/retryLink.js.map +1 -1
  42. package/package.json +21 -21
  43. package/react/components/Mutation.d.ts +6 -0
  44. package/react/components/Mutation.js +6 -0
  45. package/react/components/Mutation.js.map +1 -1
  46. package/react/components/Query.d.ts +6 -0
  47. package/react/components/Query.js +6 -0
  48. package/react/components/Query.js.map +1 -1
  49. package/react/components/Subscription.d.ts +6 -0
  50. package/react/components/Subscription.js +6 -0
  51. package/react/components/Subscription.js.map +1 -1
  52. package/react/components/components.cjs.map +1 -1
  53. package/react/hoc/graphql.d.ts +5 -0
  54. package/react/hoc/graphql.js +5 -0
  55. package/react/hoc/graphql.js.map +1 -1
  56. package/react/hoc/hoc.cjs.map +1 -1
  57. package/react/hoc/mutation-hoc.d.ts +5 -0
  58. package/react/hoc/mutation-hoc.js +5 -0
  59. package/react/hoc/mutation-hoc.js.map +1 -1
  60. package/react/hoc/query-hoc.d.ts +5 -0
  61. package/react/hoc/query-hoc.js +5 -0
  62. package/react/hoc/query-hoc.js.map +1 -1
  63. package/react/hoc/subscription-hoc.d.ts +5 -0
  64. package/react/hoc/subscription-hoc.js +5 -0
  65. package/react/hoc/subscription-hoc.js.map +1 -1
  66. package/react/hoc/withApollo.d.ts +5 -0
  67. package/react/hoc/withApollo.js +5 -0
  68. package/react/hoc/withApollo.js.map +1 -1
  69. package/react/hooks/hooks.cjs +62 -322
  70. package/react/hooks/hooks.cjs.map +1 -1
  71. package/react/hooks/hooks.cjs.native.js +62 -322
  72. package/react/hooks/internal/index.d.ts +1 -0
  73. package/react/hooks/internal/index.js +1 -0
  74. package/react/hooks/internal/index.js.map +1 -1
  75. package/react/hooks/internal/useLazyRef.d.ts +3 -0
  76. package/react/hooks/internal/useLazyRef.js +10 -0
  77. package/react/hooks/internal/useLazyRef.js.map +1 -0
  78. package/react/hooks/useBackgroundQuery.d.ts +1 -1
  79. package/react/hooks/useBackgroundQuery.js +1 -3
  80. package/react/hooks/useBackgroundQuery.js.map +1 -1
  81. package/react/hooks/useFragment.js +20 -17
  82. package/react/hooks/useFragment.js.map +1 -1
  83. package/react/hooks/useLoadableQuery.d.ts +1 -1
  84. package/react/hooks/useLoadableQuery.js +1 -3
  85. package/react/hooks/useLoadableQuery.js.map +1 -1
  86. package/react/hooks/useQueryRefHandlers.d.ts +1 -1
  87. package/react/hooks/useQueryRefHandlers.js +1 -1
  88. package/react/hooks/useQueryRefHandlers.js.map +1 -1
  89. package/react/hooks/useReadQuery.d.ts +1 -1
  90. package/react/hooks/useReadQuery.js +1 -1
  91. package/react/hooks/useReadQuery.js.map +1 -1
  92. package/react/hooks/useSuspenseQuery.js +1 -1
  93. package/react/hooks/useSuspenseQuery.js.map +1 -1
  94. package/react/{cache → internal/cache}/QueryReference.d.ts +2 -2
  95. package/react/{cache → internal/cache}/QueryReference.js +2 -2
  96. package/react/internal/cache/QueryReference.js.map +1 -0
  97. package/react/{cache → internal/cache}/SuspenseCache.d.ts +1 -1
  98. package/react/{cache → internal/cache}/SuspenseCache.js +1 -1
  99. package/react/internal/cache/SuspenseCache.js.map +1 -0
  100. package/react/{cache → internal/cache}/getSuspenseCache.d.ts +3 -3
  101. package/react/internal/cache/getSuspenseCache.js.map +1 -0
  102. package/react/internal/cache/types.js.map +1 -0
  103. package/react/internal/index.d.ts +6 -0
  104. package/react/internal/index.js +3 -0
  105. package/react/internal/index.js.map +1 -0
  106. package/react/internal/internal.cjs +283 -0
  107. package/react/internal/internal.cjs.map +1 -0
  108. package/react/internal/internal.cjs.native.js +283 -0
  109. package/react/internal/package.json +8 -0
  110. package/react/parser/parser.cjs.map +1 -1
  111. package/react/query-preloader/createQueryPreloader.d.ts +1 -1
  112. package/react/query-preloader/createQueryPreloader.js +1 -1
  113. package/react/query-preloader/createQueryPreloader.js.map +1 -1
  114. package/react/react.cjs +3 -238
  115. package/react/react.cjs.map +1 -1
  116. package/react/react.cjs.native.js +3 -238
  117. package/react/types/types.d.ts +1 -1
  118. package/react/types/types.js.map +1 -1
  119. package/testing/core/core.cjs +5 -3
  120. package/testing/core/core.cjs.map +1 -1
  121. package/testing/core/core.cjs.native.js +5 -3
  122. package/testing/core/mocking/mockLink.js +9 -3
  123. package/testing/core/mocking/mockLink.js.map +1 -1
  124. package/testing/internal/ObservableStream.js +16 -8
  125. package/testing/internal/ObservableStream.js.map +1 -1
  126. package/testing/internal/scenarios/index.js +5 -3
  127. package/testing/internal/scenarios/index.js.map +1 -1
  128. package/testing/matchers/toBeDisposed.js +1 -1
  129. package/testing/matchers/toBeDisposed.js.map +1 -1
  130. package/testing/matchers/toHaveSuspenseCacheEntryUsing.js +1 -1
  131. package/testing/matchers/toHaveSuspenseCacheEntryUsing.js.map +1 -1
  132. package/utilities/caching/getMemoryInternals.js +2 -2
  133. package/utilities/caching/getMemoryInternals.js.map +1 -1
  134. package/utilities/caching/sizes.d.ts +109 -59
  135. package/utilities/caching/sizes.js.map +1 -1
  136. package/utilities/globals/globals.cjs +1 -1
  137. package/utilities/globals/globals.cjs.map +1 -1
  138. package/utilities/globals/globals.cjs.native.js +1 -1
  139. package/utilities/subscriptions/relay/relay.cjs.map +1 -1
  140. package/utilities/subscriptions/urql/urql.cjs.map +1 -1
  141. package/utilities/utilities.cjs.map +1 -1
  142. package/version.js +1 -1
  143. package/react/cache/QueryReference.js.map +0 -1
  144. package/react/cache/SuspenseCache.js.map +0 -1
  145. package/react/cache/getSuspenseCache.js.map +0 -1
  146. package/react/cache/index.d.ts +0 -3
  147. package/react/cache/index.js +0 -2
  148. package/react/cache/index.js.map +0 -1
  149. package/react/cache/types.js.map +0 -1
  150. /package/react/{cache → internal/cache}/getSuspenseCache.js +0 -0
  151. /package/react/{cache → internal/cache}/types.d.ts +0 -0
  152. /package/react/{cache → internal/cache}/types.js +0 -0
@@ -0,0 +1,8 @@
1
+ ---
2
+ "@apollo/client": patch
3
+ ---
4
+
5
+ Adds a deprecation warning to the HOC and render prop APIs.
6
+
7
+ The HOC and render prop APIs have already been deprecated since 2020,
8
+ but we previously didn't have a @deprecated tag in the DocBlocks.
@@ -0,0 +1,13 @@
1
+ ---
2
+ "@apollo/client": minor
3
+ ---
4
+
5
+ Simplify RetryLink, fix potential memory leak
6
+
7
+ Historically, `RetryLink` would keep a `values` array of all previous values,
8
+ in case the operation would get an additional subscriber at a later point in time.
9
+ In practice, this could lead to a memory leak (#11393) and did not serve any
10
+ further purpose, as the resulting observable would only be subscribed to by
11
+ Apollo Client itself, and only once - it would be wrapped in a `Concast` before
12
+ being exposed to the user, and that `Concast` would handle subscribers on its
13
+ own.
@@ -0,0 +1,7 @@
1
+ ---
2
+ '@apollo/client': minor
3
+ ---
4
+
5
+ Remove the need to call `retain` from `useLoadableQuery` since `useReadQuery` will now retain the query. This means that a `queryRef` that is not consumed by `useReadQuery` within the given `autoDisposeTimeoutMs` will now be auto diposed for you.
6
+
7
+ Thanks to [#11412](https://github.com/apollographql/apollo-client/pull/11412), disposed query refs will be automatically resubscribed to the query when consumed by `useReadQuery` after it has been disposed.
@@ -0,0 +1,5 @@
1
+ ---
2
+ "@apollo/client": minor
3
+ ---
4
+
5
+ Increase the default memory limits for `executeSelectionSet` and `executeSelectionSetArray`.
@@ -1,27 +1,33 @@
1
1
  {
2
2
  "mode": "pre",
3
- "tag": "beta",
3
+ "tag": "rc",
4
4
  "initialVersions": {
5
5
  "@apollo/client": "3.8.3"
6
6
  },
7
7
  "changesets": [
8
8
  "beige-geese-wink",
9
9
  "breezy-spiders-tap",
10
+ "chatty-comics-yawn",
10
11
  "clean-items-smash",
11
12
  "cold-llamas-turn",
13
+ "curvy-seas-hope",
12
14
  "dirty-kids-crash",
13
15
  "dirty-tigers-matter",
14
16
  "forty-cups-shop",
15
17
  "friendly-clouds-laugh",
16
18
  "hot-ducks-burn",
19
+ "late-rabbits-protect",
17
20
  "mighty-coats-check",
21
+ "pink-apricots-yawn",
18
22
  "polite-avocados-warn",
19
23
  "quick-hats-marry",
20
24
  "rare-snakes-melt",
21
25
  "shaggy-ears-scream",
22
26
  "shaggy-sheep-pull",
23
27
  "sixty-boxes-rest",
28
+ "smooth-plums-shout",
24
29
  "sour-sheep-walk",
30
+ "spicy-drinks-camp",
25
31
  "strong-terms-perform",
26
32
  "swift-zoos-collect",
27
33
  "thick-mice-collect",
@@ -32,6 +38,7 @@
32
38
  "violet-lions-draw",
33
39
  "wet-forks-rhyme",
34
40
  "wild-dolphins-jog",
41
+ "wise-news-grab",
35
42
  "yellow-flies-repeat"
36
43
  ]
37
44
  }
@@ -0,0 +1,5 @@
1
+ ---
2
+ "@apollo/client": patch
3
+ ---
4
+
5
+ ObservableQuery: prevent reporting results of previous queries if the variables changed since
@@ -0,0 +1,5 @@
1
+ ---
2
+ '@apollo/client': patch
3
+ ---
4
+
5
+ Address bundling issue introduced in [#11412](https://github.com/apollographql/apollo-client/pull/11412) where the `react/cache` internals ended up duplicated in the bundle. This was due to the fact that we had a `react/hooks` entrypoint that imported these files along with the newly introduced `createQueryPreloader` function, which lived outside of the `react/hooks` folder.
@@ -0,0 +1,7 @@
1
+ ---
2
+ '@apollo/client': minor
3
+ ---
4
+
5
+ Remove the need to call `retain` from `useBackgroundQuery` since `useReadQuery` will now retain the query. This means that a `queryRef` that is not consumed by `useReadQuery` within the given `autoDisposeTimeoutMs` will now be auto diposed for you.
6
+
7
+ Thanks to [#11412](https://github.com/apollographql/apollo-client/pull/11412), disposed query refs will be automatically resubscribed to the query when consumed by `useReadQuery` after it has been disposed.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,56 @@
1
1
  # @apollo/client
2
2
 
3
+ ## 3.9.0-rc.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#11495](https://github.com/apollographql/apollo-client/pull/11495) [`1190aa5`](https://github.com/apollographql/apollo-client/commit/1190aa59a106217f7192c1f81099adfa5e4365c1) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Increase the default memory limits for `executeSelectionSet` and `executeSelectionSetArray`.
8
+
9
+ ## 3.8.9
10
+
11
+ ### Patch Changes
12
+
13
+ - [#11472](https://github.com/apollographql/apollo-client/pull/11472) [`afc844d`](https://github.com/apollographql/apollo-client/commit/afc844dd8d6f9f7a3e2003f9a5b541291dfe3fb4) Thanks [@alessbell](https://github.com/alessbell)! - Fix delay: Infinity when set on a MockResponse passed to Mocked Provider so it indefinitely enters loading state.
14
+
15
+ - [#11464](https://github.com/apollographql/apollo-client/pull/11464) [`aac12b2`](https://github.com/apollographql/apollo-client/commit/aac12b221a6cb776d4941b6c8aadf04f0f0acd27) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Prevent `useFragment` from excessively unsubscribing and resubscribing the fragment with the cache on every render.
16
+
17
+ - [#11449](https://github.com/apollographql/apollo-client/pull/11449) [`f40cda4`](https://github.com/apollographql/apollo-client/commit/f40cda45841e93b056c781c19651b54464f7346a) Thanks [@phryneas](https://github.com/phryneas)! - Removes refences to the typescript "dom" lib.
18
+
19
+ - [#11470](https://github.com/apollographql/apollo-client/pull/11470) [`e293bc9`](https://github.com/apollographql/apollo-client/commit/e293bc90d6f7937a6fc7c169f7b16eeb39d5fd49) Thanks [@phryneas](https://github.com/phryneas)! - Remove an unnecessary check from parseAndCheckHttpResponse.
20
+
21
+ ## 3.9.0-beta.1
22
+
23
+ ### Minor Changes
24
+
25
+ - [#11424](https://github.com/apollographql/apollo-client/pull/11424) [`62f3b6d`](https://github.com/apollographql/apollo-client/commit/62f3b6d0e89611e27d9f29812ee60e5db5963fd6) Thanks [@phryneas](https://github.com/phryneas)! - Simplify RetryLink, fix potential memory leak
26
+
27
+ Historically, `RetryLink` would keep a `values` array of all previous values,
28
+ in case the operation would get an additional subscriber at a later point in time.
29
+ In practice, this could lead to a memory leak (#11393) and did not serve any
30
+ further purpose, as the resulting observable would only be subscribed to by
31
+ Apollo Client itself, and only once - it would be wrapped in a `Concast` before
32
+ being exposed to the user, and that `Concast` would handle subscribers on its
33
+ own.
34
+
35
+ - [#11442](https://github.com/apollographql/apollo-client/pull/11442) [`4b6f2bc`](https://github.com/apollographql/apollo-client/commit/4b6f2bccf3ba94643b38689b32edd2839e47aec1) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Remove the need to call `retain` from `useLoadableQuery` since `useReadQuery` will now retain the query. This means that a `queryRef` that is not consumed by `useReadQuery` within the given `autoDisposeTimeoutMs` will now be auto diposed for you.
36
+
37
+ Thanks to [#11412](https://github.com/apollographql/apollo-client/pull/11412), disposed query refs will be automatically resubscribed to the query when consumed by `useReadQuery` after it has been disposed.
38
+
39
+ - [#11438](https://github.com/apollographql/apollo-client/pull/11438) [`6d46ab9`](https://github.com/apollographql/apollo-client/commit/6d46ab930a5e9bd5cae153d3b75b8966784fcd4e) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Remove the need to call `retain` from `useBackgroundQuery` since `useReadQuery` will now retain the query. This means that a `queryRef` that is not consumed by `useReadQuery` within the given `autoDisposeTimeoutMs` will now be auto diposed for you.
40
+
41
+ Thanks to [#11412](https://github.com/apollographql/apollo-client/pull/11412), disposed query refs will be automatically resubscribed to the query when consumed by `useReadQuery` after it has been disposed.
42
+
43
+ ### Patch Changes
44
+
45
+ - [#11443](https://github.com/apollographql/apollo-client/pull/11443) [`ff5a332`](https://github.com/apollographql/apollo-client/commit/ff5a332ff8b190c418df25371e36719d70061ebe) Thanks [@phryneas](https://github.com/phryneas)! - Adds a deprecation warning to the HOC and render prop APIs.
46
+
47
+ The HOC and render prop APIs have already been deprecated since 2020,
48
+ but we previously didn't have a @deprecated tag in the DocBlocks.
49
+
50
+ - [#11078](https://github.com/apollographql/apollo-client/pull/11078) [`14edebe`](https://github.com/apollographql/apollo-client/commit/14edebebefb7634c32b921d02c1c85c6c8737989) Thanks [@phryneas](https://github.com/phryneas)! - ObservableQuery: prevent reporting results of previous queries if the variables changed since
51
+
52
+ - [#11439](https://github.com/apollographql/apollo-client/pull/11439) [`33454f0`](https://github.com/apollographql/apollo-client/commit/33454f0a40a05ea2b00633bda20a84d0ec3a4f4d) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Address bundling issue introduced in [#11412](https://github.com/apollographql/apollo-client/pull/11412) where the `react/cache` internals ended up duplicated in the bundle. This was due to the fact that we had a `react/hooks` entrypoint that imported these files along with the newly introduced `createQueryPreloader` function, which lived outside of the `react/hooks` folder.
53
+
3
54
  ## 3.9.0-beta.0
4
55
 
5
56
  ### Minor Changes
package/apollo-client.cjs CHANGED
@@ -13,6 +13,7 @@ var optimism = require('optimism');
13
13
  var trie = require('@wry/trie');
14
14
  var graphqlTag = require('graphql-tag');
15
15
  var React = require('rehackt');
16
+ var React$1 = require('react');
16
17
 
17
18
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
18
19
 
@@ -30,8 +31,9 @@ function _interopNamespace(e) {
30
31
 
31
32
  var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
32
33
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
34
+ var React__namespace$1 = /*#__PURE__*/_interopNamespace(React$1);
33
35
 
34
- var version = "3.9.0-beta.0";
36
+ var version = "3.9.0-rc.0";
35
37
 
36
38
  function maybe(thunk) {
37
39
  try {
@@ -320,8 +322,8 @@ function getCurrentCacheSizes() {
320
322
  "cache.fragmentQueryDocuments": 1000 ,
321
323
  "removeTypenameFromVariables.getVariableDefinitions": 2000 ,
322
324
  "inMemoryCache.maybeBroadcastWatch": 5000 ,
323
- "inMemoryCache.executeSelectionSet": 10000 ,
324
- "inMemoryCache.executeSubSelectedArray": 5000 ,
325
+ "inMemoryCache.executeSelectionSet": 50000 ,
326
+ "inMemoryCache.executeSubSelectedArray": 10000 ,
325
327
  };
326
328
  return Object.fromEntries(Object.entries(defaults).map(function (_a) {
327
329
  var k = _a[0], v = _a[1];
@@ -2067,9 +2069,6 @@ function parseAndCheckHttpResponse(operations) {
2067
2069
  .text()
2068
2070
  .then(function (bodyText) { return parseJsonBody(response, bodyText); })
2069
2071
  .then(function (result) {
2070
- if (response.status >= 300) {
2071
- throwServerError(response, result, "Response not successful: Received status code ".concat(response.status));
2072
- }
2073
2072
  if (!Array.isArray(result) &&
2074
2073
  !hasOwnProperty$3.call(result, "data") &&
2075
2074
  !hasOwnProperty$3.call(result, "errors")) {
@@ -3202,7 +3201,7 @@ var StoreReader = (function () {
3202
3201
  }, {
3203
3202
  max: this.config.resultCacheMaxSize ||
3204
3203
  cacheSizes["inMemoryCache.executeSelectionSet"] ||
3205
- 10000 ,
3204
+ 50000 ,
3206
3205
  keyArgs: execSelectionSetKeyArgs,
3207
3206
  makeCacheKey: function (selectionSet, parent, context, canonizeResults) {
3208
3207
  if (supportsResultCaching(context.store)) {
@@ -3216,7 +3215,7 @@ var StoreReader = (function () {
3216
3215
  }, {
3217
3216
  max: this.config.resultCacheMaxSize ||
3218
3217
  cacheSizes["inMemoryCache.executeSubSelectedArray"] ||
3219
- 5000 ,
3218
+ 10000 ,
3220
3219
  makeCacheKey: function (_a) {
3221
3220
  var field = _a.field, array = _a.array, context = _a.context;
3222
3221
  if (supportsResultCaching(context.store)) {
@@ -5294,12 +5293,16 @@ var ObservableQuery = (function (_super) {
5294
5293
  var _a = this.fetch(options, newNetworkStatus, query), concast = _a.concast, fromLink = _a.fromLink;
5295
5294
  var observer = {
5296
5295
  next: function (result) {
5297
- finishWaitingForOwnResult();
5298
- _this.reportResult(result, variables);
5296
+ if (equal.equal(_this.variables, variables)) {
5297
+ finishWaitingForOwnResult();
5298
+ _this.reportResult(result, variables);
5299
+ }
5299
5300
  },
5300
5301
  error: function (error) {
5301
- finishWaitingForOwnResult();
5302
- _this.reportError(error, variables);
5302
+ if (equal.equal(_this.variables, variables)) {
5303
+ finishWaitingForOwnResult();
5304
+ _this.reportError(error, variables);
5305
+ }
5303
5306
  },
5304
5307
  };
5305
5308
  if (!useDisposableConcast && (fromLink || !this.concast)) {
@@ -7975,44 +7978,6 @@ function useReactiveVar(rv) {
7975
7978
  }, [rv]), rv, rv);
7976
7979
  }
7977
7980
 
7978
- function useFragment(options) {
7979
- var cache = useApolloClient().cache;
7980
- var fragment = options.fragment, fragmentName = options.fragmentName, from = options.from, _a = options.optimistic, optimistic = _a === void 0 ? true : _a, rest = tslib.__rest(options, ["fragment", "fragmentName", "from", "optimistic"]);
7981
- var diffOptions = tslib.__assign(tslib.__assign({}, rest), { returnPartialData: true, id: typeof from === "string" ? from : cache.identify(from), query: cache["getFragmentDoc"](fragment, fragmentName), optimistic: optimistic });
7982
- var resultRef = React__namespace.useRef();
7983
- var latestDiff = cache.diff(diffOptions);
7984
- var getSnapshot = function () {
7985
- var latestDiffToResult = diffToResult(latestDiff);
7986
- return (resultRef.current &&
7987
- equal.equal(resultRef.current.data, latestDiffToResult.data)) ?
7988
- resultRef.current
7989
- : (resultRef.current = latestDiffToResult);
7990
- };
7991
- return useSyncExternalStore(function (forceUpdate) {
7992
- var lastTimeout = 0;
7993
- var unsubcribe = cache.watch(tslib.__assign(tslib.__assign({}, diffOptions), { immediate: true, callback: function (diff) {
7994
- if (!equal.equal(diff, latestDiff)) {
7995
- resultRef.current = diffToResult((latestDiff = diff));
7996
- lastTimeout = setTimeout(forceUpdate);
7997
- }
7998
- } }));
7999
- return function () {
8000
- unsubcribe();
8001
- clearTimeout(lastTimeout);
8002
- };
8003
- }, getSnapshot, getSnapshot);
8004
- }
8005
- function diffToResult(diff) {
8006
- var result = {
8007
- data: diff.result,
8008
- complete: !!diff.complete,
8009
- };
8010
- if (diff.missing) {
8011
- result.missing = mergeDeepArray(diff.missing.map(function (error) { return error.missing; }));
8012
- }
8013
- return result;
8014
- }
8015
-
8016
7981
  function useDeepMemo(memoFn, deps) {
8017
7982
  var ref = React__namespace.useRef();
8018
7983
  if (!ref.current || !equal.equal(ref.current.deps, deps)) {
@@ -8033,6 +7998,15 @@ function useRenderGuard() {
8033
7998
  }, []);
8034
7999
  }
8035
8000
 
8001
+ var INIT = {};
8002
+ function useLazyRef(getInitialValue) {
8003
+ var ref = React__namespace$1.useRef(INIT);
8004
+ if (ref.current === INIT) {
8005
+ ref.current = getInitialValue();
8006
+ }
8007
+ return ref;
8008
+ }
8009
+
8036
8010
  var useKey = "use";
8037
8011
  var realHook = React__namespace[useKey];
8038
8012
  var __use = realHook ||
@@ -8048,6 +8022,42 @@ var __use = realHook ||
8048
8022
  }
8049
8023
  };
8050
8024
 
8025
+ function useFragment(options) {
8026
+ var cache = useApolloClient().cache;
8027
+ var diffOptions = useDeepMemo(function () {
8028
+ var fragment = options.fragment, fragmentName = options.fragmentName, from = options.from, _a = options.optimistic, optimistic = _a === void 0 ? true : _a, rest = tslib.__rest(options, ["fragment", "fragmentName", "from", "optimistic"]);
8029
+ return tslib.__assign(tslib.__assign({}, rest), { returnPartialData: true, id: typeof from === "string" ? from : cache.identify(from), query: cache["getFragmentDoc"](fragment, fragmentName), optimistic: optimistic });
8030
+ }, [options]);
8031
+ var resultRef = useLazyRef(function () {
8032
+ return diffToResult(cache.diff(diffOptions));
8033
+ });
8034
+ var getSnapshot = React__namespace.useCallback(function () { return resultRef.current; }, []);
8035
+ return useSyncExternalStore(React__namespace.useCallback(function (forceUpdate) {
8036
+ var lastTimeout = 0;
8037
+ var unsubscribe = cache.watch(tslib.__assign(tslib.__assign({}, diffOptions), { immediate: true, callback: function (diff) {
8038
+ if (!equal.equal(diff.result, resultRef.current.data)) {
8039
+ resultRef.current = diffToResult(diff);
8040
+ clearTimeout(lastTimeout);
8041
+ lastTimeout = setTimeout(forceUpdate);
8042
+ }
8043
+ } }));
8044
+ return function () {
8045
+ unsubscribe();
8046
+ clearTimeout(lastTimeout);
8047
+ };
8048
+ }, [cache, diffOptions]), getSnapshot, getSnapshot);
8049
+ }
8050
+ function diffToResult(diff) {
8051
+ var result = {
8052
+ data: diff.result,
8053
+ complete: !!diff.complete,
8054
+ };
8055
+ if (diff.missing) {
8056
+ result.missing = mergeDeepArray(diff.missing.map(function (error) { return error.missing; }));
8057
+ }
8058
+ return result;
8059
+ }
8060
+
8051
8061
  var QUERY_REFERENCE_SYMBOL = Symbol();
8052
8062
  var PROMISE_SYMBOL = Symbol();
8053
8063
  function wrapQueryRef(internalQueryRef) {
@@ -8458,7 +8468,6 @@ function useBackgroundQuery(query, options) {
8458
8468
  var promise = queryRef.applyOptions(watchQueryOptions);
8459
8469
  updateWrappedQueryRef(wrappedQueryRef, promise);
8460
8470
  }
8461
- React__namespace.useEffect(function () { return queryRef.retain(); }, [queryRef]);
8462
8471
  var fetchMore = React__namespace.useCallback(function (options) {
8463
8472
  var promise = queryRef.fetchMore(options);
8464
8473
  setWrappedQueryRef(wrapQueryRef(queryRef));
@@ -8488,7 +8497,6 @@ function useLoadableQuery(query, options) {
8488
8497
  updateWrappedQueryRef(queryRef, promise);
8489
8498
  }
8490
8499
  var calledDuringRender = useRenderGuard();
8491
- React__namespace.useEffect(function () { return internalQueryRef === null || internalQueryRef === void 0 ? void 0 : internalQueryRef.retain(); }, [internalQueryRef]);
8492
8500
  var fetchMore = React__namespace.useCallback(function (options) {
8493
8501
  if (!internalQueryRef) {
8494
8502
  throw new Error("The query has not been loaded. Please load the query.");