@apollo/client 3.9.0-alpha.5 → 3.9.0-beta.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 (154) hide show
  1. package/.changeset/dirty-tigers-matter.md +13 -0
  2. package/.changeset/mighty-coats-check.md +47 -0
  3. package/.changeset/pre.json +9 -1
  4. package/.changeset/rare-snakes-melt.md +24 -0
  5. package/.changeset/swift-zoos-collect.md +19 -0
  6. package/.changeset/thick-tips-cry.md +9 -0
  7. package/.changeset/tough-timers-begin.md +8 -0
  8. package/.changeset/unlucky-rats-decide.md +5 -0
  9. package/.changeset/wet-forks-rhyme.md +5 -0
  10. package/CHANGELOG.md +118 -4
  11. package/apollo-client.cjs +329 -82
  12. package/apollo-client.cjs.map +1 -1
  13. package/apollo-client.min.cjs +1 -1
  14. package/cache/cache.cjs +78 -6
  15. package/cache/cache.cjs.map +1 -1
  16. package/cache/cache.cjs.native.js +78 -6
  17. package/cache/core/cache.d.ts +9 -0
  18. package/cache/core/cache.js +11 -2
  19. package/cache/core/cache.js.map +1 -1
  20. package/cache/core/types/Cache.d.ts +7 -0
  21. package/cache/core/types/Cache.js.map +1 -1
  22. package/cache/core/types/DataProxy.d.ts +12 -0
  23. package/cache/core/types/DataProxy.js.map +1 -1
  24. package/cache/core/types/common.d.ts +4 -0
  25. package/cache/core/types/common.js.map +1 -1
  26. package/cache/inmemory/fragmentRegistry.js +19 -3
  27. package/cache/inmemory/fragmentRegistry.js.map +1 -1
  28. package/cache/inmemory/inMemoryCache.d.ts +9 -0
  29. package/cache/inmemory/inMemoryCache.js +8 -2
  30. package/cache/inmemory/inMemoryCache.js.map +1 -1
  31. package/cache/inmemory/readFromStore.js +7 -3
  32. package/cache/inmemory/readFromStore.js.map +1 -1
  33. package/cache/inmemory/types.d.ts +18 -0
  34. package/cache/inmemory/types.js.map +1 -1
  35. package/core/ApolloClient.d.ts +9 -0
  36. package/core/ApolloClient.js +4 -0
  37. package/core/ApolloClient.js.map +1 -1
  38. package/core/ObservableQuery.d.ts +2 -0
  39. package/core/ObservableQuery.js +7 -1
  40. package/core/ObservableQuery.js.map +1 -1
  41. package/core/QueryInfo.d.ts +1 -0
  42. package/core/QueryInfo.js +4 -0
  43. package/core/QueryInfo.js.map +1 -1
  44. package/core/QueryManager.d.ts +1 -1
  45. package/core/QueryManager.js +15 -10
  46. package/core/QueryManager.js.map +1 -1
  47. package/core/core.cjs +99 -12
  48. package/core/core.cjs.map +1 -1
  49. package/core/core.cjs.native.js +99 -12
  50. package/core/watchQueryOptions.d.ts +20 -1
  51. package/core/watchQueryOptions.js.map +1 -1
  52. package/dev/dev.cjs +1 -1
  53. package/dev/dev.cjs.map +1 -1
  54. package/dev/dev.cjs.native.js +1 -1
  55. package/link/core/ApolloLink.d.ts +15 -0
  56. package/link/core/ApolloLink.js +8 -4
  57. package/link/core/ApolloLink.js.map +1 -1
  58. package/link/core/core.cjs +8 -4
  59. package/link/core/core.cjs.map +1 -1
  60. package/link/core/core.cjs.native.js +8 -4
  61. package/link/persisted-queries/index.d.ts +11 -1
  62. package/link/persisted-queries/index.js +28 -3
  63. package/link/persisted-queries/index.js.map +1 -1
  64. package/link/persisted-queries/persisted-queries.cjs +26 -3
  65. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  66. package/link/persisted-queries/persisted-queries.cjs.native.js +26 -3
  67. package/link/remove-typename/remove-typename.cjs +18 -2
  68. package/link/remove-typename/remove-typename.cjs.map +1 -1
  69. package/link/remove-typename/remove-typename.cjs.native.js +18 -2
  70. package/link/remove-typename/removeTypenameFromVariables.d.ts +9 -1
  71. package/link/remove-typename/removeTypenameFromVariables.js +19 -3
  72. package/link/remove-typename/removeTypenameFromVariables.js.map +1 -1
  73. package/package.json +21 -21
  74. package/react/cache/QueryReference.d.ts +11 -5
  75. package/react/cache/QueryReference.js +91 -55
  76. package/react/cache/QueryReference.js.map +1 -1
  77. package/react/hooks/hooks.cjs +112 -52
  78. package/react/hooks/hooks.cjs.map +1 -1
  79. package/react/hooks/hooks.cjs.native.js +112 -52
  80. package/react/hooks/index.d.ts +2 -0
  81. package/react/hooks/index.js +1 -0
  82. package/react/hooks/index.js.map +1 -1
  83. package/react/hooks/useBackgroundQuery.d.ts +12 -9
  84. package/react/hooks/useBackgroundQuery.js +1 -1
  85. package/react/hooks/useBackgroundQuery.js.map +1 -1
  86. package/react/hooks/useLoadableQuery.d.ts +1 -1
  87. package/react/hooks/useLoadableQuery.js +1 -1
  88. package/react/hooks/useLoadableQuery.js.map +1 -1
  89. package/react/hooks/useQueryRefHandlers.d.ts +35 -0
  90. package/react/hooks/useQueryRefHandlers.js +48 -0
  91. package/react/hooks/useQueryRefHandlers.js.map +1 -0
  92. package/react/hooks/useReadQuery.js +8 -2
  93. package/react/hooks/useReadQuery.js.map +1 -1
  94. package/react/index.d.ts +2 -0
  95. package/react/index.js +1 -0
  96. package/react/index.js.map +1 -1
  97. package/react/parser/index.js +6 -3
  98. package/react/parser/index.js.map +1 -1
  99. package/react/parser/parser.cjs +11 -3
  100. package/react/parser/parser.cjs.map +1 -1
  101. package/react/parser/parser.cjs.native.js +11 -3
  102. package/react/query-preloader/createQueryPreloader.d.ts +253 -0
  103. package/react/query-preloader/createQueryPreloader.js +29 -0
  104. package/react/query-preloader/createQueryPreloader.js.map +1 -0
  105. package/react/react.cjs +248 -1
  106. package/react/react.cjs.map +1 -1
  107. package/react/react.cjs.native.js +248 -1
  108. package/react/types/types.d.ts +6 -0
  109. package/react/types/types.js.map +1 -1
  110. package/testing/internal/index.d.ts +4 -0
  111. package/testing/internal/index.js +2 -0
  112. package/testing/internal/index.js.map +1 -1
  113. package/testing/internal/renderHelpers.d.ts +12 -0
  114. package/testing/internal/renderHelpers.js +22 -0
  115. package/testing/internal/renderHelpers.js.map +1 -0
  116. package/testing/internal/scenarios/index.d.ts +41 -0
  117. package/testing/internal/scenarios/index.js +46 -0
  118. package/testing/internal/scenarios/index.js.map +1 -0
  119. package/testing/matchers/index.js +2 -0
  120. package/testing/matchers/index.js.map +1 -1
  121. package/testing/matchers/toBeDisposed.d.ts +3 -0
  122. package/testing/matchers/toBeDisposed.js +26 -0
  123. package/testing/matchers/toBeDisposed.js.map +1 -0
  124. package/utilities/caching/caches.d.ts +34 -0
  125. package/utilities/caching/caches.js +64 -0
  126. package/utilities/caching/caches.js.map +1 -0
  127. package/utilities/caching/getMemoryInternals.d.ts +76 -0
  128. package/utilities/caching/getMemoryInternals.js +112 -0
  129. package/utilities/caching/getMemoryInternals.js.map +1 -0
  130. package/utilities/caching/index.d.ts +4 -0
  131. package/utilities/caching/index.js +3 -0
  132. package/utilities/caching/index.js.map +1 -0
  133. package/utilities/caching/sizes.d.ts +261 -0
  134. package/utilities/caching/sizes.js +27 -0
  135. package/utilities/caching/sizes.js.map +1 -0
  136. package/utilities/common/canUse.js +1 -1
  137. package/utilities/common/canUse.js.map +1 -1
  138. package/utilities/common/canonicalStringify.js +8 -2
  139. package/utilities/common/canonicalStringify.js.map +1 -1
  140. package/utilities/globals/globals.cjs +1 -1
  141. package/utilities/globals/globals.cjs.map +1 -1
  142. package/utilities/globals/globals.cjs.native.js +1 -1
  143. package/utilities/graphql/DocumentTransform.d.ts +14 -1
  144. package/utilities/graphql/DocumentTransform.js +9 -5
  145. package/utilities/graphql/DocumentTransform.js.map +1 -1
  146. package/utilities/graphql/print.js +6 -2
  147. package/utilities/graphql/print.js.map +1 -1
  148. package/utilities/index.d.ts +2 -0
  149. package/utilities/index.js +1 -0
  150. package/utilities/index.js.map +1 -1
  151. package/utilities/utilities.cjs +57 -9
  152. package/utilities/utilities.cjs.map +1 -1
  153. package/utilities/utilities.cjs.native.js +57 -9
  154. package/version.js +1 -1
