@apollo/client 3.13.8 → 3.14.0-alpha.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 (182) hide show
  1. package/.changeset/chilled-cameras-scream.md +5 -0
  2. package/.changeset/great-suns-cover.md +5 -0
  3. package/.changeset/perfect-donuts-roll.md +5 -0
  4. package/.changeset/popular-waves-drop.md +5 -0
  5. package/.changeset/pre.json +16 -0
  6. package/.changeset/shy-dragons-tease.md +5 -0
  7. package/.changeset/smooth-countries-cough.md +5 -0
  8. package/.changeset/spotty-walls-repair.md +5 -0
  9. package/CHANGELOG.md +20 -0
  10. package/README.md +80 -31
  11. package/apollo-client.cjs +354 -132
  12. package/apollo-client.cjs.map +1 -1
  13. package/apollo-client.min.cjs +1 -1
  14. package/cache/cache.cjs +78 -21
  15. package/cache/cache.cjs.map +1 -1
  16. package/cache/cache.cjs.native.js +78 -21
  17. package/cache/core/cache.js +27 -4
  18. package/cache/core/cache.js.map +1 -1
  19. package/cache/core/types/Cache.d.ts +4 -4
  20. package/cache/core/types/Cache.js.map +1 -1
  21. package/cache/core/types/DataProxy.d.ts +2 -2
  22. package/cache/inmemory/inMemoryCache.js +15 -4
  23. package/cache/inmemory/inMemoryCache.js.map +1 -1
  24. package/cache/inmemory/policies.js +18 -13
  25. package/cache/inmemory/policies.js.map +1 -1
  26. package/cache/inmemory/readFromStore.d.ts +7 -0
  27. package/cache/inmemory/readFromStore.js.map +1 -1
  28. package/cache/inmemory/types.d.ts +14 -3
  29. package/cache/inmemory/types.js.map +1 -1
  30. package/core/ApolloClient.d.ts +191 -2
  31. package/core/ApolloClient.js +93 -7
  32. package/core/ApolloClient.js.map +1 -1
  33. package/core/LocalState.js +2 -2
  34. package/core/ObservableQuery.js +10 -6
  35. package/core/ObservableQuery.js.map +1 -1
  36. package/core/QueryInfo.js +8 -2
  37. package/core/QueryInfo.js.map +1 -1
  38. package/core/QueryManager.js +15 -12
  39. package/core/QueryManager.js.map +1 -1
  40. package/core/core.cjs +93 -30
  41. package/core/core.cjs.map +1 -1
  42. package/core/core.cjs.native.js +93 -30
  43. package/core/watchQueryOptions.d.ts +2 -2
  44. package/dev/dev.cjs +144 -84
  45. package/dev/dev.cjs.map +1 -1
  46. package/dev/dev.cjs.native.js +144 -84
  47. package/invariantErrorCodes.js +158 -83
  48. package/link/core/ApolloLink.js +2 -2
  49. package/link/core/core.cjs +2 -2
  50. package/link/core/core.cjs.map +1 -1
  51. package/link/core/core.cjs.native.js +2 -2
  52. package/link/http/checkFetcher.js +1 -1
  53. package/link/http/createHttpLink.js +1 -1
  54. package/link/http/http.cjs +3 -3
  55. package/link/http/http.cjs.map +1 -1
  56. package/link/http/http.cjs.native.js +3 -3
  57. package/link/http/serializeFetchParameter.js +1 -1
  58. package/link/persisted-queries/index.js +2 -2
  59. package/link/persisted-queries/persisted-queries.cjs +2 -2
  60. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  61. package/link/persisted-queries/persisted-queries.cjs.native.js +2 -2
  62. package/link/utils/toPromise.js +1 -1
  63. package/link/utils/utils.cjs +2 -2
  64. package/link/utils/utils.cjs.map +1 -1
  65. package/link/utils/utils.cjs.native.js +2 -2
  66. package/link/utils/validateOperation.js +1 -1
  67. package/masking/maskDefinition.js +2 -2
  68. package/masking/maskFragment.js +2 -2
  69. package/masking/maskOperation.js +1 -1
  70. package/masking/masking.cjs +6 -6
  71. package/masking/masking.cjs.map +1 -1
  72. package/masking/masking.cjs.native.js +6 -6
  73. package/masking/utils.js +1 -1
  74. package/package.json +1 -1
  75. package/react/components/Mutation.js +5 -0
  76. package/react/components/Mutation.js.map +1 -1
  77. package/react/components/Query.js +5 -0
  78. package/react/components/Query.js.map +1 -1
  79. package/react/components/Subscription.js +5 -0
  80. package/react/components/Subscription.js.map +1 -1
  81. package/react/components/components.cjs +34 -0
  82. package/react/components/components.cjs.map +1 -1
  83. package/react/components/components.cjs.native.js +34 -0
  84. package/react/context/ApolloConsumer.js +1 -1
  85. package/react/context/ApolloContext.js +7 -2
  86. package/react/context/ApolloContext.js.map +1 -1
  87. package/react/context/ApolloProvider.js +1 -1
  88. package/react/context/context.cjs +9 -4
  89. package/react/context/context.cjs.map +1 -1
  90. package/react/context/context.cjs.native.js +9 -4
  91. package/react/hoc/graphql.js +17 -4
  92. package/react/hoc/graphql.js.map +1 -1
  93. package/react/hoc/hoc-utils.js +1 -1
  94. package/react/hoc/hoc.cjs +55 -9
  95. package/react/hoc/hoc.cjs.map +1 -1
  96. package/react/hoc/hoc.cjs.native.js +55 -9
  97. package/react/hoc/mutation-hoc.js +8 -1
  98. package/react/hoc/mutation-hoc.js.map +1 -1
  99. package/react/hoc/query-hoc.js +8 -1
  100. package/react/hoc/query-hoc.js.map +1 -1
  101. package/react/hoc/subscription-hoc.js +8 -1
  102. package/react/hoc/subscription-hoc.js.map +1 -1
  103. package/react/hoc/withApollo.js +1 -1
  104. package/react/hooks/hooks.cjs +264 -31
  105. package/react/hooks/hooks.cjs.map +1 -1
  106. package/react/hooks/hooks.cjs.native.js +264 -31
  107. package/react/hooks/internal/index.d.ts +2 -0
  108. package/react/hooks/internal/index.js +2 -0
  109. package/react/hooks/internal/index.js.map +1 -1
  110. package/react/hooks/internal/useWarnRemoved.d.ts +2 -0
  111. package/react/hooks/internal/useWarnRemoved.js +14 -0
  112. package/react/hooks/internal/useWarnRemoved.js.map +1 -0
  113. package/react/hooks/internal/useWarnRemovedOption.d.ts +2 -0
  114. package/react/hooks/internal/useWarnRemovedOption.js +14 -0
  115. package/react/hooks/internal/useWarnRemovedOption.js.map +1 -0
  116. package/react/hooks/useApolloClient.js +1 -1
  117. package/react/hooks/useBackgroundQuery.js +11 -3
  118. package/react/hooks/useBackgroundQuery.js.map +1 -1
  119. package/react/hooks/useFragment.js +30 -21
  120. package/react/hooks/useFragment.js.map +1 -1
  121. package/react/hooks/useLazyQuery.js +65 -0
  122. package/react/hooks/useLazyQuery.js.map +1 -1
  123. package/react/hooks/useLoadableQuery.js +12 -5
  124. package/react/hooks/useLoadableQuery.js.map +1 -1
  125. package/react/hooks/useMutation.js +5 -1
  126. package/react/hooks/useMutation.js.map +1 -1
  127. package/react/hooks/useQuery.d.ts +2 -2
  128. package/react/hooks/useQuery.js +25 -7
  129. package/react/hooks/useQuery.js.map +1 -1
  130. package/react/hooks/useSubscription.js +3 -3
  131. package/react/hooks/useSubscription.js.map +1 -1
  132. package/react/hooks/useSuspenseQuery.js +12 -6
  133. package/react/hooks/useSuspenseQuery.js.map +1 -1
  134. package/react/hooks/useSyncExternalStore.js +1 -1
  135. package/react/internal/cache/QueryReference.d.ts +16 -0
  136. package/react/internal/cache/QueryReference.js +1 -1
  137. package/react/internal/cache/QueryReference.js.map +1 -1
  138. package/react/internal/internal.cjs +2 -2
  139. package/react/internal/internal.cjs.map +1 -1
  140. package/react/internal/internal.cjs.native.js +2 -2
  141. package/react/parser/index.d.ts +7 -0
  142. package/react/parser/index.js +17 -7
  143. package/react/parser/index.js.map +1 -1
  144. package/react/parser/parser.cjs +28 -7
  145. package/react/parser/parser.cjs.map +1 -1
  146. package/react/parser/parser.cjs.native.js +28 -7
  147. package/react/query-preloader/createQueryPreloader.d.ts +2 -1
  148. package/react/query-preloader/createQueryPreloader.js +14 -5
  149. package/react/query-preloader/createQueryPreloader.js.map +1 -1
  150. package/react/react.cjs +40 -6
  151. package/react/react.cjs.map +1 -1
  152. package/react/react.cjs.native.js +40 -6
  153. package/react/types/types.d.ts +303 -9
  154. package/react/types/types.documentation.d.ts +2 -3
  155. package/react/types/types.documentation.js.map +1 -1
  156. package/react/types/types.js.map +1 -1
  157. package/testing/core/core.cjs +2 -2
  158. package/testing/core/core.cjs.map +1 -1
  159. package/testing/core/core.cjs.native.js +2 -2
  160. package/testing/core/mocking/mockLink.js +2 -2
  161. package/testing/react/MockedProvider.d.ts +27 -1
  162. package/testing/react/MockedProvider.js +16 -10
  163. package/testing/react/MockedProvider.js.map +1 -1
  164. package/testing/testing.cjs +42 -11
  165. package/testing/testing.cjs.map +1 -1
  166. package/testing/testing.cjs.native.js +42 -11
  167. package/utilities/deprecation/index.d.ts +11 -0
  168. package/utilities/deprecation/index.js +28 -0
  169. package/utilities/deprecation/index.js.map +1 -0
  170. package/utilities/globals/globals.cjs +1 -1
  171. package/utilities/globals/globals.cjs.map +1 -1
  172. package/utilities/globals/globals.cjs.native.js +1 -1
  173. package/utilities/graphql/DocumentTransform.js +1 -1
  174. package/utilities/graphql/directives.js +7 -7
  175. package/utilities/graphql/fragments.js +3 -3
  176. package/utilities/graphql/getFromAST.js +8 -8
  177. package/utilities/graphql/storeUtils.js +1 -1
  178. package/utilities/graphql/transform.js +2 -2
  179. package/utilities/utilities.cjs +22 -22
  180. package/utilities/utilities.cjs.map +1 -1
  181. package/utilities/utilities.cjs.native.js +22 -22
  182. package/version.js +1 -1
