@apollo/client 3.13.5 → 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.5";
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);
@@ -1384,8 +1393,7 @@ var QueryManager = (function () {
1384
1393
  return true;
1385
1394
  };
1386
1395
  QueryManager.prototype.fetchQuery = function (queryId, options, networkStatus) {
1387
- return this.fetchConcastWithInfo(queryId, options, networkStatus).concast
1388
- .promise;
1396
+ return this.fetchConcastWithInfo(this.getOrCreateQuery(queryId), options, networkStatus).concast.promise;
1389
1397
  };
1390
1398
  QueryManager.prototype.getQueryStore = function () {
1391
1399
  var store = Object.create(null);
@@ -1453,7 +1461,9 @@ var QueryManager = (function () {
1453
1461
  options: options,
1454
1462
  });
1455
1463
  observable["lastQuery"] = query;
1456
- this.queries.set(observable.queryId, queryInfo);
1464
+ if (!ObservableQuery["inactiveOnCreation"].getValue()) {
1465
+ this.queries.set(observable.queryId, queryInfo);
1466
+ }
1457
1467
  queryInfo.init({
1458
1468
  document: query,
1459
1469
  observableQuery: observable,
@@ -1565,7 +1575,7 @@ var QueryManager = (function () {
1565
1575
  if (legacyQueryOptions.size) {
1566
1576
  legacyQueryOptions.forEach(function (options) {
1567
1577
  var queryId = utilities.makeUniqueId("legacyOneTimeQuery");
1568
- var queryInfo = _this.getQuery(queryId).init({
1578
+ var queryInfo = _this.getOrCreateQuery(queryId).init({
1569
1579
  document: options.query,
1570
1580
  variables: options.variables,
1571
1581
  });
@@ -1605,14 +1615,11 @@ var QueryManager = (function () {
1605
1615
  (fetchPolicy !== "standby" && fetchPolicy !== "cache-only")) {
1606
1616
  observableQueryPromises.push(observableQuery.refetch());
1607
1617
  }
1608
- _this.getQuery(queryId).setDiff(null);
1618
+ (_this.queries.get(queryId) || observableQuery["queryInfo"]).setDiff(null);
1609
1619
  });
1610
1620
  this.broadcastQueries();
1611
1621
  return Promise.all(observableQueryPromises);
1612
1622
  };
1613
- QueryManager.prototype.setObservableQuery = function (observableQuery) {
1614
- this.getQuery(observableQuery.queryId).setObservableQuery(observableQuery);
1615
- };
1616
1623
  QueryManager.prototype.startGraphQLSubscription = function (options) {
1617
1624
  var _this = this;
1618
1625
  var query = options.query, variables = options.variables;
@@ -1673,9 +1680,10 @@ var QueryManager = (function () {
1673
1680
  this.removeQuery(queryId);
1674
1681
  };
1675
1682
  QueryManager.prototype.removeQuery = function (queryId) {
1683
+ var _a;
1676
1684
  this.fetchCancelFns.delete(queryId);
1677
1685
  if (this.queries.has(queryId)) {
1678
- this.getQuery(queryId).stop();
1686
+ (_a = this.queries.get(queryId)) === null || _a === void 0 ? void 0 : _a.stop();
1679
1687
  this.queries.delete(queryId);
1680
1688
  }
1681
1689
  };
@@ -1783,13 +1791,12 @@ var QueryManager = (function () {
1783
1791
  throw error;
1784
1792
  });
1785
1793
  };
1786
- QueryManager.prototype.fetchConcastWithInfo = function (queryId, options,
1794
+ QueryManager.prototype.fetchConcastWithInfo = function (queryInfo, options,
1787
1795
  networkStatus, query) {
1788
1796
  var _this = this;
1789
1797
  if (networkStatus === void 0) { networkStatus = exports.NetworkStatus.loading; }
1790
1798
  if (query === void 0) { query = options.query; }
1791
1799
  var variables = this.getVariables(query, options.variables);
1792
- var queryInfo = this.getQuery(queryId);
1793
1800
  var defaults = this.defaultOptions.watchQuery;
1794
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;
1795
1802
  var normalized = Object.assign({}, options, {
@@ -1812,8 +1819,8 @@ var QueryManager = (function () {
1812
1819
  }
1813
1820
  return sourcesWithInfo;
1814
1821
  };
1815
- var cleanupCancelFn = function () { return _this.fetchCancelFns.delete(queryId); };
1816
- this.fetchCancelFns.set(queryId, function (reason) {
1822
+ var cleanupCancelFn = function () { return _this.fetchCancelFns.delete(queryInfo.queryId); };
1823
+ this.fetchCancelFns.set(queryInfo.queryId, function (reason) {
1817
1824
  cleanupCancelFn();
1818
1825
  setTimeout(function () { return concast.cancel(reason); });
1819
1826
  });
@@ -1844,7 +1851,7 @@ var QueryManager = (function () {
1844
1851
  this.getObservableQueries(include).forEach(function (oq, queryId) {
1845
1852
  includedQueriesById.set(queryId, {
1846
1853
  oq: oq,
1847
- lastDiff: _this.getQuery(queryId).getDiff(),
1854
+ lastDiff: (_this.queries.get(queryId) || oq["queryInfo"]).getDiff(),
1848
1855
  });
1849
1856
  });
1850
1857
  }
@@ -2040,7 +2047,7 @@ var QueryManager = (function () {
2040
2047
  return { fromLink: false, sources: [] };
2041
2048
  }
2042
2049
  };
2043
- QueryManager.prototype.getQuery = function (queryId) {
2050
+ QueryManager.prototype.getOrCreateQuery = function (queryId) {
2044
2051
  if (queryId && !this.queries.has(queryId)) {
2045
2052
  this.queries.set(queryId, new QueryInfo(this, queryId));
2046
2053
  }