@apollo/client 3.13.4 → 3.13.6

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.
package/core/core.cjs CHANGED
@@ -10,6 +10,7 @@ var equal = require('@wry/equality');
10
10
  var utilities = require('../utilities');
11
11
  var cache = require('../cache');
12
12
  var errors = require('../errors');
13
+ var optimism = require('optimism');
13
14
  var trie = require('@wry/trie');
14
15
  var masking = require('../masking');
15
16
  var graphql = require('graphql');
@@ -21,7 +22,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
21
22
 
22
23
  var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
23
24
 
24
- var version = "3.13.4";
25
+ var version = "3.13.6";
25
26
 
26
27
  function isNonNullObject(obj) {
27
28
  return obj !== null && typeof obj === "object";
@@ -199,7 +200,13 @@ var ObservableQuery = (function (_super) {
199
200
  tslib.__extends(ObservableQuery, _super);
200
201
  function ObservableQuery(_a) {
201
202
  var queryManager = _a.queryManager, queryInfo = _a.queryInfo, options = _a.options;
202
- var _this = _super.call(this, function (observer) {
203
+ var _this = this;
204
+ var startedInactive = ObservableQuery.inactiveOnCreation.getValue();
205
+ _this = _super.call(this, function (observer) {
206
+ if (startedInactive) {
207
+ queryManager["queries"].set(_this.queryId, queryInfo);
208
+ startedInactive = false;
209
+ }
203
210
  try {
204
211
  var subObserver = observer._subscription._observer;
205
212
  if (subObserver && !subObserver.error) {
@@ -579,8 +586,9 @@ var ObservableQuery = (function (_super) {
579
586
  return options.fetchPolicy;
580
587
  };
581
588
  ObservableQuery.prototype.fetch = function (options, newNetworkStatus, query) {
582
- this.queryManager.setObservableQuery(this);
583
- return this.queryManager["fetchConcastWithInfo"](this.queryId, options, newNetworkStatus, query);
589
+ var queryInfo = this.queryManager.getOrCreateQuery(this.queryId);
590
+ queryInfo.setObservableQuery(this);
591
+ return this.queryManager["fetchConcastWithInfo"](queryInfo, options, newNetworkStatus, query);
584
592
  };
585
593
  ObservableQuery.prototype.updatePolling = function () {
586
594
  var _this = this;
@@ -762,6 +770,7 @@ var ObservableQuery = (function (_super) {
762
770
  id: this.queryId,
763
771
  }) }) : result;
764
772
  };
773
+ ObservableQuery.inactiveOnCreation = new optimism.Slot();
765
774
  return ObservableQuery;
766
775
  }(utilities.Observable));
767
776
  utilities.fixObservableSubclass(ObservableQuery);
@@ -839,6 +848,7 @@ var QueryInfo = (function () {
839
848
  }
840
849
  if (!equal.equal(query.variables, this.variables)) {
841
850
  this.lastDiff = void 0;
851
+ this.cancel();
842
852
  }
843
853
  Object.assign(this, {
844
854
  document: query.document,
@@ -960,13 +970,16 @@ var QueryInfo = (function () {
960
970
  this.stopped = true;
961
971
  this.reset();
962
972
  this.cancel();
963
- this.cancel = QueryInfo.prototype.cancel;
964
973
  var oq = this.observableQuery;
965
974
  if (oq)
966
975
  oq.stopPolling();
967
976
  }
968
977
  };
969
- QueryInfo.prototype.cancel = function () { };
978
+ QueryInfo.prototype.cancel = function () {
979
+ var _a;
980
+ (_a = this.cancelWatch) === null || _a === void 0 ? void 0 : _a.call(this);
981
+ this.cancelWatch = void 0;
982
+ };
970
983
  QueryInfo.prototype.updateWatch = function (variables) {
971
984
  var _this = this;
972
985
  if (variables === void 0) { variables = this.variables; }
@@ -977,7 +990,7 @@ var QueryInfo = (function () {
977
990
  var watchOptions = tslib.__assign(tslib.__assign({}, this.getDiffOptions(variables)), { watcher: this, callback: function (diff) { return _this.setDiff(diff); } });
978
991
  if (!this.lastWatch || !equal.equal(watchOptions, this.lastWatch)) {
979
992
  this.cancel();
980
- this.cancel = this.cache.watch((this.lastWatch = watchOptions));
993
+ this.cancelWatch = this.cache.watch((this.lastWatch = watchOptions));
981
994
  }
982
995
  };
983
996
  QueryInfo.prototype.resetLastWrite = function () {
@@ -1380,8 +1393,7 @@ var QueryManager = (function () {
1380
1393
  return true;
1381
1394
  };
1382
1395
  QueryManager.prototype.fetchQuery = function (queryId, options, networkStatus) {
1383
- return this.fetchConcastWithInfo(queryId, options, networkStatus).concast
1384
- .promise;
1396
+ return this.fetchConcastWithInfo(this.getOrCreateQuery(queryId), options, networkStatus).concast.promise;
1385
1397
  };
1386
1398
  QueryManager.prototype.getQueryStore = function () {
1387
1399
  var store = Object.create(null);
@@ -1449,7 +1461,9 @@ var QueryManager = (function () {
1449
1461
  options: options,
1450
1462
  });
1451
1463
  observable["lastQuery"] = query;
1452
- this.queries.set(observable.queryId, queryInfo);
1464
+ if (!ObservableQuery["inactiveOnCreation"].getValue()) {
1465
+ this.queries.set(observable.queryId, queryInfo);
1466
+ }
1453
1467
  queryInfo.init({
1454
1468
  document: query,
1455
1469
  observableQuery: observable,
@@ -1561,7 +1575,7 @@ var QueryManager = (function () {
1561
1575
  if (legacyQueryOptions.size) {
1562
1576
  legacyQueryOptions.forEach(function (options) {
1563
1577
  var queryId = utilities.makeUniqueId("legacyOneTimeQuery");
1564
- var queryInfo = _this.getQuery(queryId).init({
1578
+ var queryInfo = _this.getOrCreateQuery(queryId).init({
1565
1579
  document: options.query,
1566
1580
  variables: options.variables,
1567
1581
  });
@@ -1601,14 +1615,11 @@ var QueryManager = (function () {
1601
1615
  (fetchPolicy !== "standby" && fetchPolicy !== "cache-only")) {
1602
1616
  observableQueryPromises.push(observableQuery.refetch());
1603
1617
  }
1604
- _this.getQuery(queryId).setDiff(null);
1618
+ (_this.queries.get(queryId) || observableQuery["queryInfo"]).setDiff(null);
1605
1619
  });
1606
1620
  this.broadcastQueries();
1607
1621
  return Promise.all(observableQueryPromises);
1608
1622
  };
1609
- QueryManager.prototype.setObservableQuery = function (observableQuery) {
1610
- this.getQuery(observableQuery.queryId).setObservableQuery(observableQuery);
1611
- };
1612
1623
  QueryManager.prototype.startGraphQLSubscription = function (options) {
1613
1624
  var _this = this;
1614
1625
  var query = options.query, variables = options.variables;
@@ -1669,9 +1680,10 @@ var QueryManager = (function () {
1669
1680
  this.removeQuery(queryId);
1670
1681
  };
1671
1682
  QueryManager.prototype.removeQuery = function (queryId) {
1683
+ var _a;
1672
1684
  this.fetchCancelFns.delete(queryId);
1673
1685
  if (this.queries.has(queryId)) {
1674
- this.getQuery(queryId).stop();
1686
+ (_a = this.queries.get(queryId)) === null || _a === void 0 ? void 0 : _a.stop();
1675
1687
  this.queries.delete(queryId);
1676
1688
  }
1677
1689
  };
@@ -1779,13 +1791,12 @@ var QueryManager = (function () {
1779
1791
  throw error;
1780
1792
  });
1781
1793
  };
1782
- QueryManager.prototype.fetchConcastWithInfo = function (queryId, options,
1794
+ QueryManager.prototype.fetchConcastWithInfo = function (queryInfo, options,
1783
1795
  networkStatus, query) {
1784
1796
  var _this = this;
1785
1797
  if (networkStatus === void 0) { networkStatus = exports.NetworkStatus.loading; }
1786
1798
  if (query === void 0) { query = options.query; }
1787
1799
  var variables = this.getVariables(query, options.variables);
1788
- var queryInfo = this.getQuery(queryId);
1789
1800
  var defaults = this.defaultOptions.watchQuery;
1790
1801
  var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? (defaults && defaults.fetchPolicy) || "cache-first" : _a, _b = options.errorPolicy, errorPolicy = _b === void 0 ? (defaults && defaults.errorPolicy) || "none" : _b, _c = options.returnPartialData, returnPartialData = _c === void 0 ? false : _c, _d = options.notifyOnNetworkStatusChange, notifyOnNetworkStatusChange = _d === void 0 ? false : _d, _e = options.context, context = _e === void 0 ? {} : _e;
1791
1802
  var normalized = Object.assign({}, options, {
@@ -1808,8 +1819,8 @@ var QueryManager = (function () {
1808
1819
  }
1809
1820
  return sourcesWithInfo;
1810
1821
  };
1811
- var cleanupCancelFn = function () { return _this.fetchCancelFns.delete(queryId); };
1812
- this.fetchCancelFns.set(queryId, function (reason) {
1822
+ var cleanupCancelFn = function () { return _this.fetchCancelFns.delete(queryInfo.queryId); };
1823
+ this.fetchCancelFns.set(queryInfo.queryId, function (reason) {
1813
1824
  cleanupCancelFn();
1814
1825
  setTimeout(function () { return concast.cancel(reason); });
1815
1826
  });
@@ -1840,7 +1851,7 @@ var QueryManager = (function () {
1840
1851
  this.getObservableQueries(include).forEach(function (oq, queryId) {
1841
1852
  includedQueriesById.set(queryId, {
1842
1853
  oq: oq,
1843
- lastDiff: _this.getQuery(queryId).getDiff(),
1854
+ lastDiff: (_this.queries.get(queryId) || oq["queryInfo"]).getDiff(),
1844
1855
  });
1845
1856
  });
1846
1857
  }
@@ -2036,7 +2047,7 @@ var QueryManager = (function () {
2036
2047
  return { fromLink: false, sources: [] };
2037
2048
  }
2038
2049
  };
2039
- QueryManager.prototype.getQuery = function (queryId) {
2050
+ QueryManager.prototype.getOrCreateQuery = function (queryId) {
2040
2051
  if (queryId && !this.queries.has(queryId)) {
2041
2052
  this.queries.set(queryId, new QueryInfo(this, queryId));
2042
2053
  }