@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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @apollo/client
2
2
 
3
+ ## 3.13.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [#12285](https://github.com/apollographql/apollo-client/pull/12285) [`cdc55ff`](https://github.com/apollographql/apollo-client/commit/cdc55ff54bf4c83ec8571508ec4bf8156af1bc97) Thanks [@phryneas](https://github.com/phryneas)! - keep ObservableQuery created by useQuery non-active before it is first subscribed
8
+
3
9
  ## 3.13.5
4
10
 
5
11
  ### Patch Changes
package/apollo-client.cjs CHANGED
@@ -7,10 +7,10 @@ var tsInvariant = require('ts-invariant');
7
7
  var equal = require('@wry/equality');
8
8
  var graphql = require('graphql');
9
9
  var caches = require('@wry/caches');
10
+ var optimism = require('optimism');
10
11
  var zenObservableTs = require('zen-observable-ts');
11
12
  require('symbol-observable');
12
13
  var trie = require('@wry/trie');
13
- var optimism = require('optimism');
14
14
  var graphqlTag = require('graphql-tag');
15
15
  var React = require('rehackt');
16
16
 
@@ -31,7 +31,7 @@ function _interopNamespace(e) {
31
31
  var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
32
32
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
33
33
 
34
- var version = "3.13.5";
34
+ var version = "3.13.6";
35
35
 
36
36
  function maybe(thunk) {
37
37
  try {
@@ -5169,7 +5169,13 @@ var ObservableQuery = (function (_super) {
5169
5169
  tslib.__extends(ObservableQuery, _super);
5170
5170
  function ObservableQuery(_a) {
5171
5171
  var queryManager = _a.queryManager, queryInfo = _a.queryInfo, options = _a.options;
5172
- var _this = _super.call(this, function (observer) {
5172
+ var _this = this;
5173
+ var startedInactive = ObservableQuery.inactiveOnCreation.getValue();
5174
+ _this = _super.call(this, function (observer) {
5175
+ if (startedInactive) {
5176
+ queryManager["queries"].set(_this.queryId, queryInfo);
5177
+ startedInactive = false;
5178
+ }
5173
5179
  try {
5174
5180
  var subObserver = observer._subscription._observer;
5175
5181
  if (subObserver && !subObserver.error) {
@@ -5549,8 +5555,9 @@ var ObservableQuery = (function (_super) {
5549
5555
  return options.fetchPolicy;
5550
5556
  };
5551
5557
  ObservableQuery.prototype.fetch = function (options, newNetworkStatus, query) {
5552
- this.queryManager.setObservableQuery(this);
5553
- return this.queryManager["fetchConcastWithInfo"](this.queryId, options, newNetworkStatus, query);
5558
+ var queryInfo = this.queryManager.getOrCreateQuery(this.queryId);
5559
+ queryInfo.setObservableQuery(this);
5560
+ return this.queryManager["fetchConcastWithInfo"](queryInfo, options, newNetworkStatus, query);
5554
5561
  };
5555
5562
  ObservableQuery.prototype.updatePolling = function () {
5556
5563
  var _this = this;
@@ -5732,6 +5739,7 @@ var ObservableQuery = (function (_super) {
5732
5739
  id: this.queryId,
5733
5740
  }) }) : result;
5734
5741
  };
5742
+ ObservableQuery.inactiveOnCreation = new optimism.Slot();
5735
5743
  return ObservableQuery;
5736
5744
  }(zenObservableTs.Observable));
5737
5745
  fixObservableSubclass(ObservableQuery);
@@ -6354,8 +6362,7 @@ var QueryManager = (function () {
6354
6362
  return true;
6355
6363
  };
6356
6364
  QueryManager.prototype.fetchQuery = function (queryId, options, networkStatus) {
6357
- return this.fetchConcastWithInfo(queryId, options, networkStatus).concast
6358
- .promise;
6365
+ return this.fetchConcastWithInfo(this.getOrCreateQuery(queryId), options, networkStatus).concast.promise;
6359
6366
  };
6360
6367
  QueryManager.prototype.getQueryStore = function () {
6361
6368
  var store = Object.create(null);
@@ -6423,7 +6430,9 @@ var QueryManager = (function () {
6423
6430
  options: options,
6424
6431
  });
6425
6432
  observable["lastQuery"] = query;
6426
- this.queries.set(observable.queryId, queryInfo);
6433
+ if (!ObservableQuery["inactiveOnCreation"].getValue()) {
6434
+ this.queries.set(observable.queryId, queryInfo);
6435
+ }
6427
6436
  queryInfo.init({
6428
6437
  document: query,
6429
6438
  observableQuery: observable,
@@ -6535,7 +6544,7 @@ var QueryManager = (function () {
6535
6544
  if (legacyQueryOptions.size) {
6536
6545
  legacyQueryOptions.forEach(function (options) {
6537
6546
  var queryId = makeUniqueId("legacyOneTimeQuery");
6538
- var queryInfo = _this.getQuery(queryId).init({
6547
+ var queryInfo = _this.getOrCreateQuery(queryId).init({
6539
6548
  document: options.query,
6540
6549
  variables: options.variables,
6541
6550
  });
@@ -6575,14 +6584,11 @@ var QueryManager = (function () {
6575
6584
  (fetchPolicy !== "standby" && fetchPolicy !== "cache-only")) {
6576
6585
  observableQueryPromises.push(observableQuery.refetch());
6577
6586
  }
6578
- _this.getQuery(queryId).setDiff(null);
6587
+ (_this.queries.get(queryId) || observableQuery["queryInfo"]).setDiff(null);
6579
6588
  });
6580
6589
  this.broadcastQueries();
6581
6590
  return Promise.all(observableQueryPromises);
6582
6591
  };
6583
- QueryManager.prototype.setObservableQuery = function (observableQuery) {
6584
- this.getQuery(observableQuery.queryId).setObservableQuery(observableQuery);
6585
- };
6586
6592
  QueryManager.prototype.startGraphQLSubscription = function (options) {
6587
6593
  var _this = this;
6588
6594
  var query = options.query, variables = options.variables;
@@ -6643,9 +6649,10 @@ var QueryManager = (function () {
6643
6649
  this.removeQuery(queryId);
6644
6650
  };
6645
6651
  QueryManager.prototype.removeQuery = function (queryId) {
6652
+ var _a;
6646
6653
  this.fetchCancelFns.delete(queryId);
6647
6654
  if (this.queries.has(queryId)) {
6648
- this.getQuery(queryId).stop();
6655
+ (_a = this.queries.get(queryId)) === null || _a === void 0 ? void 0 : _a.stop();
6649
6656
  this.queries.delete(queryId);
6650
6657
  }
6651
6658
  };
@@ -6753,13 +6760,12 @@ var QueryManager = (function () {
6753
6760
  throw error;
6754
6761
  });
6755
6762
  };
6756
- QueryManager.prototype.fetchConcastWithInfo = function (queryId, options,
6763
+ QueryManager.prototype.fetchConcastWithInfo = function (queryInfo, options,
6757
6764
  networkStatus, query) {
6758
6765
  var _this = this;
6759
6766
  if (networkStatus === void 0) { networkStatus = exports.NetworkStatus.loading; }
6760
6767
  if (query === void 0) { query = options.query; }
6761
6768
  var variables = this.getVariables(query, options.variables);
6762
- var queryInfo = this.getQuery(queryId);
6763
6769
  var defaults = this.defaultOptions.watchQuery;
6764
6770
  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;
6765
6771
  var normalized = Object.assign({}, options, {
@@ -6782,8 +6788,8 @@ var QueryManager = (function () {
6782
6788
  }
6783
6789
  return sourcesWithInfo;
6784
6790
  };
6785
- var cleanupCancelFn = function () { return _this.fetchCancelFns.delete(queryId); };
6786
- this.fetchCancelFns.set(queryId, function (reason) {
6791
+ var cleanupCancelFn = function () { return _this.fetchCancelFns.delete(queryInfo.queryId); };
6792
+ this.fetchCancelFns.set(queryInfo.queryId, function (reason) {
6787
6793
  cleanupCancelFn();
6788
6794
  setTimeout(function () { return concast.cancel(reason); });
6789
6795
  });
@@ -6814,7 +6820,7 @@ var QueryManager = (function () {
6814
6820
  this.getObservableQueries(include).forEach(function (oq, queryId) {
6815
6821
  includedQueriesById.set(queryId, {
6816
6822
  oq: oq,
6817
- lastDiff: _this.getQuery(queryId).getDiff(),
6823
+ lastDiff: (_this.queries.get(queryId) || oq["queryInfo"]).getDiff(),
6818
6824
  });
6819
6825
  });
6820
6826
  }
@@ -7010,7 +7016,7 @@ var QueryManager = (function () {
7010
7016
  return { fromLink: false, sources: [] };
7011
7017
  }
7012
7018
  };
7013
- QueryManager.prototype.getQuery = function (queryId) {
7019
+ QueryManager.prototype.getOrCreateQuery = function (queryId) {
7014
7020
  if (queryId && !this.queries.has(queryId)) {
7015
7021
  this.queries.set(queryId, new QueryInfo(this, queryId));
7016
7022
  }
@@ -7901,7 +7907,9 @@ function useInternalState(client, query, options, renderPromises, makeWatchQuery
7901
7907
  observable:
7902
7908
  (renderPromises &&
7903
7909
  renderPromises.getSSRObservable(makeWatchQueryOptions())) ||
7904
- client.watchQuery(getObsQueryOptions(void 0, client, options, makeWatchQueryOptions())),
7910
+ ObservableQuery["inactiveOnCreation"].withValue(!renderPromises, function () {
7911
+ return client.watchQuery(getObsQueryOptions(void 0, client, options, makeWatchQueryOptions()));
7912
+ }),
7905
7913
  resultData: {
7906
7914
  previousData: (_a = previous === null || previous === void 0 ? void 0 : previous.resultData.current) === null || _a === void 0 ? void 0 : _a.data,
7907
7915
  },