@apollo/client 3.4.10 → 3.4.14

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 (102) hide show
  1. package/README.md +2 -2
  2. package/apollo-client.cjs.js +85 -55
  3. package/apollo-client.cjs.js.map +1 -1
  4. package/apollo-client.cjs.min.js +1 -0
  5. package/cache/cache.cjs.js +46 -36
  6. package/cache/cache.cjs.js.map +1 -1
  7. package/cache/core/cache.js.map +1 -1
  8. package/cache/core/types/DataProxy.js.map +1 -1
  9. package/cache/index.d.ts +3 -3
  10. package/cache/index.d.ts.map +1 -1
  11. package/cache/index.js +2 -2
  12. package/cache/index.js.map +1 -1
  13. package/cache/inmemory/entityStore.d.ts +1 -1
  14. package/cache/inmemory/entityStore.d.ts.map +1 -1
  15. package/cache/inmemory/entityStore.js +3 -3
  16. package/cache/inmemory/entityStore.js.map +1 -1
  17. package/cache/inmemory/helpers.d.ts +10 -1
  18. package/cache/inmemory/helpers.d.ts.map +1 -1
  19. package/cache/inmemory/helpers.js +31 -1
  20. package/cache/inmemory/helpers.js.map +1 -1
  21. package/cache/inmemory/inMemoryCache.d.ts +2 -8
  22. package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
  23. package/cache/inmemory/inMemoryCache.js +10 -16
  24. package/cache/inmemory/inMemoryCache.js.map +1 -1
  25. package/cache/inmemory/policies.d.ts +1 -2
  26. package/cache/inmemory/policies.d.ts.map +1 -1
  27. package/cache/inmemory/policies.js +1 -18
  28. package/cache/inmemory/policies.js.map +1 -1
  29. package/cache/inmemory/readFromStore.d.ts +1 -0
  30. package/cache/inmemory/readFromStore.d.ts.map +1 -1
  31. package/cache/inmemory/readFromStore.js +7 -4
  32. package/cache/inmemory/readFromStore.js.map +1 -1
  33. package/cache/inmemory/types.d.ts +8 -1
  34. package/cache/inmemory/types.d.ts.map +1 -1
  35. package/cache/inmemory/types.js.map +1 -1
  36. package/core/ApolloClient.js.map +1 -1
  37. package/core/ObservableQuery.js.map +1 -1
  38. package/core/QueryInfo.d.ts.map +1 -1
  39. package/core/QueryInfo.js +2 -2
  40. package/core/QueryInfo.js.map +1 -1
  41. package/core/QueryManager.d.ts.map +1 -1
  42. package/core/QueryManager.js +2 -1
  43. package/core/QueryManager.js.map +1 -1
  44. package/core/core.cjs.js +5 -4
  45. package/core/core.cjs.js.map +1 -1
  46. package/core/watchQueryOptions.js.map +1 -1
  47. package/invariantErrorCodes.js +1 -1
  48. package/link/persisted-queries/index.d.ts +1 -1
  49. package/link/persisted-queries/index.d.ts.map +1 -1
  50. package/link/persisted-queries/index.js +1 -1
  51. package/link/persisted-queries/index.js.map +1 -1
  52. package/link/persisted-queries/persisted-queries.cjs.js +3 -0
  53. package/link/persisted-queries/persisted-queries.cjs.js.map +1 -1
  54. package/package.json +13 -13
  55. package/react/context/ApolloContext.d.ts +2 -1
  56. package/react/context/ApolloContext.d.ts.map +1 -1
  57. package/react/context/ApolloContext.js +11 -5
  58. package/react/context/ApolloContext.js.map +1 -1
  59. package/react/context/context.cjs.js +10 -4
  60. package/react/context/context.cjs.js.map +1 -1
  61. package/react/hoc/hoc.cjs.js +8 -5
  62. package/react/hoc/hoc.cjs.js.map +1 -1
  63. package/react/hoc/subscription-hoc.d.ts.map +1 -1
  64. package/react/hoc/subscription-hoc.js +8 -5
  65. package/react/hoc/subscription-hoc.js.map +1 -1
  66. package/react/parser/index.js.map +1 -1
  67. package/utilities/common/canUse.d.ts +1 -0
  68. package/utilities/common/canUse.d.ts.map +1 -1
  69. package/utilities/common/canUse.js +2 -0
  70. package/utilities/common/canUse.js.map +1 -1
  71. package/utilities/common/maybeDeepFreeze.d.ts.map +1 -1
  72. package/utilities/common/maybeDeepFreeze.js +14 -3
  73. package/utilities/common/maybeDeepFreeze.js.map +1 -1
  74. package/utilities/common/mergeDeep.js +1 -1
  75. package/utilities/common/mergeDeep.js.map +1 -1
  76. package/utilities/globals/globals.cjs.js +1 -0
  77. package/utilities/globals/globals.cjs.js.map +1 -1
  78. package/utilities/globals/index.js +1 -0
  79. package/utilities/globals/index.js.map +1 -1
  80. package/utilities/graphql/fragments.js +1 -1
  81. package/utilities/graphql/fragments.js.map +1 -1
  82. package/utilities/graphql/transform.js +1 -1
  83. package/utilities/graphql/transform.js.map +1 -1
  84. package/utilities/observables/subclassing.d.ts.map +1 -1
  85. package/utilities/observables/subclassing.js +2 -1
  86. package/utilities/observables/subclassing.js.map +1 -1
  87. package/utilities/policies/pagination.d.ts +1 -1
  88. package/utilities/policies/pagination.d.ts.map +1 -1
  89. package/utilities/policies/pagination.js +9 -4
  90. package/utilities/policies/pagination.js.map +1 -1
  91. package/utilities/testing/mocking/mockFetch.js +1 -1
  92. package/utilities/testing/mocking/mockFetch.js.map +1 -1
  93. package/utilities/testing/mocking/mockWatchQuery.js +1 -1
  94. package/utilities/testing/mocking/mockWatchQuery.js.map +1 -1
  95. package/utilities/testing/observableToPromise.js +1 -1
  96. package/utilities/testing/observableToPromise.js.map +1 -1
  97. package/utilities/utilities.cjs.js +34 -15
  98. package/utilities/utilities.cjs.js.map +1 -1
  99. package/version.js +1 -1
  100. package/apollo-core.cjs.js +0 -5778
  101. package/apollo-core.cjs.js.map +0 -1
  102. package/apollo-core.cjs.min.js +0 -1