@@ -127,6 +127,31 @@ function directiveIsNonreactive(dir) {
127
127
  return dir.name.value === "nonreactive";
128
128
  }
129
129
 
130
+ var slot = new optimism.Slot();
131
+ function isMuted(name) {
132
+ return (slot.getValue() || []).includes(name);
133
+ }
134
+ function muteDeprecations(name) {
135
+ var args = [];
136
+ for (var _i = 1; _i < arguments.length; _i++) {
137
+ args[_i - 1] = arguments[_i];
138
+ }
139
+ return slot.withValue.apply(slot, tslib.__spreadArray([Array.isArray(name) ? name : [name]], args, false));
140
+ }
141
+ function warnRemovedOption(options, name, callSite, recommendation) {
142
+ if (recommendation === void 0) { recommendation = "Please remove this option."; }
143
+ warnDeprecated(name, function () {
144
+ if (name in options) {
145
+ globalThis.__DEV__ !== false && globals.invariant.warn(91, callSite, name, recommendation);
146
+ }
147
+ });
148
+ }
149
+ function warnDeprecated(name, cb) {
150
+ if (!isMuted(name)) {
151
+ cb();
152
+ }
153
+ }
154
+
130
155
  var ApolloCache = (function () {
131
156
  function ApolloCache() {
132
157
  this.assumeImmutableResults = false;
@@ -167,8 +192,14 @@ var ApolloCache = (function () {
167
192
  return false;
168
193
  };
169
194
  ApolloCache.prototype.readQuery = function (options, optimistic) {
195
+ var _this = this;
170
196
  if (optimistic === void 0) { optimistic = !!options.optimistic; }
171
- return this.read(tslib.__assign(tslib.__assign({}, options), { rootId: options.id || "ROOT_QUERY", optimistic: optimistic }));
197
+ if (globalThis.__DEV__ !== false) {
198
+ warnRemovedOption(options, "canonizeResults", "cache.readQuery");
199
+ }
200
+ return muteDeprecations("canonizeResults", function () {
201
+ return _this.read(tslib.__assign(tslib.__assign({}, options), { rootId: options.id || "ROOT_QUERY", optimistic: optimistic }));
202
+ });
172
203
  };
173
204
  ApolloCache.prototype.watchFragment = function (options) {
174
205
  var _this = this;
@@ -210,8 +241,14 @@ var ApolloCache = (function () {
210
241
  });
211
242
  };
212
243
  ApolloCache.prototype.readFragment = function (options, optimistic) {
244
+ var _this = this;
213
245
  if (optimistic === void 0) { optimistic = !!options.optimistic; }
214
- return this.read(tslib.__assign(tslib.__assign({}, options), { query: this.getFragmentDoc(options.fragment, options.fragmentName), rootId: options.id, optimistic: optimistic }));
246
+ if (globalThis.__DEV__ !== false) {
247
+ warnRemovedOption(options, "canonizeResults", "cache.readFragment");
248
+ }
249
+ return muteDeprecations("canonizeResults", function () {
250
+ return _this.read(tslib.__assign(tslib.__assign({}, options), { query: _this.getFragmentDoc(options.fragment, options.fragmentName), rootId: options.id, optimistic: optimistic }));
251
+ });
215
252
  };
216
253
  ApolloCache.prototype.writeQuery = function (_a) {
217
254
  var id = _a.id, data = _a.data, options = tslib.__rest(_a, ["id", "data"]);
@@ -229,9 +266,14 @@ var ApolloCache = (function () {
229
266
  }));
230
267
  };
231
268
  ApolloCache.prototype.updateQuery = function (options, update) {
269
+ if (globalThis.__DEV__ !== false) {
270
+ warnRemovedOption(options, "canonizeResults", "cache.updateQuery");
271
+ }
232
272
  return this.batch({
233
273
  update: function (cache) {
234
- var value = cache.readQuery(options);
274
+ var value = muteDeprecations("canonizeResults", function () {
275
+ return cache.readQuery(options);
276
+ });
235
277
  var data = update(value);
236
278
  if (data === void 0 || data === null)
237
279
  return value;
@@ -241,9 +283,14 @@ var ApolloCache = (function () {
241
283
  });
242
284
  };
243
285
  ApolloCache.prototype.updateFragment = function (options, update) {
286
+ if (globalThis.__DEV__ !== false) {
287
+ warnRemovedOption(options, "canonizeResults", "cache.updateFragment");
288
+ }
244
289
  return this.batch({
245
290
  update: function (cache) {
246
- var value = cache.readFragment(options);
291
+ var value = muteDeprecations("canonizeResults", function () {
292
+ return cache.readFragment(options);
293
+ });
247
294
  var data = update(value);
248
295
  if (data === void 0 || data === null)
249
296
  return value;
@@ -1507,8 +1554,7 @@ var Policies = (function () {
1507
1554
  }
1508
1555
  });
1509
1556
  };
1510
- Policies.prototype.updateTypePolicy = function (typename, incoming) {
1511
- var _this = this;
1557
+ Policies.prototype.updateTypePolicy = function (typename, incoming, existingFieldPolicies) {
1512
1558
  var existing = this.getTypePolicy(typename);
1513
1559
  var keyFields = incoming.keyFields, fields = incoming.fields;
1514
1560
  function setMerge(existing, merge) {
@@ -1526,7 +1572,10 @@ var Policies = (function () {
1526
1572
  : existing.keyFn;
1527
1573
  if (fields) {
1528
1574
  Object.keys(fields).forEach(function (fieldName) {
1529
- var existing = _this.getFieldPolicy(typename, fieldName, true);
1575
+ var existing = existingFieldPolicies[fieldName];
1576
+ if (!existing || (existing === null || existing === void 0 ? void 0 : existing.typename) !== typename) {
1577
+ existing = existingFieldPolicies[fieldName] = { typename: typename };
1578
+ }
1530
1579
  var incoming = fields[fieldName];
1531
1580
  if (typeof incoming === "function") {
1532
1581
  existing.read = incoming;
@@ -1605,16 +1654,14 @@ var Policies = (function () {
1605
1654
  var inbox = this.toBeAdded[typename];
1606
1655
  if (inbox && inbox.length) {
1607
1656
  inbox.splice(0).forEach(function (policy) {
1608
- _this.updateTypePolicy(typename, policy);
1657
+ _this.updateTypePolicy(typename, policy, _this.typePolicies[typename].fields);
1609
1658
  });
1610
1659
  }
1611
1660
  return this.typePolicies[typename];
1612
1661
  };
1613
- Policies.prototype.getFieldPolicy = function (typename, fieldName, createIfMissing) {
1662
+ Policies.prototype.getFieldPolicy = function (typename, fieldName) {
1614
1663
  if (typename) {
1615
- var fieldPolicies = this.getTypePolicy(typename).fields;
1616
- return (fieldPolicies[fieldName] ||
1617
- (createIfMissing && (fieldPolicies[fieldName] = Object.create(null))));
1664
+ return this.getTypePolicy(typename).fields[fieldName];
1618
1665
  }
1619
1666
  };
1620
1667
  Policies.prototype.getSupertypeSet = function (subtype, createIfMissing) {
@@ -1675,12 +1722,12 @@ var Policies = (function () {
1675
1722
  return false;
1676
1723
  };
1677
1724
  Policies.prototype.hasKeyArgs = function (typename, fieldName) {
1678
- var policy = this.getFieldPolicy(typename, fieldName, false);
1725
+ var policy = this.getFieldPolicy(typename, fieldName);
1679
1726
  return !!(policy && policy.keyFn);
1680
1727
  };
1681
1728
  Policies.prototype.getStoreFieldName = function (fieldSpec) {
1682
1729
  var typename = fieldSpec.typename, fieldName = fieldSpec.fieldName;
1683
- var policy = this.getFieldPolicy(typename, fieldName, false);
1730
+ var policy = this.getFieldPolicy(typename, fieldName);
1684
1731
  var storeFieldName;
1685
1732
  var keyFn = policy && policy.keyFn;
1686
1733
  if (keyFn && typename) {
@@ -1729,7 +1776,7 @@ var Policies = (function () {
1729
1776
  var storeFieldName = this.getStoreFieldName(options);
1730
1777
  var fieldName = fieldNameFromStoreName(storeFieldName);
1731
1778
  var existing = context.store.getFieldValue(objectOrReference, storeFieldName);
1732
- var policy = this.getFieldPolicy(options.typename, fieldName, false);
1779
+ var policy = this.getFieldPolicy(options.typename, fieldName);
1733
1780
  var read = policy && policy.read;
1734
1781
  if (read) {
1735
1782
  var readOptions = makeFieldFunctionOptions(this, objectOrReference, options, context, context.store.getStorage(utilities.isReference(objectOrReference) ?
@@ -1743,11 +1790,11 @@ var Policies = (function () {
1743
1790
  return existing;
1744
1791
  };
1745
1792
  Policies.prototype.getReadFunction = function (typename, fieldName) {
1746
- var policy = this.getFieldPolicy(typename, fieldName, false);
1793
+ var policy = this.getFieldPolicy(typename, fieldName);
1747
1794
  return policy && policy.read;
1748
1795
  };
1749
1796
  Policies.prototype.getMergeFunction = function (parentTypename, fieldName, childTypename) {
1750
- var policy = this.getFieldPolicy(parentTypename, fieldName, false);
1797
+ var policy = this.getFieldPolicy(parentTypename, fieldName);
1751
1798
  var merge = policy && policy.merge;
1752
1799
  if (!merge && childTypename) {
1753
1800
  policy = this.getTypePolicy(childTypename);
@@ -2256,6 +2303,10 @@ var InMemoryCache = (function (_super) {
2256
2303
  _this.assumeImmutableResults = true;
2257
2304
  _this.makeVar = makeVar;
2258
2305
  _this.txCount = 0;
2306
+ if (globalThis.__DEV__ !== false) {
2307
+ warnRemovedOption(config, "addTypename", "InMemoryCache", "Please remove the `addTypename` option when initializing `InMemoryCache`.");
2308
+ warnRemovedOption(config, "canonizeResults", "InMemoryCache", "Please remove the `canonizeResults` option when initializing `InMemoryCache`.");
2309
+ }
2259
2310
  _this.config = normalizeConfig(config);
2260
2311
  _this.addTypename = !!_this.config.addTypename;
2261
2312
  _this.policies = new Policies({
@@ -2279,6 +2330,8 @@ var InMemoryCache = (function (_super) {
2279
2330
  var _this = this;
2280
2331
  var previousReader = this.storeReader;
2281
2332
  var fragments = this.config.fragments;
2333
+ this.addTypenameTransform.resetCache();
2334
+ fragments === null || fragments === void 0 ? void 0 : fragments.resetCaches();
2282
2335
  this.storeWriter = new StoreWriter(this, (this.storeReader = new StoreReader({
2283
2336
  cache: this,
2284
2337
  addTypename: this.addTypename,
@@ -2317,6 +2370,9 @@ var InMemoryCache = (function (_super) {
2317
2370
  return (optimistic ? this.optimisticData : this.data).extract();
2318
2371
  };
2319
2372
  InMemoryCache.prototype.read = function (options) {
2373
+ if (globalThis.__DEV__ !== false) {
2374
+ warnRemovedOption(options, "canonizeResults", "cache.read");
2375
+ }
2320
2376
  var
2321
2377
  _a = options.returnPartialData,
2322
2378
  returnPartialData = _a === void 0 ? false : _a;
@@ -2360,6 +2416,9 @@ var InMemoryCache = (function (_super) {
2360
2416
  }
2361
2417
  };
2362
2418
  InMemoryCache.prototype.diff = function (options) {
2419
+ if (globalThis.__DEV__ !== false) {
2420
+ warnRemovedOption(options, "canonizeResults", "cache.diff");
2421
+ }
2363
2422
  return this.storeReader.diffQueryAgainstStore(tslib.__assign(tslib.__assign({}, options), { store: options.optimistic ? this.optimisticData : this.data, rootId: options.id || "ROOT_QUERY", config: this.config }));
2364
2423
  };
2365
2424
  InMemoryCache.prototype.watch = function (watch) {
@@ -2379,11 +2438,8 @@ var InMemoryCache = (function (_super) {
2379
2438
  };
2380
2439
  };
2381
2440
  InMemoryCache.prototype.gc = function (options) {
2382
- var _a;
2383
2441
  utilities.canonicalStringify.reset();
2384
2442
  utilities.print.reset();
2385
- this.addTypenameTransform.resetCache();
2386
- (_a = this.config.fragments) === null || _a === void 0 ? void 0 : _a.resetCaches();
2387
2443
  var ids = this.optimisticData.gc();
2388
2444
  if (options && !this.txCount) {
2389
2445
  if (options.resetResultCache) {
@@ -2537,8 +2593,9 @@ var InMemoryCache = (function (_super) {
2537
2593
  return document;
2538
2594
  };
2539
2595
  InMemoryCache.prototype.broadcastWatch = function (c, options) {
2596
+ var _this = this;
2540
2597
  var lastDiff = c.lastDiff;
2541
- var diff = this.diff(c);
2598
+ var diff = muteDeprecations("canonizeResults", function () { return _this.diff(c); });
2542
2599
  if (options) {
2543
2600
  if (c.optimistic && typeof options.optimistic === "string") {
2544
2601
  diff.fromOptimisticTransaction = true;
@@ -6,6 +6,7 @@ import { getApolloCacheMemoryInternals } from "../../utilities/caching/getMemory
6
6
  import { equalByQuery } from "../../core/equalByQuery.js";
7
7
  import { invariant } from "../../utilities/globals/index.js";
8
8
  import { maskFragment } from "../../masking/index.js";
9
+ import { muteDeprecations, warnRemovedOption, } from "../../utilities/deprecation/index.js";
9
10
  var ApolloCache = /** @class */ (function () {
10
11
  function ApolloCache() {
11
12
  this.assumeImmutableResults = false;
@@ -63,8 +64,14 @@ var ApolloCache = /** @class */ (function () {
63
64
  };
64
65
  // DataProxy API
65
66
  ApolloCache.prototype.readQuery = function (options, optimistic) {
67
+ var _this = this;
66
68
  if (optimistic === void 0) { optimistic = !!options.optimistic; }
67
- return this.read(__assign(__assign({}, options), { rootId: options.id || "ROOT_QUERY", optimistic: optimistic }));
69
+ if (globalThis.__DEV__ !== false) {
70
+ warnRemovedOption(options, "canonizeResults", "cache.readQuery");
71
+ }
72
+ return muteDeprecations("canonizeResults", function () {
73
+ return _this.read(__assign(__assign({}, options), { rootId: options.id || "ROOT_QUERY", optimistic: optimistic }));
74
+ });
68
75
  };
69
76
  /** {@inheritDoc @apollo/client!ApolloClient#watchFragment:member(1)} */
70
77
  ApolloCache.prototype.watchFragment = function (options) {
@@ -116,8 +123,14 @@ var ApolloCache = /** @class */ (function () {
116
123
  });
117
124
  };
118
125
  ApolloCache.prototype.readFragment = function (options, optimistic) {
126
+ var _this = this;
119
127
  if (optimistic === void 0) { optimistic = !!options.optimistic; }
120
- return this.read(__assign(__assign({}, options), { query: this.getFragmentDoc(options.fragment, options.fragmentName), rootId: options.id, optimistic: optimistic }));
128
+ if (globalThis.__DEV__ !== false) {
129
+ warnRemovedOption(options, "canonizeResults", "cache.readFragment");
130
+ }
131
+ return muteDeprecations("canonizeResults", function () {
132
+ return _this.read(__assign(__assign({}, options), { query: _this.getFragmentDoc(options.fragment, options.fragmentName), rootId: options.id, optimistic: optimistic }));
133
+ });
121
134
  };
122
135
  ApolloCache.prototype.writeQuery = function (_a) {
123
136
  var id = _a.id, data = _a.data, options = __rest(_a, ["id", "data"]);
@@ -135,9 +148,14 @@ var ApolloCache = /** @class */ (function () {
135
148
  }));
136
149
  };
137
150
  ApolloCache.prototype.updateQuery = function (options, update) {
151
+ if (globalThis.__DEV__ !== false) {
152
+ warnRemovedOption(options, "canonizeResults", "cache.updateQuery");
153
+ }
138
154
  return this.batch({
139
155
  update: function (cache) {
140
- var value = cache.readQuery(options);
156
+ var value = muteDeprecations("canonizeResults", function () {
157
+ return cache.readQuery(options);
158
+ });
141
159
  var data = update(value);
142
160
  if (data === void 0 || data === null)
143
161
  return value;
@@ -147,9 +165,14 @@ var ApolloCache = /** @class */ (function () {
147
165
  });
148
166
  };
149
167
  ApolloCache.prototype.updateFragment = function (options, update) {
168
+ if (globalThis.__DEV__ !== false) {
169
+ warnRemovedOption(options, "canonizeResults", "cache.updateFragment");
170
+ }
150
171
  return this.batch({
151
172
  update: function (cache) {
152
- var value = cache.readFragment(options);
173
+ var value = muteDeprecations("canonizeResults", function () {
174
+ return cache.readFragment(options);
175
+ });
153
176
  var data = update(value);
154
177
  if (data === void 0 || data === null)
155
178
  return value;
@@ -1 +1 @@
1
- {"version":3,"file":"cache.js","sourceRoot":"","sources":["../../../src/cache/core/cache.ts"],"names":[],"mappings":";AAKA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAQhC,OAAO,EACL,UAAU,EACV,UAAU,EAEV,qBAAqB,EACrB,wBAAwB,EACxB,cAAc,GACf,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,6BAA6B,EAAE,MAAM,+CAA+C,CAAC;AAM9F,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAqEtD;IAAA;QACkB,2BAAsB,GAAY,KAAK,CAAC;QA2OxD,oEAAoE;QACpE,qDAAqD;QAC7C,mBAAc,GAAG,IAAI,CAAC,wBAAwB,EAAE;YACtD,GAAG,EACD,UAAU,CAAC,8BAA8B,CAAC;4EACO;YACnD,KAAK,EAAE,SAAS;SACjB,CAAC,CAAC;IAiFL,CAAC;IAvQC,4EAA4E;IAC5E,6EAA6E;IAC7E,2EAA2E;IACpE,oCAAc,GAArB,UAAsB,YAAoB;QACxC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,oBAAoB;IAEpB,0EAA0E;IAC1E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CAAoB,OAAO,CAAC,CAAC;gBAC7D,IAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;gBAC3B,IAAI,IAAI,KAAK,KAAK,CAAC,IAAI,IAAI,KAAK,IAAI;oBAAE,OAAO,KAAK,CAAC;gBACnD,KAAK,CAAC,aAAa,uBAAyB,OAAO,KAAE,IAAI,MAAA,IAAG,CAAC;gBAC7D,OAAO,IAAI,CAAC;YACd,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAUH,kBAAC;AAAD,CAAC,AApUD,IAoUC;;AAED,IAAI,OAAO,EAAE,CAAC;IACZ,WAAW,CAAC,SAAS,CAAC,kBAAkB,GAAG,6BAA6B,CAAC;AAC3E,CAAC","sourcesContent":["import type {\n DocumentNode,\n FragmentDefinitionNode,\n InlineFragmentNode,\n} from \"graphql\";\nimport { wrap } from \"optimism\";\n\nimport type {\n StoreObject,\n Reference,\n DeepPartial,\n NoInfer,\n} from \"../../utilities/index.js\";\nimport {\n Observable,\n cacheSizes,\n defaultCacheSizes,\n getFragmentDefinition,\n getFragmentQueryDocument,\n mergeDeepArray,\n} from \"../../utilities/index.js\";\nimport type { DataProxy } from \"./types/DataProxy.js\";\nimport type { Cache } from \"./types/Cache.js\";\nimport { WeakCache } from \"@wry/caches\";\nimport { getApolloCacheMemoryInternals } from \"../../utilities/caching/getMemoryInternals.js\";\nimport type {\n OperationVariables,\n TypedDocumentNode,\n} from \"../../core/types.js\";\nimport type { MissingTree } from \"./types/common.js\";\nimport { equalByQuery } from \"../../core/equalByQuery.js\";\nimport { invariant } from \"../../utilities/globals/index.js\";\nimport { maskFragment } from \"../../masking/index.js\";\nimport type {\n FragmentType,\n MaybeMasked,\n Unmasked,\n} from \"../../masking/index.js\";\n\nexport type Transaction<T> = (c: ApolloCache<T>) => void;\n\n/**\n * Watched fragment options.\n */\nexport interface WatchFragmentOptions<TData, TVars> {\n /**\n * A GraphQL fragment document parsed into an AST with the `gql`\n * template literal.\n *\n * @docGroup 1. Required options\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVars>;\n /**\n * An object containing a `__typename` and primary key fields\n * (such as `id`) identifying the entity object from which the fragment will\n * be retrieved, or a `{ __ref: \"...\" }` reference, or a `string` ID\n * (uncommon).\n *\n * @docGroup 1. Required options\n */\n from: StoreObject | Reference | FragmentType<NoInfer<TData>> | string;\n /**\n * Any variables that the GraphQL fragment may depend on.\n *\n * @docGroup 2. Cache options\n */\n variables?: TVars;\n /**\n * The name of the fragment defined in the fragment document.\n *\n * Required if the fragment document includes more than one fragment,\n * optional otherwise.\n *\n * @docGroup 2. Cache options\n */\n fragmentName?: string;\n /**\n * If `true`, `watchFragment` returns optimistic results.\n *\n * The default value is `true`.\n *\n * @docGroup 2. Cache options\n */\n optimistic?: boolean;\n}\n\n/**\n * Watched fragment results.\n */\nexport type WatchFragmentResult<TData> =\n | {\n data: MaybeMasked<TData>;\n complete: true;\n missing?: never;\n }\n | {\n data: DeepPartial<MaybeMasked<TData>>;\n complete: false;\n missing: MissingTree;\n };\n\nexport abstract class ApolloCache<TSerialized> implements DataProxy {\n public readonly assumeImmutableResults: boolean = false;\n\n // required to implement\n // core API\n public abstract read<TData = any, TVariables = any>(\n query: Cache.ReadOptions<TVariables, TData>\n ): Unmasked<TData> | null;\n public abstract write<TData = any, TVariables = any>(\n write: Cache.WriteOptions<TData, TVariables>\n ): Reference | undefined;\n public abstract diff<T>(query: Cache.DiffOptions): Cache.DiffResult<T>;\n public abstract watch<TData = any, TVariables = any>(\n watch: Cache.WatchOptions<TData, TVariables>\n ): () => void;\n\n // Empty the cache and restart all current watches (unless\n // options.discardWatches is true).\n public abstract reset(options?: Cache.ResetOptions): Promise<void>;\n\n // Remove whole objects from the cache by passing just options.id, or\n // specific fields by passing options.field and/or options.args. If no\n // options.args are provided, all fields matching options.field (even\n // those with arguments) will be removed. Returns true iff any data was\n // removed from the cache.\n public abstract evict(options: Cache.EvictOptions): boolean;\n\n // initializer / offline / ssr API\n /**\n * Replaces existing state in the cache (if any) with the values expressed by\n * `serializedState`.\n *\n * Called when hydrating a cache (server side rendering, or offline storage),\n * and also (potentially) during hot reloads.\n */\n public abstract restore(\n serializedState: TSerialized\n ): ApolloCache<TSerialized>;\n\n /**\n * Exposes the cache's complete state, in a serializable format for later restoration.\n */\n public abstract extract(optimistic?: boolean): TSerialized;\n\n // Optimistic API\n\n public abstract removeOptimistic(id: string): void;\n\n // Data masking API\n\n // Used by data masking to determine if an inline fragment with a type\n // condition matches a given typename.\n //\n // If not implemented by a cache subclass, data masking will effectively be\n // disabled since we will not be able to accurately determine if a given type\n // condition for a union or interface matches a particular type.\n public fragmentMatches?(\n fragment: InlineFragmentNode,\n typename: string\n ): boolean;\n\n // Function used to lookup a fragment when a fragment definition is not part\n // of the GraphQL document. This is useful for caches, such as InMemoryCache,\n // that register fragments ahead of time so they can be referenced by name.\n public lookupFragment(fragmentName: string): FragmentDefinitionNode | null {\n return null;\n }\n\n // Transactional API\n\n // The batch method is intended to replace/subsume both performTransaction\n // and recordOptimisticTransaction, but performTransaction came first, so we\n // provide a default batch implementation that's just another way of calling\n // performTransaction. Subclasses of ApolloCache (such as InMemoryCache) can\n // override the batch method to do more interesting things with its options.\n public batch<U>(options: Cache.BatchOptions<this, U>): U {\n const optimisticId =\n typeof options.optimistic === \"string\" ? options.optimistic\n : options.optimistic === false ? null\n : void 0;\n let updateResult: U;\n this.performTransaction(\n () => (updateResult = options.update(this)),\n optimisticId\n );\n return updateResult!;\n }\n\n public abstract performTransaction(\n transaction: Transaction<TSerialized>,\n // Although subclasses may implement recordOptimisticTransaction\n // however they choose, the default implementation simply calls\n // performTransaction with a string as the second argument, allowing\n // performTransaction to handle both optimistic and non-optimistic\n // (broadcast-batching) transactions. Passing null for optimisticId is\n // also allowed, and indicates that performTransaction should apply\n // the transaction non-optimistically (ignoring optimistic data).\n optimisticId?: string | null\n ): void;\n\n public recordOptimisticTransaction(\n transaction: Transaction<TSerialized>,\n optimisticId: string\n ) {\n this.performTransaction(transaction, optimisticId);\n }\n\n // Optional API\n\n // Called once per input document, allowing the cache to make static changes\n // to the query, such as adding __typename fields.\n public transformDocument(document: DocumentNode): DocumentNode {\n return document;\n }\n\n // Called before each ApolloLink request, allowing the cache to make dynamic\n // changes to the query, such as filling in missing fragment definitions.\n public transformForLink(document: DocumentNode): DocumentNode {\n return document;\n }\n\n public identify(object: StoreObject | Reference): string | undefined {\n return;\n }\n\n public gc(): string[] {\n return [];\n }\n\n public modify<Entity extends Record<string, any> = Record<string, any>>(\n options: Cache.ModifyOptions<Entity>\n ): boolean {\n return false;\n }\n\n // DataProxy API\n public readQuery<QueryType, TVariables = any>(\n options: Cache.ReadQueryOptions<QueryType, TVariables>,\n optimistic = !!options.optimistic\n ): Unmasked<QueryType> | null {\n return this.read({\n ...options,\n rootId: options.id || \"ROOT_QUERY\",\n optimistic,\n });\n }\n\n /** {@inheritDoc @apollo/client!ApolloClient#watchFragment:member(1)} */\n public watchFragment<TData = any, TVars = OperationVariables>(\n options: WatchFragmentOptions<TData, TVars>\n ): Observable<WatchFragmentResult<TData>> {\n const {\n fragment,\n fragmentName,\n from,\n optimistic = true,\n ...otherOptions\n } = options;\n const query = this.getFragmentDoc(fragment, fragmentName);\n // While our TypeScript types do not allow for `undefined` as a valid\n // `from`, its possible `useFragment` gives us an `undefined` since it\n // calls` cache.identify` and provides that value to `from`. We are\n // adding this fix here however to ensure those using plain JavaScript\n // and using `cache.identify` themselves will avoid seeing the obscure\n // warning.\n const id =\n typeof from === \"undefined\" || typeof from === \"string\" ?\n from\n : this.identify(from);\n const dataMasking = !!(options as any)[Symbol.for(\"apollo.dataMasking\")];\n\n if (__DEV__) {\n const actualFragmentName =\n fragmentName || getFragmentDefinition(fragment).name.value;\n\n if (!id) {\n invariant.warn(\n \"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.\",\n actualFragmentName\n );\n }\n }\n\n const diffOptions: Cache.DiffOptions<TData, TVars> = {\n ...otherOptions,\n returnPartialData: true,\n id,\n query,\n optimistic,\n };\n\n let latestDiff: DataProxy.DiffResult<TData> | undefined;\n\n return new Observable((observer) => {\n return this.watch<TData, TVars>({\n ...diffOptions,\n immediate: true,\n callback: (diff) => {\n const data =\n dataMasking ?\n maskFragment(diff.result, fragment, this, fragmentName)\n : diff.result;\n\n if (\n // Always ensure we deliver the first result\n latestDiff &&\n equalByQuery(\n query,\n { data: latestDiff.result },\n { data },\n // TODO: Fix the type on WatchFragmentOptions so that TVars\n // extends OperationVariables\n options.variables as OperationVariables\n )\n ) {\n return;\n }\n\n const result = {\n data,\n complete: !!diff.complete,\n } as WatchFragmentResult<TData>;\n\n if (diff.missing) {\n result.missing = mergeDeepArray(\n diff.missing.map((error) => error.missing)\n );\n }\n\n latestDiff = { ...diff, result: data };\n observer.next(result);\n },\n });\n });\n }\n\n // Make sure we compute the same (===) fragment query document every\n // time we receive the same fragment in readFragment.\n private getFragmentDoc = wrap(getFragmentQueryDocument, {\n max:\n cacheSizes[\"cache.fragmentQueryDocuments\"] ||\n defaultCacheSizes[\"cache.fragmentQueryDocuments\"],\n cache: WeakCache,\n });\n\n public readFragment<FragmentType, TVariables = any>(\n options: Cache.ReadFragmentOptions<FragmentType, TVariables>,\n optimistic = !!options.optimistic\n ): Unmasked<FragmentType> | null {\n return this.read({\n ...options,\n query: this.getFragmentDoc(options.fragment, options.fragmentName),\n rootId: options.id,\n optimistic,\n });\n }\n\n public writeQuery<TData = any, TVariables = any>({\n id,\n data,\n ...options\n }: Cache.WriteQueryOptions<TData, TVariables>): Reference | undefined {\n return this.write(\n Object.assign(options, {\n dataId: id || \"ROOT_QUERY\",\n result: data,\n })\n );\n }\n\n public writeFragment<TData = any, TVariables = any>({\n id,\n data,\n fragment,\n fragmentName,\n ...options\n }: Cache.WriteFragmentOptions<TData, TVariables>): Reference | undefined {\n return this.write(\n Object.assign(options, {\n query: this.getFragmentDoc(fragment, fragmentName),\n dataId: id,\n result: data,\n })\n );\n }\n\n public updateQuery<TData = any, TVariables = any>(\n options: Cache.UpdateQueryOptions<TData, TVariables>,\n update: (data: Unmasked<TData> | null) => Unmasked<TData> | null | void\n ): Unmasked<TData> | null {\n return this.batch({\n update(cache) {\n const value = cache.readQuery<TData, TVariables>(options);\n const data = update(value);\n if (data === void 0 || data === null) return value;\n cache.writeQuery<TData, TVariables>({ ...options, data });\n return data;\n },\n });\n }\n\n public updateFragment<TData = any, TVariables = any>(\n options: Cache.UpdateFragmentOptions<TData, TVariables>,\n update: (data: Unmasked<TData> | null) => Unmasked<TData> | null | void\n ): Unmasked<TData> | null {\n return this.batch({\n update(cache) {\n const value = cache.readFragment<TData, TVariables>(options);\n const data = update(value);\n if (data === void 0 || data === null) return value;\n cache.writeFragment<TData, TVariables>({ ...options, data });\n return data;\n },\n });\n }\n\n /**\n * @experimental\n * @internal\n * This is not a stable API - it is used in development builds to expose\n * information to the DevTools.\n * Use at your own risk!\n */\n public getMemoryInternals?: typeof getApolloCacheMemoryInternals;\n}\n\nif (__DEV__) {\n ApolloCache.prototype.getMemoryInternals = getApolloCacheMemoryInternals;\n}\n"]}
1
+ {"version":3,"file":"cache.js","sourceRoot":"","sources":["../../../src/cache/core/cache.ts"],"names":[],"mappings":";AAKA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAQhC,OAAO,EACL,UAAU,EACV,UAAU,EAEV,qBAAqB,EACrB,wBAAwB,EACxB,cAAc,GACf,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,6BAA6B,EAAE,MAAM,+CAA+C,CAAC;AAM9F,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAMtD,OAAO,EACL,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,sCAAs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IAAI;oBAAE,OAAO,KAAK,CAAC;gBACnD,KAAK,CAAC,aAAa,uBAAyB,OAAO,KAAE,IAAI,MAAA,IAAG,CAAC;gBAC7D,OAAO,IAAI,CAAC;YACd,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAUH,kBAAC;AAAD,CAAC,AA5VD,IA4VC;;AAED,IAAI,OAAO,EAAE,CAAC;IACZ,WAAW,CAAC,SAAS,CAAC,kBAAkB,GAAG,6BAA6B,CAAC;AAC3E,CAAC","sourcesContent":["import type {\n DocumentNode,\n FragmentDefinitionNode,\n InlineFragmentNode,\n} from \"graphql\";\nimport { wrap } from \"optimism\";\n\nimport type {\n StoreObject,\n Reference,\n DeepPartial,\n NoInfer,\n} from \"../../utilities/index.js\";\nimport {\n Observable,\n cacheSizes,\n defaultCacheSizes,\n getFragmentDefinition,\n getFragmentQueryDocument,\n mergeDeepArray,\n} from \"../../utilities/index.js\";\nimport type { DataProxy } from \"./types/DataProxy.js\";\nimport type { Cache } from \"./types/Cache.js\";\nimport { WeakCache } from \"@wry/caches\";\nimport { getApolloCacheMemoryInternals } from \"../../utilities/caching/getMemoryInternals.js\";\nimport type {\n OperationVariables,\n TypedDocumentNode,\n} from \"../../core/types.js\";\nimport type { MissingTree } from \"./types/common.js\";\nimport { equalByQuery } from \"../../core/equalByQuery.js\";\nimport { invariant } from \"../../utilities/globals/index.js\";\nimport { maskFragment } from \"../../masking/index.js\";\nimport type {\n FragmentType,\n MaybeMasked,\n Unmasked,\n} from \"../../masking/index.js\";\nimport {\n muteDeprecations,\n warnRemovedOption,\n} from \"../../utilities/deprecation/index.js\";\n\nexport type Transaction<T> = (c: ApolloCache<T>) => void;\n\n/**\n * Watched fragment options.\n */\nexport interface WatchFragmentOptions<TData, TVars> {\n /**\n * A GraphQL fragment document parsed into an AST with the `gql`\n * template literal.\n *\n * @docGroup 1. Required options\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVars>;\n /**\n * An object containing a `__typename` and primary key fields\n * (such as `id`) identifying the entity object from which the fragment will\n * be retrieved, or a `{ __ref: \"...\" }` reference, or a `string` ID\n * (uncommon).\n *\n * @docGroup 1. Required options\n */\n from: StoreObject | Reference | FragmentType<NoInfer<TData>> | string;\n /**\n * Any variables that the GraphQL fragment may depend on.\n *\n * @docGroup 2. Cache options\n */\n variables?: TVars;\n /**\n * The name of the fragment defined in the fragment document.\n *\n * Required if the fragment document includes more than one fragment,\n * optional otherwise.\n *\n * @docGroup 2. Cache options\n */\n fragmentName?: string;\n /**\n * If `true`, `watchFragment` returns optimistic results.\n *\n * The default value is `true`.\n *\n * @docGroup 2. Cache options\n */\n optimistic?: boolean;\n}\n\n/**\n * Watched fragment results.\n */\nexport type WatchFragmentResult<TData> =\n | {\n data: MaybeMasked<TData>;\n complete: true;\n missing?: never;\n }\n | {\n data: DeepPartial<MaybeMasked<TData>>;\n complete: false;\n missing: MissingTree;\n };\n\nexport abstract class ApolloCache<TSerialized> implements DataProxy {\n public readonly assumeImmutableResults: boolean = false;\n\n // required to implement\n // core API\n public abstract read<TData = any, TVariables = any>(\n query: Cache.ReadOptions<TVariables, TData>\n ): Unmasked<TData> | null;\n public abstract write<TData = any, TVariables = any>(\n write: Cache.WriteOptions<TData, TVariables>\n ): Reference | undefined;\n public abstract diff<T>(query: Cache.DiffOptions): Cache.DiffResult<T>;\n public abstract watch<TData = any, TVariables = any>(\n watch: Cache.WatchOptions<TData, TVariables>\n ): () => void;\n\n // Empty the cache and restart all current watches (unless\n // options.discardWatches is true).\n public abstract reset(options?: Cache.ResetOptions): Promise<void>;\n\n // Remove whole objects from the cache by passing just options.id, or\n // specific fields by passing options.field and/or options.args. If no\n // options.args are provided, all fields matching options.field (even\n // those with arguments) will be removed. Returns true iff any data was\n // removed from the cache.\n public abstract evict(options: Cache.EvictOptions): boolean;\n\n // initializer / offline / ssr API\n /**\n * Replaces existing state in the cache (if any) with the values expressed by\n * `serializedState`.\n *\n * Called when hydrating a cache (server side rendering, or offline storage),\n * and also (potentially) during hot reloads.\n */\n public abstract restore(\n serializedState: TSerialized\n ): ApolloCache<TSerialized>;\n\n /**\n * Exposes the cache's complete state, in a serializable format for later restoration.\n */\n public abstract extract(optimistic?: boolean): TSerialized;\n\n // Optimistic API\n\n public abstract removeOptimistic(id: string): void;\n\n // Data masking API\n\n // Used by data masking to determine if an inline fragment with a type\n // condition matches a given typename.\n //\n // If not implemented by a cache subclass, data masking will effectively be\n // disabled since we will not be able to accurately determine if a given type\n // condition for a union or interface matches a particular type.\n public fragmentMatches?(\n fragment: InlineFragmentNode,\n typename: string\n ): boolean;\n\n // Function used to lookup a fragment when a fragment definition is not part\n // of the GraphQL document. This is useful for caches, such as InMemoryCache,\n // that register fragments ahead of time so they can be referenced by name.\n public lookupFragment(fragmentName: string): FragmentDefinitionNode | null {\n return null;\n }\n\n // Transactional API\n\n // The batch method is intended to replace/subsume both performTransaction\n // and recordOptimisticTransaction, but performTransaction came first, so we\n // provide a default batch implementation that's just another way of calling\n // performTransaction. Subclasses of ApolloCache (such as InMemoryCache) can\n // override the batch method to do more interesting things with its options.\n public batch<U>(options: Cache.BatchOptions<this, U>): U {\n const optimisticId =\n typeof options.optimistic === \"string\" ? options.optimistic\n : options.optimistic === false ? null\n : void 0;\n let updateResult: U;\n this.performTransaction(\n () => (updateResult = options.update(this)),\n optimisticId\n );\n return updateResult!;\n }\n\n public abstract performTransaction(\n transaction: Transaction<TSerialized>,\n // Although subclasses may implement recordOptimisticTransaction\n // however they choose, the default implementation simply calls\n // performTransaction with a string as the second argument, allowing\n // performTransaction to handle both optimistic and non-optimistic\n // (broadcast-batching) transactions. Passing null for optimisticId is\n // also allowed, and indicates that performTransaction should apply\n // the transaction non-optimistically (ignoring optimistic data).\n optimisticId?: string | null\n ): void;\n\n public recordOptimisticTransaction(\n transaction: Transaction<TSerialized>,\n optimisticId: string\n ) {\n this.performTransaction(transaction, optimisticId);\n }\n\n // Optional API\n\n // Called once per input document, allowing the cache to make static changes\n // to the query, such as adding __typename fields.\n public transformDocument(document: DocumentNode): DocumentNode {\n return document;\n }\n\n // Called before each ApolloLink request, allowing the cache to make dynamic\n // changes to the query, such as filling in missing fragment definitions.\n public transformForLink(document: DocumentNode): DocumentNode {\n return document;\n }\n\n public identify(object: StoreObject | Reference): string | undefined {\n return;\n }\n\n public gc(): string[] {\n return [];\n }\n\n public modify<Entity extends Record<string, any> = Record<string, any>>(\n options: Cache.ModifyOptions<Entity>\n ): boolean {\n return false;\n }\n\n // DataProxy API\n public readQuery<QueryType, TVariables = any>(\n options: Cache.ReadQueryOptions<QueryType, TVariables>,\n optimistic = !!options.optimistic\n ): Unmasked<QueryType> | null {\n if (__DEV__) {\n warnRemovedOption(options, \"canonizeResults\", \"cache.readQuery\");\n }\n\n return muteDeprecations(\"canonizeResults\", () =>\n this.read({\n ...options,\n rootId: options.id || \"ROOT_QUERY\",\n optimistic,\n })\n );\n }\n\n /** {@inheritDoc @apollo/client!ApolloClient#watchFragment:member(1)} */\n public watchFragment<TData = any, TVars = OperationVariables>(\n options: WatchFragmentOptions<TData, TVars>\n ): Observable<WatchFragmentResult<TData>> {\n const {\n fragment,\n fragmentName,\n from,\n optimistic = true,\n ...otherOptions\n } = options;\n const query = this.getFragmentDoc(fragment, fragmentName);\n // While our TypeScript types do not allow for `undefined` as a valid\n // `from`, its possible `useFragment` gives us an `undefined` since it\n // calls` cache.identify` and provides that value to `from`. We are\n // adding this fix here however to ensure those using plain JavaScript\n // and using `cache.identify` themselves will avoid seeing the obscure\n // warning.\n const id =\n typeof from === \"undefined\" || typeof from === \"string\" ?\n from\n : this.identify(from);\n const dataMasking = !!(options as any)[Symbol.for(\"apollo.dataMasking\")];\n\n if (__DEV__) {\n const actualFragmentName =\n fragmentName || getFragmentDefinition(fragment).name.value;\n\n if (!id) {\n invariant.warn(\n \"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.\",\n actualFragmentName\n );\n }\n }\n\n const diffOptions: Cache.DiffOptions<TData, TVars> = {\n ...otherOptions,\n returnPartialData: true,\n id,\n query,\n optimistic,\n };\n\n let latestDiff: DataProxy.DiffResult<TData> | undefined;\n\n return new Observable((observer) => {\n return this.watch<TData, TVars>({\n ...diffOptions,\n immediate: true,\n callback: (diff) => {\n const data =\n dataMasking ?\n maskFragment(diff.result, fragment, this, fragmentName)\n : diff.result;\n\n if (\n // Always ensure we deliver the first result\n latestDiff &&\n equalByQuery(\n query,\n { data: latestDiff.result },\n { data },\n // TODO: Fix the type on WatchFragmentOptions so that TVars\n // extends OperationVariables\n options.variables as OperationVariables\n )\n ) {\n return;\n }\n\n const result = {\n data,\n complete: !!diff.complete,\n } as WatchFragmentResult<TData>;\n\n if (diff.missing) {\n result.missing = mergeDeepArray(\n diff.missing.map((error) => error.missing)\n );\n }\n\n latestDiff = { ...diff, result: data };\n observer.next(result);\n },\n });\n });\n }\n\n // Make sure we compute the same (===) fragment query document every\n // time we receive the same fragment in readFragment.\n private getFragmentDoc = wrap(getFragmentQueryDocument, {\n max:\n cacheSizes[\"cache.fragmentQueryDocuments\"] ||\n defaultCacheSizes[\"cache.fragmentQueryDocuments\"],\n cache: WeakCache,\n });\n\n public readFragment<FragmentType, TVariables = any>(\n options: Cache.ReadFragmentOptions<FragmentType, TVariables>,\n optimistic = !!options.optimistic\n ): Unmasked<FragmentType> | null {\n if (__DEV__) {\n warnRemovedOption(options, \"canonizeResults\", \"cache.readFragment\");\n }\n\n return muteDeprecations(\"canonizeResults\", () =>\n this.read({\n ...options,\n query: this.getFragmentDoc(options.fragment, options.fragmentName),\n rootId: options.id,\n optimistic,\n })\n );\n }\n\n public writeQuery<TData = any, TVariables = any>({\n id,\n data,\n ...options\n }: Cache.WriteQueryOptions<TData, TVariables>): Reference | undefined {\n return this.write(\n Object.assign(options, {\n dataId: id || \"ROOT_QUERY\",\n result: data,\n })\n );\n }\n\n public writeFragment<TData = any, TVariables = any>({\n id,\n data,\n fragment,\n fragmentName,\n ...options\n }: Cache.WriteFragmentOptions<TData, TVariables>): Reference | undefined {\n return this.write(\n Object.assign(options, {\n query: this.getFragmentDoc(fragment, fragmentName),\n dataId: id,\n result: data,\n })\n );\n }\n\n public updateQuery<TData = any, TVariables = any>(\n options: Cache.UpdateQueryOptions<TData, TVariables>,\n update: (data: Unmasked<TData> | null) => Unmasked<TData> | null | void\n ): Unmasked<TData> | null {\n if (__DEV__) {\n warnRemovedOption(options, \"canonizeResults\", \"cache.updateQuery\");\n }\n\n return this.batch({\n update(cache) {\n const value = muteDeprecations(\"canonizeResults\", () =>\n cache.readQuery<TData, TVariables>(options)\n );\n const data = update(value);\n if (data === void 0 || data === null) return value;\n cache.writeQuery<TData, TVariables>({ ...options, data });\n return data;\n },\n });\n }\n\n public updateFragment<TData = any, TVariables = any>(\n options: Cache.UpdateFragmentOptions<TData, TVariables>,\n update: (data: Unmasked<TData> | null) => Unmasked<TData> | null | void\n ): Unmasked<TData> | null {\n if (__DEV__) {\n warnRemovedOption(options, \"canonizeResults\", \"cache.updateFragment\");\n }\n\n return this.batch({\n update(cache) {\n const value = muteDeprecations(\"canonizeResults\", () =>\n cache.readFragment<TData, TVariables>(options)\n );\n const data = update(value);\n if (data === void 0 || data === null) return value;\n cache.writeFragment<TData, TVariables>({ ...options, data });\n return data;\n },\n });\n }\n\n /**\n * @experimental\n * @internal\n * This is not a stable API - it is used in development builds to expose\n * information to the DevTools.\n * Use at your own risk!\n */\n public getMemoryInternals?: typeof getApolloCacheMemoryInternals;\n}\n\nif (__DEV__) {\n ApolloCache.prototype.getMemoryInternals = getApolloCacheMemoryInternals;\n}\n"]}
@@ -10,11 +10,11 @@ export declare namespace Cache {
10
10
  optimistic: boolean;
11
11
  returnPartialData?: boolean;
12
12
  /**
13
+ * Whether to canonize cache results before returning them. Canonization takes some extra time, but it speeds up future deep equality comparisons. Defaults to false.
14
+ *
13
15
  * @deprecated
14
- * Using `canonizeResults` can result in memory leaks so we generally do not
15
- * recommend using this option anymore.
16
- * A future version of Apollo Client will contain a similar feature without
17
- * the risk of memory leaks.
16
+ *
17
+ * Using `canonizeResults` can result in memory leaks so we generally do not recommend using this option. `canonizeResults` will be removed in Apollo Client 4.0.
18
18
  */
19
19
  canonizeResults?: boolean;
20
20
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Cache.js","sourceRoot":"","sources":["../../../../src/cache/core/types/Cache.ts"],"names":[],"mappings":"AAKA,MAAM,KAAW,KAAK,CA8GrB;AA9GD,WAAiB,KAAK;AA8GtB,CAAC,EA9GgB,KAAK,KAAL,KAAK,QA8GrB","sourcesContent":["import { DataProxy } from \"./DataProxy.js\";\nimport type { AllFieldsModifier, Modifiers } from \"./common.js\";\nimport type { ApolloCache } from \"../cache.js\";\nimport type { Unmasked } from \"../../../masking/index.js\";\n\nexport namespace Cache {\n export type WatchCallback<TData = any> = (\n diff: Cache.DiffResult<TData>,\n lastDiff?: Cache.DiffResult<TData>\n ) => void;\n\n export interface ReadOptions<TVariables = any, TData = any>\n extends DataProxy.Query<TVariables, TData> {\n rootId?: string;\n previousResult?: any;\n optimistic: boolean;\n returnPartialData?: boolean;\n /**\n * @deprecated\n * Using `canonizeResults` can result in memory leaks so we generally do not\n * recommend using this option anymore.\n * A future version of Apollo Client will contain a similar feature without\n * the risk of memory leaks.\n */\n canonizeResults?: boolean;\n }\n\n export interface WriteOptions<TResult = any, TVariables = any>\n extends Omit<DataProxy.Query<TVariables, TResult>, \"id\">,\n Omit<DataProxy.WriteOptions<TResult>, \"data\"> {\n dataId?: string;\n result: Unmasked<TResult>;\n }\n\n export interface DiffOptions<TData = any, TVariables = any>\n extends Omit<ReadOptions<TVariables, TData>, \"rootId\"> {\n // The DiffOptions interface is currently just an alias for\n // ReadOptions, though DiffOptions used to be responsible for\n // declaring the returnPartialData option.\n }\n\n export interface WatchOptions<TData = any, TVariables = any>\n extends DiffOptions<TData, TVariables> {\n watcher?: object;\n immediate?: boolean;\n callback: WatchCallback<TData>;\n lastDiff?: DiffResult<TData>;\n }\n\n export interface EvictOptions {\n id?: string;\n fieldName?: string;\n args?: Record<string, any>;\n broadcast?: boolean;\n }\n\n // Although you can call cache.reset() without options, its behavior can be\n // configured by passing a Cache.ResetOptions object.\n export interface ResetOptions {\n discardWatches?: boolean;\n }\n\n export interface ModifyOptions<\n Entity extends Record<string, any> = Record<string, any>,\n > {\n id?: string;\n fields: Modifiers<Entity> | AllFieldsModifier<Entity>;\n optimistic?: boolean;\n broadcast?: boolean;\n }\n\n export interface BatchOptions<\n TCache extends ApolloCache<any>,\n TUpdateResult = void,\n > {\n // Same as the first parameter of performTransaction, except the cache\n // argument will have the subclass type rather than ApolloCache.\n update(cache: TCache): TUpdateResult;\n\n // Passing a string for this option creates a new optimistic layer, with the\n // given string as its layer.id, just like passing a string for the\n // optimisticId parameter of performTransaction. Passing true is the same as\n // passing undefined to performTransaction (running the batch operation\n // against the current top layer of the cache), and passing false is the\n // same as passing null (running the operation against root/non-optimistic\n // cache data).\n optimistic?: string | boolean;\n\n // If you specify the ID of an optimistic layer using this option, that\n // layer will be removed as part of the batch transaction, triggering at\n // most one broadcast for both the transaction and the removal of the layer.\n // Note: this option is needed because calling cache.removeOptimistic during\n // the transaction function may not be not safe, since any modifications to\n // cache layers may be discarded after the transaction finishes.\n removeOptimistic?: string;\n\n // If you want to find out which watched queries were invalidated during\n // this batch operation, pass this optional callback function. Returning\n // false from the callback will prevent broadcasting this result.\n onWatchUpdated?: (\n this: TCache,\n watch: Cache.WatchOptions,\n diff: Cache.DiffResult<any>,\n lastDiff?: Cache.DiffResult<any> | undefined\n ) => any;\n }\n\n export import DiffResult = DataProxy.DiffResult;\n export import ReadQueryOptions = DataProxy.ReadQueryOptions;\n export import ReadFragmentOptions = DataProxy.ReadFragmentOptions;\n export import WriteQueryOptions = DataProxy.WriteQueryOptions;\n export import WriteFragmentOptions = DataProxy.WriteFragmentOptions;\n export import UpdateQueryOptions = DataProxy.UpdateQueryOptions;\n export import UpdateFragmentOptions = DataProxy.UpdateFragmentOptions;\n export import Fragment = DataProxy.Fragment;\n}\n"]}
1
+ {"version":3,"file":"Cache.js","sourceRoot":"","sources":["../../../../src/cache/core/types/Cache.ts"],"names":[],"mappings":"AAKA,MAAM,KAAW,KAAK,CAwGrB;AAxGD,WAAiB,KAAK;AAwGtB,CAAC,EAxGgB,KAAK,KAAL,KAAK,QAwGrB","sourcesContent":["import { DataProxy } from \"./DataProxy.js\";\nimport type { AllFieldsModifier, Modifiers } from \"./common.js\";\nimport type { ApolloCache } from \"../cache.js\";\nimport type { Unmasked } from \"../../../masking/index.js\";\n\nexport namespace Cache {\n export type WatchCallback<TData = any> = (\n diff: Cache.DiffResult<TData>,\n lastDiff?: Cache.DiffResult<TData>\n ) => void;\n\n export interface ReadOptions<TVariables = any, TData = any>\n extends DataProxy.Query<TVariables, TData> {\n rootId?: string;\n previousResult?: any;\n optimistic: boolean;\n returnPartialData?: boolean;\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#canonizeResults:member} */\n canonizeResults?: boolean;\n }\n\n export interface WriteOptions<TResult = any, TVariables = any>\n extends Omit<DataProxy.Query<TVariables, TResult>, \"id\">,\n Omit<DataProxy.WriteOptions<TResult>, \"data\"> {\n dataId?: string;\n result: Unmasked<TResult>;\n }\n\n export interface DiffOptions<TData = any, TVariables = any>\n extends Omit<ReadOptions<TVariables, TData>, \"rootId\"> {\n // The DiffOptions interface is currently just an alias for\n // ReadOptions, though DiffOptions used to be responsible for\n // declaring the returnPartialData option.\n }\n\n export interface WatchOptions<TData = any, TVariables = any>\n extends DiffOptions<TData, TVariables> {\n watcher?: object;\n immediate?: boolean;\n callback: WatchCallback<TData>;\n lastDiff?: DiffResult<TData>;\n }\n\n export interface EvictOptions {\n id?: string;\n fieldName?: string;\n args?: Record<string, any>;\n broadcast?: boolean;\n }\n\n // Although you can call cache.reset() without options, its behavior can be\n // configured by passing a Cache.ResetOptions object.\n export interface ResetOptions {\n discardWatches?: boolean;\n }\n\n export interface ModifyOptions<\n Entity extends Record<string, any> = Record<string, any>,\n > {\n id?: string;\n fields: Modifiers<Entity> | AllFieldsModifier<Entity>;\n optimistic?: boolean;\n broadcast?: boolean;\n }\n\n export interface BatchOptions<\n TCache extends ApolloCache<any>,\n TUpdateResult = void,\n > {\n // Same as the first parameter of performTransaction, except the cache\n // argument will have the subclass type rather than ApolloCache.\n update(cache: TCache): TUpdateResult;\n\n // Passing a string for this option creates a new optimistic layer, with the\n // given string as its layer.id, just like passing a string for the\n // optimisticId parameter of performTransaction. Passing true is the same as\n // passing undefined to performTransaction (running the batch operation\n // against the current top layer of the cache), and passing false is the\n // same as passing null (running the operation against root/non-optimistic\n // cache data).\n optimistic?: string | boolean;\n\n // If you specify the ID of an optimistic layer using this option, that\n // layer will be removed as part of the batch transaction, triggering at\n // most one broadcast for both the transaction and the removal of the layer.\n // Note: this option is needed because calling cache.removeOptimistic during\n // the transaction function may not be not safe, since any modifications to\n // cache layers may be discarded after the transaction finishes.\n removeOptimistic?: string;\n\n // If you want to find out which watched queries were invalidated during\n // this batch operation, pass this optional callback function. Returning\n // false from the callback will prevent broadcasting this result.\n onWatchUpdated?: (\n this: TCache,\n watch: Cache.WatchOptions,\n diff: Cache.DiffResult<any>,\n lastDiff?: Cache.DiffResult<any> | undefined\n ) => any;\n }\n\n export import DiffResult = DataProxy.DiffResult;\n export import ReadQueryOptions = DataProxy.ReadQueryOptions;\n export import ReadFragmentOptions = DataProxy.ReadFragmentOptions;\n export import WriteQueryOptions = DataProxy.WriteQueryOptions;\n export import WriteFragmentOptions = DataProxy.WriteFragmentOptions;\n export import UpdateQueryOptions = DataProxy.UpdateQueryOptions;\n export import UpdateFragmentOptions = DataProxy.UpdateFragmentOptions;\n export import Fragment = DataProxy.Fragment;\n}\n"]}
@@ -64,7 +64,7 @@ export declare namespace DataProxy {
64
64
  *
65
65
  * @deprecated
66
66
  *
67
- * Using `canonizeResults` can result in memory leaks so we generally do not recommend using this option anymore. A future version of Apollo Client will contain a similar feature without the risk of memory leaks.
67
+ * Using `canonizeResults` can result in memory leaks so we generally do not recommend using this option. `canonizeResults` will be removed in Apollo Client 4.0.
68
68
  */
69
69
  canonizeResults?: boolean;
70
70
  }
@@ -85,7 +85,7 @@ export declare namespace DataProxy {
85
85
  *
86
86
  * @deprecated
87
87
  *
88
- * Using `canonizeResults` can result in memory leaks so we generally do not recommend using this option anymore. A future version of Apollo Client will contain a similar feature without the risk of memory leaks.
88
+ * Using `canonizeResults` can result in memory leaks so we generally do not recommend using this option. `canonizeResults` will be removed in Apollo Client 4.0.
89
89
  */
90
90
  canonizeResults?: boolean;
91
91
  }
@@ -14,6 +14,7 @@ import { makeVar, forgetCache, recallCache } from "./reactiveVars.js";
14
14
  import { Policies } from "./policies.js";
15
15
  import { hasOwn, normalizeConfig, shouldCanonizeResults } from "./helpers.js";
16
16
  import { getInMemoryCacheMemoryInternals } from "../../utilities/caching/getMemoryInternals.js";
17
+ import { muteDeprecations, warnRemovedOption, } from "../../utilities/deprecation/index.js";
17
18
  var InMemoryCache = /** @class */ (function (_super) {
18
19
  __extends(InMemoryCache, _super);
19
20
  function InMemoryCache(config) {
@@ -26,6 +27,10 @@ var InMemoryCache = /** @class */ (function (_super) {
26
27
  _this.assumeImmutableResults = true;
27
28
  _this.makeVar = makeVar;
28
29
  _this.txCount = 0;
30
+ if (globalThis.__DEV__ !== false) {
31
+ warnRemovedOption(config, "addTypename", "InMemoryCache", "Please remove the `addTypename` option when initializing `InMemoryCache`.");
32
+ warnRemovedOption(config, "canonizeResults", "InMemoryCache", "Please remove the `canonizeResults` option when initializing `InMemoryCache`.");
33
+ }
29
34
  _this.config = normalizeConfig(config);
30
35
  _this.addTypename = !!_this.config.addTypename;
31
36
  _this.policies = new Policies({
@@ -57,6 +62,8 @@ var InMemoryCache = /** @class */ (function (_super) {
57
62
  var _this = this;
58
63
  var previousReader = this.storeReader;
59
64
  var fragments = this.config.fragments;
65
+ this.addTypenameTransform.resetCache();
66
+ fragments === null || fragments === void 0 ? void 0 : fragments.resetCaches();
60
67
  // The StoreWriter is mostly stateless and so doesn't really need to be
61
68
  // reset, but it does need to have its writer.storeReader reference updated,
62
69
  // so it's simpler to update this.storeWriter as well.
@@ -112,6 +119,9 @@ var InMemoryCache = /** @class */ (function (_super) {
112
119
  return (optimistic ? this.optimisticData : this.data).extract();
113
120
  };
114
121
  InMemoryCache.prototype.read = function (options) {
122
+ if (globalThis.__DEV__ !== false) {
123
+ warnRemovedOption(options, "canonizeResults", "cache.read");
124
+ }
115
125
  var
116
126
  // Since read returns data or null, without any additional metadata
117
127
  // about whether/where there might have been missing fields, the
@@ -183,6 +193,9 @@ var InMemoryCache = /** @class */ (function (_super) {
183
193
  }
184
194
  };
185
195
  InMemoryCache.prototype.diff = function (options) {
196
+ if (globalThis.__DEV__ !== false) {
197
+ warnRemovedOption(options, "canonizeResults", "cache.diff");
198
+ }
186
199
  return this.storeReader.diffQueryAgainstStore(__assign(__assign({}, options), { store: options.optimistic ? this.optimisticData : this.data, rootId: options.id || "ROOT_QUERY", config: this.config }));
187
200
  };
188
201
  InMemoryCache.prototype.watch = function (watch) {
@@ -218,11 +231,8 @@ var InMemoryCache = /** @class */ (function (_super) {
218
231
  };
219
232
  };
220
233
  InMemoryCache.prototype.gc = function (options) {
221
- var _a;
222
234
  canonicalStringify.reset();
223
235
  print.reset();
224
- this.addTypenameTransform.resetCache();
225
- (_a = this.config.fragments) === null || _a === void 0 ? void 0 : _a.resetCaches();
226
236
  var ids = this.optimisticData.gc();
227
237
  if (options && !this.txCount) {
228
238
  if (options.resetResultCache) {
@@ -447,6 +457,7 @@ var InMemoryCache = /** @class */ (function (_super) {
447
457
  // broadcasting it, but this wrapping approach allows us to skip both
448
458
  // the recomputation and the broadcast, in most cases.
449
459
  InMemoryCache.prototype.broadcastWatch = function (c, options) {
460
+ var _this = this;
450
461
  var lastDiff = c.lastDiff;
451
462
  // Both WatchOptions and DiffOptions extend ReadOptions, and DiffOptions
452
463
  // currently requires no additional properties, so we can use c (a
@@ -454,7 +465,7 @@ var InMemoryCache = /** @class */ (function (_super) {
454
465
  // object, and without having to enumerate the relevant properties (query,
455
466
  // variables, etc.) explicitly. There will be some additional properties
456
467
  // (lastDiff, callback, etc.), but cache.diff ignores them.
457
- var diff = this.diff(c);
468
+ var diff = muteDeprecations("canonizeResults", function () { return _this.diff(c); });
458
469
  if (options) {
459
470
  if (c.optimistic && typeof options.optimistic === "string") {
460
471
  diff.fromOptimisticTransaction = true;