@apollo/client 3.4.13 → 3.4.17

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 (67) hide show
  1. package/README.md +8 -6
  2. package/apollo-client.cjs.js +68 -51
  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 +6 -7
  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/QueryInfo.d.ts.map +1 -1
  45. package/core/QueryInfo.js +2 -2
  46. package/core/QueryInfo.js.map +1 -1
  47. package/core/QueryManager.d.ts +2 -3
  48. package/core/QueryManager.d.ts.map +1 -1
  49. package/core/QueryManager.js +7 -9
  50. package/core/QueryManager.js.map +1 -1
  51. package/core/core.cjs.js +16 -14
  52. package/core/core.cjs.js.map +1 -1
  53. package/core/watchQueryOptions.js.map +1 -1
  54. package/invariantErrorCodes.js +1 -1
  55. package/package.json +18 -19
  56. package/utilities/globals/{graphql.d.ts → fix-graphql.d.ts} +1 -1
  57. package/utilities/globals/fix-graphql.d.ts.map +1 -0
  58. package/utilities/globals/fix-graphql.js +6 -0
  59. package/utilities/globals/fix-graphql.js.map +1 -0
  60. package/utilities/globals/globals.cjs.js +1 -2
  61. package/utilities/globals/globals.cjs.js.map +1 -1
  62. package/utilities/globals/index.js +1 -1
  63. package/utilities/globals/index.js.map +1 -1
  64. package/version.js +1 -1
  65. package/utilities/globals/graphql.d.ts.map +0 -1
  66. package/utilities/globals/graphql.js +0 -7
  67. 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.
@@ -1286,7 +1286,7 @@ var concat = ApolloLink.concat;
1286
1286
 
1287
1287
  var execute = ApolloLink.execute;
1288
1288
 
1289
- var version = '3.4.13';
1289
+ var version = '3.4.17';
1290
1290
 
1291
1291
  var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