package/README.md CHANGED
@@ -22,9 +22,9 @@ Learn how to use Apollo Client with self-paced hands-on training on Odyssey, Apo
22
22
  ## Maintainers
23
23
 
24
24
  - [@benjamn](https://github.com/benjamn) (Apollo)
25
- - [@hwillson](https://github.com/hwillson) (Apollo)
26
- - [@jcreighton](https://github.com/jcreighton) (Apollo)
27
25
  - [@brainkim](https://github.com/brainkim) (Apollo)
26
+ - [@jcreighton](https://github.com/jcreighton) (Netflix)
27
+ - [@hwillson](https://github.com/hwillson) (Apollo)
28
28
 
29
29
  ## Who is Apollo?
30
30
 
@@ -128,7 +128,7 @@ function getFragmentQueryDocument(document, fragmentName) {
128
128
  ],
129
129
  },
130
130
  }
131
- ], document.definitions) });
131
+ ], document.definitions, true) });
132
132
  return query;
133
133
  }
134
134
  function createFragmentMap(fragments) {
@@ -564,7 +564,7 @@ var addTypenameToDocument = Object.assign(function (doc) {
564
564
  field.directives.some(function (d) { return d.name.value === 'export'; })) {
565
565
  return;
566
566
  }
567
- return tslib.__assign(tslib.__assign({}, node), { selections: tslib.__spreadArray(tslib.__spreadArray([], selections), [TYPENAME_FIELD]) });
567
+ return tslib.__assign(tslib.__assign({}, node), { selections: tslib.__spreadArray(tslib.__spreadArray([], selections, true), [TYPENAME_FIELD], false) });
568
568
  },
569
569
  },
570
570
  });
