@apollo/client 3.4.11 → 3.4.15

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 (85) hide show
  1. package/apollo-client.cjs.js +88 -53
  2. package/apollo-client.cjs.js.map +1 -1
  3. package/apollo-client.cjs.min.js +1 -0
  4. package/cache/cache.cjs.js +52 -37
  5. package/cache/cache.cjs.js.map +1 -1
  6. package/cache/core/cache.d.ts +1 -1
  7. package/cache/core/cache.d.ts.map +1 -1
  8. package/cache/core/cache.js.map +1 -1
  9. package/cache/core/types/Cache.d.ts +3 -0
  10. package/cache/core/types/Cache.d.ts.map +1 -1
  11. package/cache/core/types/Cache.js.map +1 -1
  12. package/cache/core/types/DataProxy.js.map +1 -1
  13. package/cache/index.d.ts +3 -3
  14. package/cache/index.d.ts.map +1 -1
  15. package/cache/index.js +2 -2
  16. package/cache/index.js.map +1 -1
  17. package/cache/inmemory/entityStore.d.ts +1 -1
  18. package/cache/inmemory/entityStore.d.ts.map +1 -1
  19. package/cache/inmemory/entityStore.js +3 -3
  20. package/cache/inmemory/entityStore.js.map +1 -1
  21. package/cache/inmemory/helpers.d.ts +10 -1
  22. package/cache/inmemory/helpers.d.ts.map +1 -1
  23. package/cache/inmemory/helpers.js +31 -1
  24. package/cache/inmemory/helpers.js.map +1 -1
  25. package/cache/inmemory/inMemoryCache.d.ts +3 -9
  26. package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
  27. package/cache/inmemory/inMemoryCache.js +16 -17
  28. package/cache/inmemory/inMemoryCache.js.map +1 -1
  29. package/cache/inmemory/policies.d.ts +1 -2
  30. package/cache/inmemory/policies.d.ts.map +1 -1
  31. package/cache/inmemory/policies.js +1 -18
  32. package/cache/inmemory/policies.js.map +1 -1
  33. package/cache/inmemory/readFromStore.d.ts +1 -0
  34. package/cache/inmemory/readFromStore.d.ts.map +1 -1
  35. package/cache/inmemory/readFromStore.js +7 -4
  36. package/cache/inmemory/readFromStore.js.map +1 -1
  37. package/cache/inmemory/types.d.ts +8 -1
  38. package/cache/inmemory/types.d.ts.map +1 -1
  39. package/cache/inmemory/types.js.map +1 -1
  40. package/core/ApolloClient.js.map +1 -1
  41. package/core/ObservableQuery.js.map +1 -1
  42. package/core/QueryInfo.d.ts.map +1 -1
  43. package/core/QueryInfo.js +2 -2
  44. package/core/QueryInfo.js.map +1 -1
  45. package/core/QueryManager.d.ts.map +1 -1
  46. package/core/QueryManager.js +2 -1
  47. package/core/QueryManager.js.map +1 -1
  48. package/core/core.cjs.js +5 -4
  49. package/core/core.cjs.js.map +1 -1
  50. package/core/watchQueryOptions.js.map +1 -1
  51. package/invariantErrorCodes.js +1 -1
  52. package/package.json +10 -10
  53. package/react/context/ApolloContext.d.ts +2 -1
  54. package/react/context/ApolloContext.d.ts.map +1 -1
  55. package/react/context/ApolloContext.js +11 -5
  56. package/react/context/ApolloContext.js.map +1 -1
  57. package/react/context/context.cjs.js +10 -4
  58. package/react/context/context.cjs.js.map +1 -1
  59. package/react/hoc/hoc.cjs.js +8 -5
  60. package/react/hoc/hoc.cjs.js.map +1 -1
  61. package/react/hoc/subscription-hoc.d.ts.map +1 -1
  62. package/react/hoc/subscription-hoc.js +8 -5
  63. package/react/hoc/subscription-hoc.js.map +1 -1
  64. package/react/parser/index.js.map +1 -1
  65. package/utilities/common/canUse.d.ts +1 -0
  66. package/utilities/common/canUse.d.ts.map +1 -1
  67. package/utilities/common/canUse.js +2 -0
  68. package/utilities/common/canUse.js.map +1 -1
  69. package/utilities/common/maybeDeepFreeze.d.ts.map +1 -1
  70. package/utilities/common/maybeDeepFreeze.js +14 -3
  71. package/utilities/common/maybeDeepFreeze.js.map +1 -1
  72. package/utilities/observables/subclassing.d.ts.map +1 -1
  73. package/utilities/observables/subclassing.js +2 -1
  74. package/utilities/observables/subclassing.js.map +1 -1
  75. package/utilities/policies/pagination.d.ts +1 -1
  76. package/utilities/policies/pagination.d.ts.map +1 -1
  77. package/utilities/policies/pagination.js +7 -2
  78. package/utilities/policies/pagination.js.map +1 -1
  79. package/utilities/testing/mocking/mockFetch.js.map +1 -1
  80. package/utilities/utilities.cjs.js +29 -10
  81. package/utilities/utilities.cjs.js.map +1 -1
  82. package/version.js +1 -1
  83. package/apollo-core.cjs.js +0 -5782
  84. package/apollo-core.cjs.js.map +0 -1
  85. package/apollo-core.cjs.min.js +0 -1