1292
1292
  function parseAndCheckHttpResponse(operations) {
@@ -1645,6 +1645,36 @@ var MissingFieldError = (function (_super) {
1645
1645
  }(Error));
1646
1646
 
1647
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
+ }
1648
1678
  function getTypenameFromStoreObject(store, objectOrReference) {
1649
1679
  return isReference(objectOrReference)
1650
1680
  ? store.get(objectOrReference.__ref, "__typename")
@@ -1873,14 +1903,14 @@ var EntityStore = (function () {
1873
1903
  }
1874
1904
  return false;
1875
1905
  };
1876
- EntityStore.prototype.evict = function (options) {
1906
+ EntityStore.prototype.evict = function (options, limit) {
1877
1907
  var evicted = false;
1878
1908
  if (options.id) {
1879
1909
  if (hasOwn.call(this.data, options.id)) {
1880
1910
  evicted = this.delete(options.id, options.fieldName, options.args);
1881
1911
  }
1882
- if (this instanceof Layer) {
1883
- evicted = this.parent.evict(options) || evicted;
1912
+ if (this instanceof Layer && this !== limit) {
1913
+ evicted = this.parent.evict(options, limit) || evicted;
1884
1914
  }
1885
1915
  if (options.fieldName || evicted) {
1886
1916
  this.group.dirty(options.id, options.fieldName || "__exists");
@@ -2268,7 +2298,10 @@ var StoreReader = (function () {
2268
2298
  function StoreReader(config) {
2269
2299
  var _this = this;
2270
2300
  this.knownResults = new (canUseWeakMap ? WeakMap : Map)();
2271
- 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
+ });
2272
2305
  this.canon = config.canon || new ObjectCanon;
2273
2306
  this.executeSelectionSet = optimism.wrap(function (options) {
2274
2307
  var _a;
@@ -2310,7 +2343,7 @@ var StoreReader = (function () {
2310
2343
  this.canon = new ObjectCanon;
2311
2344
  };
2312
2345
  StoreReader.prototype.diffQueryAgainstStore = function (_a) {
2313
- 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;
2314
2347
  var policies = this.config.cache.policies;
2315
2348
  variables = tslib.__assign(tslib.__assign({}, getDefaultValues(getQueryDefinition(query))), variables);
2316
2349
  var rootRef = makeReference(rootId);
@@ -2890,23 +2923,6 @@ function argsFromFieldSpecifier(spec) {
2890
2923
  return spec.args !== void 0 ? spec.args :
2891
2924
  spec.field ? argumentsObjectFromField(spec.field, spec.variables) : null;
2892
2925
  }
2893
- var defaultDataIdFromObject = function (_a, context) {
2894
- var __typename = _a.__typename, id = _a.id, _id = _a._id;
2895
- if (typeof __typename === "string") {
2896
- if (context) {
2897
- context.keyObject =
2898
- id !== void 0 ? { id: id } :
2899
- _id !== void 0 ? { _id: _id } :
2900
- void 0;
2901
- }
2902
- if (id === void 0)
2903
- id = _id;
2904
- if (id !== void 0) {
2905
- return __typename + ":" + ((typeof id === "number" ||
2906
- typeof id === "string") ? id : JSON.stringify(id));
2907
- }
2908
- }
2909
- };
2910
2926
  var nullKeyFieldsFn = function () { return void 0; };
2911
2927
  var simpleKeyArgsFn = function (_args, context) { return context.fieldName; };
2912
2928
  var mergeTrueFn = function (existing, incoming, _a) {
@@ -3381,12 +3397,6 @@ function computeKeyObject(response, specifier, strict, aliasMap) {
3381
3397
  return keyObj;
3382
3398
  }
3383
3399
 
3384
- var defaultConfig = {
3385
- dataIdFromObject: defaultDataIdFromObject,
3386
- addTypename: true,
3387
- resultCaching: true,
3388
- typePolicies: {},
3389
- };
3390
3400
  var InMemoryCache = (function (_super) {
3391
3401
  tslib.__extends(InMemoryCache, _super);
3392
3402
  function InMemoryCache(config) {
@@ -3396,7 +3406,7 @@ var InMemoryCache = (function (_super) {
3396
3406
  _this.typenameDocumentCache = new Map();
3397
3407
  _this.makeVar = makeVar;
3398
3408
  _this.txCount = 0;
3399
- _this.config = tslib.__assign(tslib.__assign({}, defaultConfig), config);
3409
+ _this.config = normalizeConfig(config);
3400
3410
  _this.addTypename = !!_this.config.addTypename;
3401
3411
  _this.policies = new Policies({
3402
3412
  cache: _this,
@@ -3422,6 +3432,7 @@ var InMemoryCache = (function (_super) {
3422
3432
  cache: this,
3423
3433
  addTypename: this.addTypename,
3424
3434
  resultCacheMaxSize: this.config.resultCacheMaxSize,
3435
+ canonizeResults: shouldCanonizeResults(this.config),
3425
3436
  canon: resetResultIdentities
3426
3437
  ? void 0
3427
3438
  : previousReader && previousReader.canon,
@@ -3544,7 +3555,7 @@ var InMemoryCache = (function (_super) {
3544
3555
  }
3545
3556
  try {
3546
3557
  ++this.txCount;
3547
- return this.optimisticData.evict(options);
3558
+ return this.optimisticData.evict(options, this.data);
3548
3559
  }
3549
3560
  finally {
3550
3561
  if (!--this.txCount && options.broadcast !== false) {
@@ -3552,10 +3563,18 @@ var InMemoryCache = (function (_super) {
3552
3563
  }
3553
3564
  }
3554
3565
  };
3555
- InMemoryCache.prototype.reset = function () {
3566
+ InMemoryCache.prototype.reset = function (options) {
3567
+ var _this = this;
3556
3568
  this.init();
3557
- this.broadcastWatches();
3558
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
+ }
3559
3578
  return Promise.resolve();
3560
3579
  };
3561
3580
  InMemoryCache.prototype.removeOptimistic = function (idToRemove) {
@@ -3644,11 +3663,7 @@ var InMemoryCache = (function (_super) {
3644
3663
  };
3645
3664
  InMemoryCache.prototype.broadcastWatch = function (c, options) {
3646
3665
  var lastDiff = c.lastDiff;
3647
- var diff = this.diff({
3648
- query: c.query,
3649
- variables: c.variables,
3650
- optimistic: c.optimistic,
3651
- });
3666
+ var diff = this.diff(c);
3652
3667
  if (options) {
3653
3668
  if (c.optimistic &&
3654
3669
  typeof options.optimistic === "string") {
@@ -4496,14 +4511,14 @@ var QueryInfo = (function () {
4496
4511
  } : void 0;
4497
4512
  };
4498
4513
  QueryInfo.prototype.getDiffOptions = function (variables) {
4514
+ var _a;
4499
4515
  if (variables === void 0) { variables = this.variables; }
4500
- var oq = this.observableQuery;
4501
4516
  return {
4502
4517
  query: this.document,
4503
4518
  variables: variables,
4504
4519
  returnPartialData: true,
4505
4520
  optimistic: true,
4506
- canonizeResults: !oq || oq.options.canonizeResults !== false,
4521
+ canonizeResults: (_a = this.observableQuery) === null || _a === void 0 ? void 0 : _a.options.canonizeResults,
4507
4522
  };
4508
4523
  };
4509
4524
  QueryInfo.prototype.setDiff = function (diff) {
@@ -5028,7 +5043,10 @@ var QueryManager = (function () {
5028
5043
  if (queryInfo)
5029
5044
  queryInfo.stop();
5030
5045
  };
5031
- QueryManager.prototype.clearStore = function () {
5046
+ QueryManager.prototype.clearStore = function (options) {
5047
+ if (options === void 0) { options = {
5048
+ discardWatches: true,
5049
+ }; }
5032
5050
  this.cancelPendingFetches(__DEV__ ? new tsInvariant.InvariantError('Store reset while query was in flight (not completed in link chain)') : new tsInvariant.InvariantError(20));
5033
5051
  this.queries.forEach(function (queryInfo) {
5034
5052
  if (queryInfo.observableQuery) {
@@ -5041,13 +5059,7 @@ var QueryManager = (function () {
5041
5059
  if (this.mutationStore) {
5042
5060
  this.mutationStore = Object.create(null);
5043
5061
  }
5044
- return this.cache.reset();
5045
- };
5046
- QueryManager.prototype.resetStore = function () {
5047
- var _this = this;
5048
- return this.clearStore().then(function () {
5049
- return _this.reFetchObservableQueries();
5050
- });
5062
+ return this.cache.reset(options);
5051
5063
  };
5052
5064
  QueryManager.prototype.getObservableQueries = function (include) {
5053
5065
  var _this = this;
@@ -5076,7 +5088,8 @@ var QueryManager = (function () {
5076
5088
  return;
5077
5089
  }
5078
5090
  var queryName = oq.queryName, fetchPolicy = oq.options.fetchPolicy;
5079
- if (fetchPolicy === "standby" || !oq.hasObservers()) {
5091
+ if (fetchPolicy === "standby" ||
5092
+ (include === "active" && !oq.hasObservers())) {
5080
5093
  return;
5081
5094
  }
5082
5095
  if (include === "active" ||
@@ -5658,14 +5671,18 @@ var ApolloClient = (function () {
5658
5671
  ApolloClient.prototype.resetStore = function () {
5659
5672
  var _this = this;
5660
5673
  return Promise.resolve()
5661
- .then(function () { return _this.queryManager.clearStore(); })
5674
+ .then(function () { return _this.queryManager.clearStore({
5675
+ discardWatches: false,
5676
+ }); })
5662
5677
  .then(function () { return Promise.all(_this.resetStoreCallbacks.map(function (fn) { return fn(); })); })
5663
5678
  .then(function () { return _this.reFetchObservableQueries(); });
5664
5679
  };
5665
5680
  ApolloClient.prototype.clearStore = function () {
5666
5681
  var _this = this;
5667
5682
  return Promise.resolve()
5668
- .then(function () { return _this.queryManager.clearStore(); })
5683
+ .then(function () { return _this.queryManager.clearStore({
5684
+ discardWatches: true,
5685
+ }); })
5669
5686
  .then(function () { return Promise.all(_this.clearStoreCallbacks.map(function (fn) { return fn(); })); });
5670
5687
  };
5671
5688
  ApolloClient.prototype.onResetStore = function (cb) {