@apollo/client 3.4.12 → 3.4.16

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 (82) hide show
  1. package/README.md +8 -6
  2. package/apollo-client.cjs.js +89 -62
  3. package/apollo-client.cjs.js.map +1 -1
  4. package/apollo-client.cjs.min.js +1 -1
  5. package/cache/cache.cjs.js +52 -37
  6. package/cache/cache.cjs.js.map +1 -1
  7. package/cache/core/cache.d.ts +1 -1
  8. package/cache/core/cache.d.ts.map +1 -1
  9. package/cache/core/cache.js.map +1 -1
  10. package/cache/core/types/Cache.d.ts +3 -0
  11. package/cache/core/types/Cache.d.ts.map +1 -1
  12. package/cache/core/types/Cache.js.map +1 -1
  13. package/cache/core/types/DataProxy.js.map +1 -1
  14. package/cache/index.d.ts +3 -3
  15. package/cache/index.d.ts.map +1 -1
  16. package/cache/index.js +2 -2
  17. package/cache/index.js.map +1 -1
  18. package/cache/inmemory/entityStore.d.ts +1 -1
  19. package/cache/inmemory/entityStore.d.ts.map +1 -1
  20. package/cache/inmemory/entityStore.js +3 -3
  21. package/cache/inmemory/entityStore.js.map +1 -1
  22. package/cache/inmemory/helpers.d.ts +10 -1
  23. package/cache/inmemory/helpers.d.ts.map +1 -1
  24. package/cache/inmemory/helpers.js +31 -1
  25. package/cache/inmemory/helpers.js.map +1 -1
  26. package/cache/inmemory/inMemoryCache.d.ts +3 -9
  27. package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
  28. package/cache/inmemory/inMemoryCache.js +16 -17
  29. package/cache/inmemory/inMemoryCache.js.map +1 -1
  30. package/cache/inmemory/policies.d.ts +1 -2
  31. package/cache/inmemory/policies.d.ts.map +1 -1
  32. package/cache/inmemory/policies.js +1 -18
  33. package/cache/inmemory/policies.js.map +1 -1
  34. package/cache/inmemory/readFromStore.d.ts +1 -0
  35. package/cache/inmemory/readFromStore.d.ts.map +1 -1
  36. package/cache/inmemory/readFromStore.js +7 -4
  37. package/cache/inmemory/readFromStore.js.map +1 -1
  38. package/cache/inmemory/types.d.ts +8 -1
  39. package/cache/inmemory/types.d.ts.map +1 -1
  40. package/cache/inmemory/types.js.map +1 -1
  41. package/core/ApolloClient.d.ts.map +1 -1
  42. package/core/ApolloClient.js +6 -2
  43. package/core/ApolloClient.js.map +1 -1
  44. package/core/ObservableQuery.js.map +1 -1
  45. package/core/QueryInfo.d.ts.map +1 -1
  46. package/core/QueryInfo.js +2 -2
  47. package/core/QueryInfo.js.map +1 -1
  48. package/core/QueryManager.d.ts +2 -3
  49. package/core/QueryManager.d.ts.map +1 -1
  50. package/core/QueryManager.js +7 -9
  51. package/core/QueryManager.js.map +1 -1
  52. package/core/core.cjs.js +16 -14
  53. package/core/core.cjs.js.map +1 -1
  54. package/core/watchQueryOptions.js.map +1 -1
  55. package/invariantErrorCodes.js +1 -1
  56. package/package.json +9 -9
  57. package/react/hoc/hoc.cjs.js +8 -5
  58. package/react/hoc/hoc.cjs.js.map +1 -1
  59. package/react/hoc/subscription-hoc.d.ts.map +1 -1
  60. package/react/hoc/subscription-hoc.js +8 -5
  61. package/react/hoc/subscription-hoc.js.map +1 -1
  62. package/react/parser/index.js.map +1 -1
  63. package/utilities/common/maybeDeepFreeze.d.ts.map +1 -1
  64. package/utilities/common/maybeDeepFreeze.js +14 -3
  65. package/utilities/common/maybeDeepFreeze.js.map +1 -1
  66. package/utilities/globals/{graphql.d.ts → fix-graphql.d.ts} +1 -1
  67. package/utilities/globals/fix-graphql.d.ts.map +1 -0
  68. package/utilities/globals/fix-graphql.js +6 -0
  69. package/utilities/globals/fix-graphql.js.map +1 -0
  70. package/utilities/globals/globals.cjs.js +1 -2
  71. package/utilities/globals/globals.cjs.js.map +1 -1
  72. package/utilities/globals/index.js +1 -1
  73. package/utilities/globals/index.js.map +1 -1
  74. package/utilities/observables/subclassing.js +1 -1
  75. package/utilities/observables/subclassing.js.map +1 -1
  76. package/utilities/testing/mocking/mockFetch.js.map +1 -1
  77. package/utilities/utilities.cjs.js +21 -11
  78. package/utilities/utilities.cjs.js.map +1 -1
  79. package/version.js +1 -1
  80. package/utilities/globals/graphql.d.ts.map +0 -1
  81. package/utilities/globals/graphql.js +0 -7
  82. package/utilities/globals/graphql.js.map +0 -1