@@ -810,9 +810,7 @@ function cloneDeepHelper(val, seen) {
810
810
  function deepFreeze(value) {
811
811
  var workSet = new Set([value]);
812
812
  workSet.forEach(function (obj) {
813
- if (isNonNullObject(obj)) {
814
- if (!Object.isFrozen(obj))
815
- Object.freeze(obj);
813
+ if (isNonNullObject(obj) && shallowFreeze(obj) === obj) {
816
814
  Object.getOwnPropertyNames(obj).forEach(function (name) {
817
815
  if (isNonNullObject(obj[name]))
818
816
  workSet.add(obj[name]);
@@ -821,6 +819,19 @@ function deepFreeze(value) {
821
819
  });
822
820
  return value;
823
821
  }
822
+ function shallowFreeze(obj) {
823
+ if (__DEV__ && !Object.isFrozen(obj)) {
824
+ try {
825
+ Object.freeze(obj);
826
+ }
827
+ catch (e) {
828
+ if (e instanceof TypeError)
829
+ return null;
830
+ throw e;
831
+ }
832
+ }
833
+ return obj;
834
+ }
824
835
  function maybeDeepFreeze(obj) {
825
836
  if (__DEV__) {
826
837
  deepFreeze(obj);
@@ -882,11 +893,17 @@ function asyncMap(observable, mapFn, catchFn) {
882
893
  });
883
894
  }
884
895
 
896
+ var canUseWeakMap = typeof WeakMap === 'function' && !(typeof navigator === 'object' &&
897
+ navigator.product === 'ReactNative');
898
+ var canUseWeakSet = typeof WeakSet === 'function';
899
+ var canUseSymbol = typeof Symbol === 'function' &&
900
+ typeof Symbol.for === 'function';
901
+
885
902
  function fixObservableSubclass(subclass) {
886
903
  function set(key) {
887
904
  Object.defineProperty(subclass, key, { value: zenObservableTs.Observable });
888
905
  }
889
- if (typeof Symbol === "function" && Symbol.species) {
906
+ if (canUseSymbol && Symbol.species) {
890
907
  set(Symbol.species);
891
908
  }
892
909
  set("@@species");
@@ -1032,10 +1049,6 @@ function graphQLResultHasError(result) {
1032
1049
  return (result.errors && result.errors.length > 0) || false;
1033
1050
  }
1034
1051
 
1035
- var canUseWeakMap = typeof WeakMap === 'function' && !(typeof navigator === 'object' &&
1036
- navigator.product === 'ReactNative');
1037
- var canUseWeakSet = typeof WeakSet === 'function';
1038
-
1039
1052
  function compact() {
1040
1053
  var objects = [];
1041
1054
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -1273,7 +1286,7 @@ var concat = ApolloLink.concat;
1273
1286
 
1274
1287
  var execute = ApolloLink.execute;
1275
1288
 
1276
- var version = '3.4.11';
1289
+ var version = '3.4.15';
1277
1290
 
1278
1291
  var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
1279
1292
  function parseAndCheckHttpResponse(operations) {
@@ -1632,6 +1645,36 @@ var MissingFieldError = (function (_super) {
1632
1645
  }(Error));
1633
1646
 
1634
1647
  var hasOwn = Object.prototype.hasOwnProperty;
1648
+ function defaultDataIdFromObject(_a, context) {
1649
+ var __typename = _a.__typename, id = _a.id, _id = _a._id;
1650
+ if (typeof __typename === "string") {
1651
+ if (context) {
1652
+ context.keyObject =
1653
+ id !== void 0 ? { id: id } :
1654
+ _id !== void 0 ? { _id: _id } :
1655
+ void 0;
1656
+ }
1657
+ if (id === void 0)
1658
+ id = _id;
1659
+ if (id !== void 0) {
1660
+ return __typename + ":" + ((typeof id === "number" ||
1661
+ typeof id === "string") ? id : JSON.stringify(id));
1662
+ }
1663
+ }
1664
+ }
1665
+ var defaultConfig = {
1666
+ dataIdFromObject: defaultDataIdFromObject,
1667
+ addTypename: true,
1668
+ resultCaching: true,
1669
+ canonizeResults: false,
1670
+ };
1671
+ function normalizeConfig(config) {
1672
+ return compact(defaultConfig, config);
1673
+ }
1674
+ function shouldCanonizeResults(config) {
1675
+ var value = config.canonizeResults;
1676
+ return value === void 0 ? defaultConfig.canonizeResults : value;
1677
+ }
1635
1678
  function getTypenameFromStoreObject(store, objectOrReference) {
1636
1679
  return isReference(objectOrReference)
1637
1680
  ? store.get(objectOrReference.__ref, "__typename")
@@ -1860,14 +1903,14 @@ var EntityStore = (function () {
1860
1903
  }
1861
1904
  return false;
1862
1905
  };
1863
- EntityStore.prototype.evict = function (options) {
1906
+ EntityStore.prototype.evict = function (options, limit) {
1864
1907
  var evicted = false;
1865
1908
  if (options.id) {
1866
1909
  if (hasOwn.call(this.data, options.id)) {
1867
1910
  evicted = this.delete(options.id, options.fieldName, options.args);
1868
1911
  }
1869
- if (this instanceof Layer) {
1870
- evicted = this.parent.evict(options) || evicted;
1912
+ if (this instanceof Layer && this !== limit) {
1913
+ evicted = this.parent.evict(options, limit) || evicted;
1871
1914
  }
1872
1915
  if (options.fieldName || evicted) {
1873
1916
  this.group.dirty(options.id, options.fieldName || "__exists");
@@ -2255,7 +2298,10 @@ var StoreReader = (function () {
2255
2298
  function StoreReader(config) {
2256
2299
  var _this = this;
2257
2300
  this.knownResults = new (canUseWeakMap ? WeakMap : Map)();
2258
- this.config = tslib.__assign(tslib.__assign({}, config), { addTypename: config.addTypename !== false });
2301
+ this.config = compact(config, {
2302
+ addTypename: config.addTypename !== false,
2303
+ canonizeResults: shouldCanonizeResults(config),
2304
+ });
2259
2305
  this.canon = config.canon || new ObjectCanon;
2260
2306
  this.executeSelectionSet = optimism.wrap(function (options) {
2261
2307
  var _a;
@@ -2297,7 +2343,7 @@ var StoreReader = (function () {
2297
2343
  this.canon = new ObjectCanon;
2298
2344
  };
2299
2345
  StoreReader.prototype.diffQueryAgainstStore = function (_a) {
2300
- var store = _a.store, query = _a.query, _b = _a.rootId, rootId = _b === void 0 ? 'ROOT_QUERY' : _b, variables = _a.variables, _c = _a.returnPartialData, returnPartialData = _c === void 0 ? true : _c, _d = _a.canonizeResults, canonizeResults = _d === void 0 ? true : _d;
2346
+ var store = _a.store, query = _a.query, _b = _a.rootId, rootId = _b === void 0 ? 'ROOT_QUERY' : _b, variables = _a.variables, _c = _a.returnPartialData, returnPartialData = _c === void 0 ? true : _c, _d = _a.canonizeResults, canonizeResults = _d === void 0 ? this.config.canonizeResults : _d;
2301
2347
  var policies = this.config.cache.policies;
2302
2348
  variables = tslib.__assign(tslib.__assign({}, getDefaultValues(getQueryDefinition(query))), variables);
2303
2349
  var rootRef = makeReference(rootId);
@@ -2877,23 +2923,6 @@ function argsFromFieldSpecifier(spec) {
2877
2923
  return spec.args !== void 0 ? spec.args :
2878
2924
  spec.field ? argumentsObjectFromField(spec.field, spec.variables) : null;
2879
2925
  }
2880
- var defaultDataIdFromObject = function (_a, context) {
2881
- var __typename = _a.__typename, id = _a.id, _id = _a._id;
2882
- if (typeof __typename === "string") {
2883
- if (context) {
2884
- context.keyObject =
2885
- id !== void 0 ? { id: id } :
2886
- _id !== void 0 ? { _id: _id } :
2887
- void 0;
2888
- }
2889
- if (id === void 0)
2890
- id = _id;
2891
- if (id !== void 0) {
2892
- return __typename + ":" + ((typeof id === "number" ||
2893
- typeof id === "string") ? id : JSON.stringify(id));
2894
- }
2895
- }
2896
- };
2897
2926
  var nullKeyFieldsFn = function () { return void 0; };
2898
2927
  var simpleKeyArgsFn = function (_args, context) { return context.fieldName; };
2899
2928
  var mergeTrueFn = function (existing, incoming, _a) {
@@ -3368,12 +3397,6 @@ function computeKeyObject(response, specifier, strict, aliasMap) {
3368
3397
  return keyObj;
3369
3398
  }
3370
3399
 
3371
- var defaultConfig = {
3372
- dataIdFromObject: defaultDataIdFromObject,
3373
- addTypename: true,
3374
- resultCaching: true,
3375
- typePolicies: {},
3376
- };
3377
3400
  var InMemoryCache = (function (_super) {
3378
3401
  tslib.__extends(InMemoryCache, _super);
3379
3402
  function InMemoryCache(config) {
@@ -3383,7 +3406,7 @@ var InMemoryCache = (function (_super) {
3383
3406
  _this.typenameDocumentCache = new Map();
3384
3407
  _this.makeVar = makeVar;
3385
3408
  _this.txCount = 0;
3386
- _this.config = tslib.__assign(tslib.__assign({}, defaultConfig), config);
3409
+ _this.config = normalizeConfig(config);
3387
3410
  _this.addTypename = !!_this.config.addTypename;
3388
3411
  _this.policies = new Policies({
3389
3412
  cache: _this,
@@ -3409,6 +3432,7 @@ var InMemoryCache = (function (_super) {
3409
3432
  cache: this,
3410
3433
  addTypename: this.addTypename,
3411
3434
  resultCacheMaxSize: this.config.resultCacheMaxSize,
3435
+ canonizeResults: shouldCanonizeResults(this.config),
3412
3436
  canon: resetResultIdentities
3413
3437
  ? void 0
3414
3438
  : previousReader && previousReader.canon,
@@ -3531,7 +3555,7 @@ var InMemoryCache = (function (_super) {
3531
3555
  }
3532
3556
  try {
3533
3557
  ++this.txCount;
3534
- return this.optimisticData.evict(options);
3558
+ return this.optimisticData.evict(options, this.data);
3535
3559
  }
3536
3560
  finally {
3537
3561
  if (!--this.txCount && options.broadcast !== false) {
@@ -3539,10 +3563,18 @@ var InMemoryCache = (function (_super) {
3539
3563
  }
3540
3564
  }
3541
3565
  };
3542
- InMemoryCache.prototype.reset = function () {
3566
+ InMemoryCache.prototype.reset = function (options) {
3567
+ var _this = this;
3543
3568
  this.init();
3544
- this.broadcastWatches();
3545
3569
  canonicalStringify.reset();
3570
+ if (options && options.discardWatches) {
3571
+ this.watches.forEach(function (watch) { return _this.maybeBroadcastWatch.forget(watch); });
3572
+ this.watches.clear();
3573
+ forgetCache(this);
3574
+ }
3575
+ else {
3576
+ this.broadcastWatches();
3577
+ }
3546
3578
  return Promise.resolve();
3547
3579
  };
3548
3580
  InMemoryCache.prototype.removeOptimistic = function (idToRemove) {
@@ -3631,11 +3663,7 @@ var InMemoryCache = (function (_super) {
3631
3663
  };
3632
3664
  InMemoryCache.prototype.broadcastWatch = function (c, options) {
3633
3665
  var lastDiff = c.lastDiff;
3634
- var diff = this.diff({
3635
- query: c.query,
3636
- variables: c.variables,
3637
- optimistic: c.optimistic,
3638
- });
3666
+ var diff = this.diff(c);
3639
3667
  if (options) {
3640
3668
  if (c.optimistic &&
3641
3669
  typeof options.optimistic === "string") {
@@ -4483,14 +4511,14 @@ var QueryInfo = (function () {
4483
4511
  } : void 0;
4484
4512
  };
4485
4513
  QueryInfo.prototype.getDiffOptions = function (variables) {
4514
+ var _a;
4486
4515
  if (variables === void 0) { variables = this.variables; }
4487
- var oq = this.observableQuery;
4488
4516
  return {
4489
4517
  query: this.document,
4490
4518
  variables: variables,
4491
4519
  returnPartialData: true,
4492
4520
  optimistic: true,
4493
- canonizeResults: !oq || oq.options.canonizeResults !== false,
4521
+ canonizeResults: (_a = this.observableQuery) === null || _a === void 0 ? void 0 : _a.options.canonizeResults,
4494
4522
  };
4495
4523
  };
4496
4524
  QueryInfo.prototype.setDiff = function (diff) {
@@ -5063,7 +5091,8 @@ var QueryManager = (function () {
5063
5091
  return;
5064
5092
  }
5065
5093
  var queryName = oq.queryName, fetchPolicy = oq.options.fetchPolicy;
5066
- if (fetchPolicy === "standby" || !oq.hasObservers()) {
5094
+ if (fetchPolicy === "standby" ||
5095
+ (include === "active" && !oq.hasObservers())) {
5067
5096
  return;
5068
5097
  }
5069
5098
  if (include === "active" ||
@@ -5716,13 +5745,19 @@ var ApolloClient = (function () {
5716
5745
  return ApolloClient;
5717
5746
  }());
5718
5747
 
5719
- var cache$1 = new (canUseWeakMap ? WeakMap : Map)();
5748
+ var contextKey = canUseSymbol
5749
+ ? Symbol.for('__APOLLO_CONTEXT__')
5750
+ : '__APOLLO_CONTEXT__';
5720
5751
  function getApolloContext() {
5721
- var context = cache$1.get(React__namespace.createContext);
5752
+ var context = React__namespace.createContext[contextKey];
5722
5753
  if (!context) {
5723
- context = React__namespace.createContext({});
5754
+ Object.defineProperty(React__namespace.createContext, contextKey, {
5755
+ value: context = React__namespace.createContext({}),
5756
+ enumerable: false,
5757
+ writable: false,
5758
+ configurable: true,
5759
+ });
5724
5760
  context.displayName = 'ApolloContext';
5725
- cache$1.set(React__namespace.createContext, context);
5726
5761
  }
5727
5762
  return context;
5728
5763
  }