@@ -743,7 +743,7 @@ var DeepMerger = (function () {
743
743
  if (hasOwnProperty$3.call(target, sourceKey)) {
744
744
  var targetValue = target[sourceKey];
745
745
  if (source[sourceKey] !== targetValue) {
746
- var result = _this.reconciler.apply(_this, tslib.__spreadArray([target, source, sourceKey], context));
746
+ var result = _this.reconciler.apply(_this, tslib.__spreadArray([target, source, sourceKey], context, false));
747
747
  if (result !== targetValue) {
748
748
  target = _this.shallowCopyForMerge(target);
749
749
  target[sourceKey] = result;
@@ -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.10';
1289
+ var version = '3.4.14';
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) {
@@ -3540,8 +3564,11 @@ var InMemoryCache = (function (_super) {
3540
3564
  }
3541
3565
  };
3542
3566
  InMemoryCache.prototype.reset = function () {
3567
+ var _this = this;
3543
3568
  this.init();
3544
- this.broadcastWatches();
3569
+ this.watches.forEach(function (watch) { return _this.maybeBroadcastWatch.forget(watch); });
3570
+ this.watches.clear();
3571
+ forgetCache(this);
3545
3572
  canonicalStringify.reset();
3546
3573
  return Promise.resolve();
3547
3574
  };
@@ -3631,11 +3658,7 @@ var InMemoryCache = (function (_super) {
3631
3658
  };
3632
3659
  InMemoryCache.prototype.broadcastWatch = function (c, options) {
3633
3660
  var lastDiff = c.lastDiff;
3634
- var diff = this.diff({
3635
- query: c.query,
3636
- variables: c.variables,
3637
- optimistic: c.optimistic,
3638
- });
3661
+ var diff = this.diff(c);
3639
3662
  if (options) {
3640
3663
  if (c.optimistic &&
3641
3664
  typeof options.optimistic === "string") {
@@ -4483,14 +4506,14 @@ var QueryInfo = (function () {
4483
4506
  } : void 0;
4484
4507
  };
4485
4508
  QueryInfo.prototype.getDiffOptions = function (variables) {
4509
+ var _a;
4486
4510
  if (variables === void 0) { variables = this.variables; }
4487
- var oq = this.observableQuery;
4488
4511
  return {
4489
4512
  query: this.document,
4490
4513
  variables: variables,
4491
4514
  returnPartialData: true,
4492
4515
  optimistic: true,
4493
- canonizeResults: !oq || oq.options.canonizeResults !== false,
4516
+ canonizeResults: (_a = this.observableQuery) === null || _a === void 0 ? void 0 : _a.options.canonizeResults,
4494
4517
  };
4495
4518
  };
4496
4519
  QueryInfo.prototype.setDiff = function (diff) {
@@ -5063,7 +5086,8 @@ var QueryManager = (function () {
5063
5086
  return;
5064
5087
  }
5065
5088
  var queryName = oq.queryName, fetchPolicy = oq.options.fetchPolicy;
5066
- if (fetchPolicy === "standby" || !oq.hasObservers()) {
5089
+ if (fetchPolicy === "standby" ||
5090
+ (include === "active" && !oq.hasObservers())) {
5067
5091
  return;
5068
5092
  }
5069
5093
  if (include === "active" ||
@@ -5716,13 +5740,19 @@ var ApolloClient = (function () {
5716
5740
  return ApolloClient;
5717
5741
  }());
5718
5742
 
5719
- var cache$1 = new (canUseWeakMap ? WeakMap : Map)();
5743
+ var contextKey = canUseSymbol
5744
+ ? Symbol.for('__APOLLO_CONTEXT__')
5745
+ : '__APOLLO_CONTEXT__';
5720
5746
  function getApolloContext() {
5721
- var context = cache$1.get(React__namespace.createContext);
5747
+ var context = React__namespace.createContext[contextKey];
5722
5748
  if (!context) {
5723
- context = React__namespace.createContext({});
5749
+ Object.defineProperty(React__namespace.createContext, contextKey, {
5750
+ value: context = React__namespace.createContext({}),
5751
+ enumerable: false,
5752
+ writable: false,
5753
+ configurable: true,
5754
+ });
5724
5755
  context.displayName = 'ApolloContext';
5725
- cache$1.set(React__namespace.createContext, context);
5726
5756
  }
5727
5757
  return context;
5728
5758
  }