package/core/core.cjs CHANGED
@@ -7,7 +7,6 @@ var globals = require('../utilities/globals');
7
7
  var core = require('../link/core');
8
8
  var http = require('../link/http');
9
9
  var equal = require('@wry/equality');
10
- var caches = require('@wry/caches');
11
10
  var utilities = require('../utilities');
12
11
  var cache = require('../cache');
13
12
  var errors = require('../errors');
@@ -21,7 +20,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
21
20
 
22
21
  var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
23
22
 
24
- var version = "3.9.0-alpha.5";
23
+ var version = "3.9.0-beta.0";
25
24
 
26
25
  function isNonNullObject(obj) {
27
26
  return obj !== null && typeof obj === "object";
@@ -276,6 +275,9 @@ var ObservableQuery = (function (_super) {
276
275
  var subscription = _this.subscribe(observer);
277
276
  });
278
277
  };
278
+ ObservableQuery.prototype.resetDiff = function () {
279
+ this.queryInfo.resetDiff();
280
+ };
279
281
  ObservableQuery.prototype.getCurrentResult = function (saveAsLastResult) {
280
282
  if (saveAsLastResult === void 0) { saveAsLastResult = true; }
281
283
  var lastResult = this.getLastResult(true);
@@ -576,8 +578,10 @@ var ObservableQuery = (function (_super) {
576
578
  var info = pollingInfo || (this.pollingInfo = {});
577
579
  info.interval = pollInterval;
578
580
  var maybeFetch = function () {
581
+ var _a, _b;
579
582
  if (_this.pollingInfo) {
580
- if (!isNetworkRequestInFlight(_this.queryInfo.networkStatus)) {
583
+ if (!isNetworkRequestInFlight(_this.queryInfo.networkStatus) &&
584
+ !((_b = (_a = _this.options).skipPollAttempt) === null || _b === void 0 ? void 0 : _b.call(_a))) {
581
585
  _this.reobserve({
582
586
  fetchPolicy: _this.options.initialFetchPolicy === "no-cache" ?
583
587
  "no-cache"
@@ -1130,6 +1134,9 @@ var QueryInfo = (function () {
1130
1134
  cancelNotifyTimeout(this);
1131
1135
  this.dirty = false;
1132
1136
  };
1137
+ QueryInfo.prototype.resetDiff = function () {
1138
+ this.lastDiff = void 0;
1139
+ };
1133
1140
  QueryInfo.prototype.getDiff = function () {
1134
1141
  var options = this.getDiffOptions();
1135
1142
  if (this.lastDiff && equal.equal(options, this.lastDiff.options)) {
@@ -1338,6 +1345,7 @@ function shouldWriteResult(result, errorPolicy) {
1338
1345
  }
1339
1346
 
1340
1347
  var hasOwnProperty = Object.prototype.hasOwnProperty;
1348
+ var IGNORE = Object.create(null);
1341
1349
  var QueryManager = (function () {
1342
1350
  function QueryManager(_a) {
1343
1351
  var cache = _a.cache, link = _a.link, defaultOptions = _a.defaultOptions, documentTransform = _a.documentTransform, _b = _a.queryDeduplication, queryDeduplication = _b === void 0 ? false : _b, onBroadcast = _a.onBroadcast, _c = _a.ssrMode, ssrMode = _c === void 0 ? false : _c, _d = _a.clientAwareness, clientAwareness = _d === void 0 ? {} : _d, localState = _a.localState, _e = _a.assumeImmutableResults, assumeImmutableResults = _e === void 0 ? !!cache.assumeImmutableResults : _e, defaultContext = _a.defaultContext;
@@ -1345,7 +1353,8 @@ var QueryManager = (function () {
1345
1353
  this.clientAwareness = {};
1346
1354
  this.queries = new Map();
1347
1355
  this.fetchCancelFns = new Map();
1348
- this.transformCache = new caches.WeakCache( );
1356
+ this.transformCache = new utilities.AutoCleanedWeakCache(utilities.cacheSizes["queryManager.getDocumentInfo"] ||
1357
+ 2000 );
1349
1358
  this.queryIdCounter = 1;
1350
1359
  this.requestIdCounter = 1;
1351
1360
  this.mutationIdCounter = 1;
@@ -1391,7 +1400,7 @@ var QueryManager = (function () {
1391
1400
  var _b, _c;
1392
1401
  var mutation = _a.mutation, variables = _a.variables, optimisticResponse = _a.optimisticResponse, updateQueries = _a.updateQueries, _d = _a.refetchQueries, refetchQueries = _d === void 0 ? [] : _d, _e = _a.awaitRefetchQueries, awaitRefetchQueries = _e === void 0 ? false : _e, updateWithProxyFn = _a.update, onQueryUpdated = _a.onQueryUpdated, _f = _a.fetchPolicy, fetchPolicy = _f === void 0 ? ((_b = this.defaultOptions.mutate) === null || _b === void 0 ? void 0 : _b.fetchPolicy) || "network-only" : _f, _g = _a.errorPolicy, errorPolicy = _g === void 0 ? ((_c = this.defaultOptions.mutate) === null || _c === void 0 ? void 0 : _c.errorPolicy) || "none" : _g, keepRootFields = _a.keepRootFields, context = _a.context;
1393
1402
  return tslib.__awaiter(this, void 0, void 0, function () {
1394
- var mutationId, hasClientExports, mutationStoreValue, self;
1403
+ var mutationId, hasClientExports, mutationStoreValue, isOptimistic, self;
1395
1404
  return tslib.__generator(this, function (_h) {
1396
1405
  switch (_h.label) {
1397
1406
  case 0:
@@ -1414,7 +1423,7 @@ var QueryManager = (function () {
1414
1423
  loading: true,
1415
1424
  error: null,
1416
1425
  });
1417
- if (optimisticResponse) {
1426
+ isOptimistic = optimisticResponse &&
1418
1427
  this.markMutationOptimistic(optimisticResponse, {
1419
1428
  mutationId: mutationId,
1420
1429
  document: mutation,
@@ -1426,11 +1435,10 @@ var QueryManager = (function () {
1426
1435
  update: updateWithProxyFn,
1427
1436
  keepRootFields: keepRootFields,
1428
1437
  });
1429
- }
1430
1438
  this.broadcastQueries();
1431
1439
  self = this;
1432
1440
  return [2 , new Promise(function (resolve, reject) {
1433
- return utilities.asyncMap(self.getObservableFromLink(mutation, tslib.__assign(tslib.__assign({}, context), { optimisticResponse: optimisticResponse }), variables, false), function (result) {
1441
+ return utilities.asyncMap(self.getObservableFromLink(mutation, tslib.__assign(tslib.__assign({}, context), { optimisticResponse: isOptimistic ? optimisticResponse : void 0 }), variables, false), function (result) {
1434
1442
  if (utilities.graphQLResultHasError(result) && errorPolicy === "none") {
1435
1443
  throw new errors.ApolloError({
1436
1444
  graphQLErrors: utilities.getGraphQLErrorsFromResult(result),
@@ -1459,7 +1467,7 @@ var QueryManager = (function () {
1459
1467
  updateQueries: updateQueries,
1460
1468
  awaitRefetchQueries: awaitRefetchQueries,
1461
1469
  refetchQueries: refetchQueries,
1462
- removeOptimistic: optimisticResponse ? mutationId : void 0,
1470
+ removeOptimistic: isOptimistic ? mutationId : void 0,
1463
1471
  onQueryUpdated: onQueryUpdated,
1464
1472
  keepRootFields: keepRootFields,
1465
1473
  });
@@ -1475,7 +1483,7 @@ var QueryManager = (function () {
1475
1483
  mutationStoreValue.loading = false;
1476
1484
  mutationStoreValue.error = err;
1477
1485
  }
1478
- if (optimisticResponse) {
1486
+ if (isOptimistic) {
1479
1487
  self.cache.removeOptimistic(mutationId);
1480
1488
  }
1481
1489
  self.broadcastQueries();
@@ -1625,9 +1633,12 @@ var QueryManager = (function () {
1625
1633
  QueryManager.prototype.markMutationOptimistic = function (optimisticResponse, mutation) {
1626
1634
  var _this = this;
1627
1635
  var data = typeof optimisticResponse === "function" ?
1628
- optimisticResponse(mutation.variables)
1636
+ optimisticResponse(mutation.variables, { IGNORE: IGNORE })
1629
1637
  : optimisticResponse;
1630
- return this.cache.recordOptimisticTransaction(function (cache) {
1638
+ if (data === IGNORE) {
1639
+ return false;
1640
+ }
1641
+ this.cache.recordOptimisticTransaction(function (cache) {
1631
1642
  try {
1632
1643
  _this.markMutationResult(tslib.__assign(tslib.__assign({}, mutation), { result: { data: data } }), cache);
1633
1644
  }
@@ -1635,6 +1646,7 @@ var QueryManager = (function () {
1635
1646
  globalThis.__DEV__ !== false && globals.invariant.error(error);
1636
1647
  }
1637
1648
  }, mutation.mutationId);
1649
+ return true;
1638
1650
  };
1639
1651
  QueryManager.prototype.fetchQuery = function (queryId, options, networkStatus) {
1640
1652
  return this.fetchConcastWithInfo(queryId, options, networkStatus).concast
@@ -2246,6 +2258,78 @@ var QueryManager = (function () {
2246
2258
  return QueryManager;
2247
2259
  }());
2248
2260
 
2261
+ var cacheSizeSymbol = Symbol.for("apollo.cacheSize");
2262
+ var cacheSizes = tslib.__assign({}, globals.global[cacheSizeSymbol]);
2263
+
2264
+ var globalCaches = {};
2265
+ var getApolloClientMemoryInternals = globalThis.__DEV__ !== false ?
2266
+ _getApolloClientMemoryInternals
2267
+ : undefined;
2268
+ function getCurrentCacheSizes() {
2269
+ var defaults = {
2270
+ parser: 1000 ,
2271
+ canonicalStringify: 1000 ,
2272
+ print: 2000 ,
2273
+ "documentTransform.cache": 2000 ,
2274
+ "queryManager.getDocumentInfo": 2000 ,
2275
+ "PersistedQueryLink.persistedQueryHashes": 2000 ,
2276
+ "fragmentRegistry.transform": 2000 ,
2277
+ "fragmentRegistry.lookup": 1000 ,
2278
+ "fragmentRegistry.findFragmentSpreads": 4000 ,
2279
+ "cache.fragmentQueryDocuments": 1000 ,
2280
+ "removeTypenameFromVariables.getVariableDefinitions": 2000 ,
2281
+ "inMemoryCache.maybeBroadcastWatch": 5000 ,
2282
+ "inMemoryCache.executeSelectionSet": 10000 ,
2283
+ "inMemoryCache.executeSubSelectedArray": 5000 ,
2284
+ };
2285
+ return Object.fromEntries(Object.entries(defaults).map(function (_a) {
2286
+ var k = _a[0], v = _a[1];
2287
+ return [
2288
+ k,
2289
+ cacheSizes[k] || v,
2290
+ ];
2291
+ }));
2292
+ }
2293
+ function _getApolloClientMemoryInternals() {
2294
+ var _a, _b, _c, _d, _e;
2295
+ if (!(globalThis.__DEV__ !== false))
2296
+ throw new Error("only supported in development mode");
2297
+ return {
2298
+ limits: getCurrentCacheSizes(),
2299
+ sizes: tslib.__assign({ print: (_a = globalCaches.print) === null || _a === void 0 ? void 0 : _a.call(globalCaches), parser: (_b = globalCaches.parser) === null || _b === void 0 ? void 0 : _b.call(globalCaches), canonicalStringify: (_c = globalCaches.canonicalStringify) === null || _c === void 0 ? void 0 : _c.call(globalCaches), links: linkInfo(this.link), queryManager: {
2300
+ getDocumentInfo: this["queryManager"]["transformCache"].size,
2301
+ documentTransforms: transformInfo(this["queryManager"].documentTransform),
2302
+ } }, (_e = (_d = this.cache).getMemoryInternals) === null || _e === void 0 ? void 0 : _e.call(_d)),
2303
+ };
2304
+ }
2305
+ function isWrapper(f) {
2306
+ return !!f && "dirtyKey" in f;
2307
+ }
2308
+ function getWrapperInformation(f) {
2309
+ return isWrapper(f) ? f.size : undefined;
2310
+ }
2311
+ function isDefined(value) {
2312
+ return value != null;
2313
+ }
2314
+ function transformInfo(transform) {
2315
+ return recurseTransformInfo(transform).map(function (cache) { return ({ cache: cache }); });
2316
+ }
2317
+ function recurseTransformInfo(transform) {
2318
+ return transform ?
2319
+ tslib.__spreadArray(tslib.__spreadArray([
2320
+ getWrapperInformation(transform === null || transform === void 0 ? void 0 : transform["performWork"])
2321
+ ], recurseTransformInfo(transform === null || transform === void 0 ? void 0 : transform["left"]), true), recurseTransformInfo(transform === null || transform === void 0 ? void 0 : transform["right"]), true).filter(isDefined)
2322
+ : [];
2323
+ }
2324
+ function linkInfo(link) {
2325
+ var _a;
2326
+ return link ?
2327
+ tslib.__spreadArray(tslib.__spreadArray([
2328
+ (_a = link === null || link === void 0 ? void 0 : link.getMemoryInternals) === null || _a === void 0 ? void 0 : _a.call(link)
2329
+ ], linkInfo(link === null || link === void 0 ? void 0 : link.left), true), linkInfo(link === null || link === void 0 ? void 0 : link.right), true).filter(isDefined)
2330
+ : [];
2331
+ }
2332
+
2249
2333
  var hasSuggestedDevtools = false;
2250
2334
  var ApolloClient = (function () {
2251
2335
  function ApolloClient(options) {
@@ -2511,6 +2595,9 @@ var ApolloClient = (function () {
2511
2595
  });
2512
2596
  return ApolloClient;
2513
2597
  }());
2598
+ if (globalThis.__DEV__ !== false) {
2599
+ ApolloClient.prototype.getMemoryInternals = getApolloClientMemoryInternals;
2600
+ }
2514
2601
 
2515
2602
  tsInvariant.setVerbosity(globalThis.__DEV__ !== false ? "log" : "silent");
2516
2603