package/README.md CHANGED
@@ -28,11 +28,13 @@ Learn how to use Apollo Client with self-paced hands-on training on Odyssey, Apo
28
28
 
29
29
  ## Who is Apollo?
30
30
 
31
- [Apollo Graph, Inc.](https://apollographql.com/) creates industry-leading tools for building applications with GraphQL:
31
+ [Apollo](https://apollographql.com/) builds open-source software and a graph platform to unify GraphQL across your apps and services. We help you ship faster with:
32
32
 
33
- - [Apollo Client](https://www.apollographql.com/apollo-client/) – The most popular GraphQL client for the web. Apollo also builds and maintains [Apollo iOS](https://github.com/apollographql/apollo-ios) and [Apollo Android](https://github.com/apollographql/apollo-android).
34
- - [Apollo Server](https://www.apollographql.com/docs/apollo-server/) – Build a production-ready JavaScript GraphQL server with a schema-first approach.
35
- - [Apollo Studio](https://www.apollographql.com/studio/develop/) – A turnkey portal for GraphQL developers, featuring a powerful GraphQL IDE (the [Apollo Explorer](https://www.apollographql.com/docs/studio/explorer/)), metrics reporting, schema search, and documentation.
36
- - [Apollo Federation](https://www.apollographql.com/apollo-federation) – Create and manage a single data graph composed of subgraphs that can be developed independently.
33
+ * [Apollo Studio](https://www.apollographql.com/studio/develop/) – A free, end-to-end platform for managing your GraphQL lifecycle. Track your GraphQL schemas in a hosted registry to create a source of truth for everything in your graph. Studio provides an IDE (Apollo Explorer) so you can explore data, collaborate on queries, observe usage, and safely make schema changes.
34
+ * [Apollo Federation](https://www.apollographql.com/apollo-federation) – The industry-standard open architecture for building a distributed graph. Use Apollo’s open-source gateway to compose a unified graph from multiple subgraphs, determine a query plan, and route requests across your services.
35
+ * [Apollo Client](https://www.apollographql.com/apollo-client/) – The most popular GraphQL client for the web. Apollo also builds and maintains [Apollo iOS](https://github.com/apollographql/apollo-ios) and [Apollo Android](https://github.com/apollographql/apollo-android).
36
+ * [Apollo Server](https://www.apollographql.com/docs/apollo-server/) – A production-ready JavaScript GraphQL server that connects to any microservice, API, or database. Compatible with all popular JavaScript frameworks and deployable in serverless environments.
37
37
 
38
- We are fully committed to advancing the frontier of graph development with open-source libraries, hosted software tooling, developer extensions, and community contributions.
38
+ ## Learn how to build with Apollo
39
+
40
+ Check out the [Odyssey](https://odyssey.apollographql.com/) learning platform, the perfect place to start your GraphQL journey with videos and interactive code challenges. Join the [Apollo Community](https://community.apollographql.com/) to interact with and get technical help from the GraphQL community.
@@ -7,7 +7,6 @@ var tsInvariant = require('ts-invariant');
7
7
  var equality = require('@wry/equality');
8
8
  var zenObservableTs = require('zen-observable-ts');
9
9
  require('symbol-observable');
10
- var __ = require('..');
11
10
  var graphql = require('graphql');
12
11
  var optimism = require('optimism');
13
12
  var context = require('@wry/context');
@@ -811,9 +810,7 @@ function cloneDeepHelper(val, seen) {
811
810
  function deepFreeze(value) {
812
811
  var workSet = new Set([value]);
813
812
  workSet.forEach(function (obj) {
814
- if (isNonNullObject(obj)) {
815
- if (!Object.isFrozen(obj))
816
- Object.freeze(obj);
813
+ if (isNonNullObject(obj) && shallowFreeze(obj) === obj) {
817
814
  Object.getOwnPropertyNames(obj).forEach(function (name) {
818
815
  if (isNonNullObject(obj[name]))
819
816
  workSet.add(obj[name]);
@@ -822,6 +819,19 @@ function deepFreeze(value) {
822
819
  });
823
820
  return value;
824
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
+ }
825
835
  function maybeDeepFreeze(obj) {
826
836
  if (__DEV__) {
827
837
  deepFreeze(obj);
@@ -883,11 +893,17 @@ function asyncMap(observable, mapFn, catchFn) {
883
893
  });
884
894
  }
885
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
+
886
902
  function fixObservableSubclass(subclass) {
887
903
  function set(key) {
888
904
  Object.defineProperty(subclass, key, { value: zenObservableTs.Observable });
889
905
  }
890
- if (__.canUseSymbol && Symbol.species) {
906
+ if (canUseSymbol && Symbol.species) {
891
907
  set(Symbol.species);
892
908
  }
893
909
  set("@@species");
@@ -1033,12 +1049,6 @@ function graphQLResultHasError(result) {
1033
1049
  return (result.errors && result.errors.length > 0) || false;
1034
1050
  }
1035
1051
 
1036
- var canUseWeakMap = typeof WeakMap === 'function' && !(typeof navigator === 'object' &&
1037
- navigator.product === 'ReactNative');
1038
- var canUseWeakSet = typeof WeakSet === 'function';
1039
- var canUseSymbol = typeof Symbol === 'function' &&
1040
- typeof Symbol.for === 'function';
1041
-
1042
1052
  function compact() {
1043
1053
  var objects = [];
1044
1054
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -1276,7 +1286,7 @@ var concat = ApolloLink.concat;
1276
1286
 
1277
1287
  var execute = ApolloLink.execute;
1278
1288
 
1279
- var version = '3.4.12';
1289
+ var version = '3.4.16';
1280
1290
 
1281
1291
  var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
1282
1292
  function parseAndCheckHttpResponse(operations) {
@@ -1635,6 +1645,36 @@ var MissingFieldError = (function (_super) {
1635
1645
  }(Error));
1636
1646
 
1637
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
+ }
1638
1678
  function getTypenameFromStoreObject(store, objectOrReference) {
1639
1679
  return isReference(objectOrReference)
1640
1680
  ? store.get(objectOrReference.__ref, "__typename")
@@ -1863,14 +1903,14 @@ var EntityStore = (function () {
1863
1903
  }
1864
1904
  return false;
1865
1905
  };
1866
- EntityStore.prototype.evict = function (options) {
1906
+ EntityStore.prototype.evict = function (options, limit) {
1867
1907
  var evicted = false;
1868
1908
  if (options.id) {
1869
1909
  if (hasOwn.call(this.data, options.id)) {
1870
1910
  evicted = this.delete(options.id, options.fieldName, options.args);
1871
1911
  }
1872
- if (this instanceof Layer) {
1873
- evicted = this.parent.evict(options) || evicted;
1912
+ if (this instanceof Layer && this !== limit) {
1913
+ evicted = this.parent.evict(options, limit) || evicted;
1874
1914
  }
1875
1915
  if (options.fieldName || evicted) {
1876
1916
  this.group.dirty(options.id, options.fieldName || "__exists");
@@ -2258,7 +2298,10 @@ var StoreReader = (function () {
2258
2298
  function StoreReader(config) {
2259
2299
  var _this = this;
2260
2300
  this.knownResults = new (canUseWeakMap ? WeakMap : Map)();
2261
- 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
+ });
2262
2305
  this.canon = config.canon || new ObjectCanon;
2263
2306
  this.executeSelectionSet = optimism.wrap(function (options) {
2264
2307
  var _a;
@@ -2300,7 +2343,7 @@ var StoreReader = (function () {
2300
2343
  this.canon = new ObjectCanon;
2301
2344
  };
2302
2345
  StoreReader.prototype.diffQueryAgainstStore = function (_a) {
2303
- 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;
2304
2347
  var policies = this.config.cache.policies;
2305
2348
  variables = tslib.__assign(tslib.__assign({}, getDefaultValues(getQueryDefinition(query))), variables);
2306
2349
  var rootRef = makeReference(rootId);
@@ -2880,23 +2923,6 @@ function argsFromFieldSpecifier(spec) {
2880
2923
  return spec.args !== void 0 ? spec.args :
2881
2924
  spec.field ? argumentsObjectFromField(spec.field, spec.variables) : null;
2882
2925
  }
2883
- var defaultDataIdFromObject = function (_a, context) {
2884
- var __typename = _a.__typename, id = _a.id, _id = _a._id;
2885
- if (typeof __typename === "string") {
2886
- if (context) {
2887
- context.keyObject =
2888
- id !== void 0 ? { id: id } :
2889
- _id !== void 0 ? { _id: _id } :
2890
- void 0;
2891
- }
2892
- if (id === void 0)
2893
- id = _id;
2894
- if (id !== void 0) {
2895
- return __typename + ":" + ((typeof id === "number" ||
2896
- typeof id === "string") ? id : JSON.stringify(id));
2897
- }
2898
- }
2899
- };
2900
2926
  var nullKeyFieldsFn = function () { return void 0; };
2901
2927
  var simpleKeyArgsFn = function (_args, context) { return context.fieldName; };
2902
2928
  var mergeTrueFn = function (existing, incoming, _a) {
@@ -3371,12 +3397,6 @@ function computeKeyObject(response, specifier, strict, aliasMap) {
3371
3397
  return keyObj;
3372
3398
  }
3373
3399
 
3374
- var defaultConfig = {
3375
- dataIdFromObject: defaultDataIdFromObject,
3376
- addTypename: true,
3377
- resultCaching: true,
3378
- typePolicies: {},
3379
- };
3380
3400
  var InMemoryCache = (function (_super) {
3381
3401
  tslib.__extends(InMemoryCache, _super);
3382
3402
  function InMemoryCache(config) {
@@ -3386,7 +3406,7 @@ var InMemoryCache = (function (_super) {
3386
3406
  _this.typenameDocumentCache = new Map();
3387
3407
  _this.makeVar = makeVar;
3388
3408
  _this.txCount = 0;
3389
- _this.config = tslib.__assign(tslib.__assign({}, defaultConfig), config);
3409
+ _this.config = normalizeConfig(config);
3390
3410
  _this.addTypename = !!_this.config.addTypename;
3391
3411
  _this.policies = new Policies({
3392
3412
  cache: _this,
@@ -3412,6 +3432,7 @@ var InMemoryCache = (function (_super) {
3412
3432
  cache: this,
3413
3433
  addTypename: this.addTypename,
3414
3434
  resultCacheMaxSize: this.config.resultCacheMaxSize,
3435
+ canonizeResults: shouldCanonizeResults(this.config),
3415
3436
  canon: resetResultIdentities
3416
3437
  ? void 0
3417
3438
  : previousReader && previousReader.canon,
@@ -3534,7 +3555,7 @@ var InMemoryCache = (function (_super) {
3534
3555
  }
3535
3556
  try {
3536
3557
  ++this.txCount;
3537
- return this.optimisticData.evict(options);
3558
+ return this.optimisticData.evict(options, this.data);
3538
3559
  }
3539
3560
  finally {
3540
3561
  if (!--this.txCount && options.broadcast !== false) {
@@ -3542,10 +3563,18 @@ var InMemoryCache = (function (_super) {
3542
3563
  }
3543
3564
  }
3544
3565
  };
3545
- InMemoryCache.prototype.reset = function () {
3566
+ InMemoryCache.prototype.reset = function (options) {
3567
+ var _this = this;
3546
3568
  this.init();
3547
- this.broadcastWatches();
3548
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
+ }
3549
3578
  return Promise.resolve();
3550
3579
  };
3551
3580
  InMemoryCache.prototype.removeOptimistic = function (idToRemove) {
@@ -3634,11 +3663,7 @@ var InMemoryCache = (function (_super) {
3634
3663
  };
3635
3664
  InMemoryCache.prototype.broadcastWatch = function (c, options) {
3636
3665
  var lastDiff = c.lastDiff;
3637
- var diff = this.diff({
3638
- query: c.query,
3639
- variables: c.variables,
3640
- optimistic: c.optimistic,
3641
- });
3666
+ var diff = this.diff(c);
3642
3667
  if (options) {
3643
3668
  if (c.optimistic &&
3644
3669
  typeof options.optimistic === "string") {
@@ -4486,14 +4511,14 @@ var QueryInfo = (function () {
4486
4511
  } : void 0;
4487
4512
  };
4488
4513
  QueryInfo.prototype.getDiffOptions = function (variables) {
4514
+ var _a;
4489
4515
  if (variables === void 0) { variables = this.variables; }
4490
- var oq = this.observableQuery;
4491
4516
  return {
4492
4517
  query: this.document,
4493
4518
  variables: variables,
4494
4519
  returnPartialData: true,
4495
4520
  optimistic: true,
4496
- canonizeResults: !oq || oq.options.canonizeResults !== false,
4521
+ canonizeResults: (_a = this.observableQuery) === null || _a === void 0 ? void 0 : _a.options.canonizeResults,
4497
4522
  };
4498
4523
  };
4499
4524
  QueryInfo.prototype.setDiff = function (diff) {
@@ -5018,7 +5043,10 @@ var QueryManager = (function () {
5018
5043
  if (queryInfo)
5019
5044
  queryInfo.stop();
5020
5045
  };
5021
- QueryManager.prototype.clearStore = function () {
5046
+ QueryManager.prototype.clearStore = function (options) {
5047
+ if (options === void 0) { options = {
5048
+ discardWatches: true,
5049
+ }; }
5022
5050
  this.cancelPendingFetches(__DEV__ ? new tsInvariant.InvariantError('Store reset while query was in flight (not completed in link chain)') : new tsInvariant.InvariantError(20));
5023
5051
  this.queries.forEach(function (queryInfo) {
5024
5052
  if (queryInfo.observableQuery) {
@@ -5031,13 +5059,7 @@ var QueryManager = (function () {
5031
5059
  if (this.mutationStore) {
5032
5060
  this.mutationStore = Object.create(null);
5033
5061
  }
5034
- return this.cache.reset();
5035
- };
5036
- QueryManager.prototype.resetStore = function () {
5037
- var _this = this;
5038
- return this.clearStore().then(function () {
5039
- return _this.reFetchObservableQueries();
5040
- });
5062
+ return this.cache.reset(options);
5041
5063
  };
5042
5064
  QueryManager.prototype.getObservableQueries = function (include) {
5043
5065
  var _this = this;
@@ -5066,7 +5088,8 @@ var QueryManager = (function () {
5066
5088
  return;
5067
5089
  }
5068
5090
  var queryName = oq.queryName, fetchPolicy = oq.options.fetchPolicy;
5069
- if (fetchPolicy === "standby" || !oq.hasObservers()) {
5091
+ if (fetchPolicy === "standby" ||
5092
+ (include === "active" && !oq.hasObservers())) {
5070
5093
  return;
5071
5094
  }
5072
5095
  if (include === "active" ||
@@ -5648,14 +5671,18 @@ var ApolloClient = (function () {
5648
5671
  ApolloClient.prototype.resetStore = function () {
5649
5672
  var _this = this;
5650
5673
  return Promise.resolve()
5651
- .then(function () { return _this.queryManager.clearStore(); })
5674
+ .then(function () { return _this.queryManager.clearStore({
5675
+ discardWatches: false,
5676
+ }); })
5652
5677
  .then(function () { return Promise.all(_this.resetStoreCallbacks.map(function (fn) { return fn(); })); })
5653
5678
  .then(function () { return _this.reFetchObservableQueries(); });
5654
5679
  };
5655
5680
  ApolloClient.prototype.clearStore = function () {
5656
5681
  var _this = this;
5657
5682
  return Promise.resolve()
5658
- .then(function () { return _this.queryManager.clearStore(); })
5683
+ .then(function () { return _this.queryManager.clearStore({
5684
+ discardWatches: true,
5685
+ }); })
5659
5686
  .then(function () { return Promise.all(_this.clearStoreCallbacks.map(function (fn) { return fn(); })); });
5660
5687
  };
5661
5688
  ApolloClient.prototype.onResetStore = function (cb) {