@apollo/client 3.13.6 → 3.13.7

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,13 @@
1
1
  # @apollo/client
2
2
 
3
+ ## 3.13.7
4
+
5
+ ### Patch Changes
6
+
7
+ - [#12540](https://github.com/apollographql/apollo-client/pull/12540) [`0098932`](https://github.com/apollographql/apollo-client/commit/009893220934081f6e5733bff5863c768a597117) Thanks [@phryneas](https://github.com/phryneas)! - Refactor: Move notification scheduling logic from `QueryInfo` to `ObservableQuery`
8
+
9
+ - [#12540](https://github.com/apollographql/apollo-client/pull/12540) [`0098932`](https://github.com/apollographql/apollo-client/commit/009893220934081f6e5733bff5863c768a597117) Thanks [@phryneas](https://github.com/phryneas)! - Refactored cache emit logic for ObservableQuery. This should be an invisible change.
10
+
3
11
  ## 3.13.6
4
12
 
5
13
  ### Patch Changes
package/apollo-client.cjs CHANGED
@@ -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.6";
34
+ var version = "3.13.7";
35
35
 
36
36
  function maybe(thunk) {
37
37
  try {
@@ -5203,6 +5203,7 @@ var ObservableQuery = (function (_super) {
5203
5203
  }) || this;
5204
5204
  _this.observers = new Set();
5205
5205
  _this.subscriptions = new Set();
5206
+ _this.dirty = false;
5206
5207
  _this.queryInfo = queryInfo;
5207
5208
  _this.queryManager = queryManager;
5208
5209
  _this.waitForOwnResult = skipCacheDataFor(options.fetchPolicy);
@@ -5446,7 +5447,7 @@ var ObservableQuery = (function (_super) {
5446
5447
  })
5447
5448
  .finally(function () {
5448
5449
  if (isCached && !updatedQuerySet.has(_this.query)) {
5449
- reobserveCacheFirst(_this);
5450
+ _this.reobserveCacheFirst();
5450
5451
  }
5451
5452
  });
5452
5453
  };
@@ -5739,26 +5740,62 @@ var ObservableQuery = (function (_super) {
5739
5740
  id: this.queryId,
5740
5741
  }) }) : result;
5741
5742
  };
5743
+ ObservableQuery.prototype.resetNotifications = function () {
5744
+ this.cancelNotifyTimeout();
5745
+ this.dirty = false;
5746
+ };
5747
+ ObservableQuery.prototype.cancelNotifyTimeout = function () {
5748
+ if (this.notifyTimeout) {
5749
+ clearTimeout(this.notifyTimeout);
5750
+ this.notifyTimeout = void 0;
5751
+ }
5752
+ };
5753
+ ObservableQuery.prototype.scheduleNotify = function () {
5754
+ var _this = this;
5755
+ if (this.dirty)
5756
+ return;
5757
+ this.dirty = true;
5758
+ if (!this.notifyTimeout) {
5759
+ this.notifyTimeout = setTimeout(function () { return _this.notify(); }, 0);
5760
+ }
5761
+ };
5762
+ ObservableQuery.prototype.notify = function () {
5763
+ this.cancelNotifyTimeout();
5764
+ if (this.dirty) {
5765
+ if (this.options.fetchPolicy == "cache-only" ||
5766
+ this.options.fetchPolicy == "cache-and-network" ||
5767
+ !isNetworkRequestInFlight(this.queryInfo.networkStatus)) {
5768
+ var diff = this.queryInfo.getDiff();
5769
+ if (diff.fromOptimisticTransaction) {
5770
+ this.observe();
5771
+ }
5772
+ else {
5773
+ this.reobserveCacheFirst();
5774
+ }
5775
+ }
5776
+ }
5777
+ this.dirty = false;
5778
+ };
5779
+ ObservableQuery.prototype.reobserveCacheFirst = function () {
5780
+ var _a = this.options, fetchPolicy = _a.fetchPolicy, nextFetchPolicy = _a.nextFetchPolicy;
5781
+ if (fetchPolicy === "cache-and-network" || fetchPolicy === "network-only") {
5782
+ return this.reobserve({
5783
+ fetchPolicy: "cache-first",
5784
+ nextFetchPolicy: function (currentFetchPolicy, context) {
5785
+ this.nextFetchPolicy = nextFetchPolicy;
5786
+ if (typeof this.nextFetchPolicy === "function") {
5787
+ return this.nextFetchPolicy(currentFetchPolicy, context);
5788
+ }
5789
+ return fetchPolicy;
5790
+ },
5791
+ });
5792
+ }
5793
+ return this.reobserve();
5794
+ };
5742
5795
  ObservableQuery.inactiveOnCreation = new optimism.Slot();
5743
5796
  return ObservableQuery;
5744
5797
  }(zenObservableTs.Observable));
5745
5798
  fixObservableSubclass(ObservableQuery);
5746
- function reobserveCacheFirst(obsQuery) {
5747
- var _a = obsQuery.options, fetchPolicy = _a.fetchPolicy, nextFetchPolicy = _a.nextFetchPolicy;
5748
- if (fetchPolicy === "cache-and-network" || fetchPolicy === "network-only") {
5749
- return obsQuery.reobserve({
5750
- fetchPolicy: "cache-first",
5751
- nextFetchPolicy: function (currentFetchPolicy, context) {
5752
- this.nextFetchPolicy = nextFetchPolicy;
5753
- if (typeof this.nextFetchPolicy === "function") {
5754
- return this.nextFetchPolicy(currentFetchPolicy, context);
5755
- }
5756
- return fetchPolicy;
5757
- },
5758
- });
5759
- }
5760
- return obsQuery.reobserve();
5761
- }
5762
5799
  function defaultSubscriptionObserverErrorCallback(error) {
5763
5800
  globalThis.__DEV__ !== false && invariant.error(25, error.message, error.stack);
5764
5801
  }
@@ -5784,21 +5821,13 @@ function wrapDestructiveCacheMethod(cache, methodName) {
5784
5821
  };
5785
5822
  }
5786
5823
  }
5787
- function cancelNotifyTimeout(info) {
5788
- if (info["notifyTimeout"]) {
5789
- clearTimeout(info["notifyTimeout"]);
5790
- info["notifyTimeout"] = void 0;
5791
- }
5792
- }
5793
5824
  var QueryInfo = (function () {
5794
5825
  function QueryInfo(queryManager, queryId) {
5795
5826
  if (queryId === void 0) { queryId = queryManager.generateQueryId(); }
5796
5827
  this.queryId = queryId;
5797
- this.listeners = new Set();
5798
5828
  this.document = null;
5799
5829
  this.lastRequestId = 1;
5800
5830
  this.stopped = false;
5801
- this.dirty = false;
5802
5831
  this.observableQuery = null;
5803
5832
  var cache = (this.cache = queryManager.cache);
5804
5833
  if (!destructiveMethodCounts.has(cache)) {
@@ -5834,10 +5863,6 @@ var QueryInfo = (function () {
5834
5863
  }
5835
5864
  return this;
5836
5865
  };
5837
- QueryInfo.prototype.reset = function () {
5838
- cancelNotifyTimeout(this);
5839
- this.dirty = false;
5840
- };
5841
5866
  QueryInfo.prototype.resetDiff = function () {
5842
5867
  this.lastDiff = void 0;
5843
5868
  };
@@ -5876,68 +5901,29 @@ var QueryInfo = (function () {
5876
5901
  };
5877
5902
  };
5878
5903
  QueryInfo.prototype.setDiff = function (diff) {
5879
- var _this = this;
5880
- var _a;
5904
+ var _a, _b;
5881
5905
  var oldDiff = this.lastDiff && this.lastDiff.diff;
5882
5906
  if (diff && !diff.complete && ((_a = this.observableQuery) === null || _a === void 0 ? void 0 : _a.getLastError())) {
5883
5907
  return;
5884
5908
  }
5885
5909
  this.updateLastDiff(diff);
5886
- if (!this.dirty && !equal.equal(oldDiff && oldDiff.result, diff && diff.result)) {
5887
- this.dirty = true;
5888
- if (!this.notifyTimeout) {
5889
- this.notifyTimeout = setTimeout(function () { return _this.notify(); }, 0);
5890
- }
5910
+ if (!equal.equal(oldDiff && oldDiff.result, diff && diff.result)) {
5911
+ (_b = this.observableQuery) === null || _b === void 0 ? void 0 : _b["scheduleNotify"]();
5891
5912
  }
5892
5913
  };
5893
5914
  QueryInfo.prototype.setObservableQuery = function (oq) {
5894
- var _this = this;
5895
5915
  if (oq === this.observableQuery)
5896
5916
  return;
5897
- if (this.oqListener) {
5898
- this.listeners.delete(this.oqListener);
5899
- }
5900
5917
  this.observableQuery = oq;
5901
5918
  if (oq) {
5902
5919
  oq["queryInfo"] = this;
5903
- this.listeners.add((this.oqListener = function () {
5904
- var diff = _this.getDiff();
5905
- if (diff.fromOptimisticTransaction) {
5906
- oq["observe"]();
5907
- }
5908
- else {
5909
- reobserveCacheFirst(oq);
5910
- }
5911
- }));
5912
- }
5913
- else {
5914
- delete this.oqListener;
5915
5920
  }
5916
5921
  };
5917
- QueryInfo.prototype.notify = function () {
5918
- var _this = this;
5919
- cancelNotifyTimeout(this);
5920
- if (this.shouldNotify()) {
5921
- this.listeners.forEach(function (listener) { return listener(_this); });
5922
- }
5923
- this.dirty = false;
5924
- };
5925
- QueryInfo.prototype.shouldNotify = function () {
5926
- if (!this.dirty || !this.listeners.size) {
5927
- return false;
5928
- }
5929
- if (isNetworkRequestInFlight(this.networkStatus) && this.observableQuery) {
5930
- var fetchPolicy = this.observableQuery.options.fetchPolicy;
5931
- if (fetchPolicy !== "cache-only" && fetchPolicy !== "cache-and-network") {
5932
- return false;
5933
- }
5934
- }
5935
- return true;
5936
- };
5937
5922
  QueryInfo.prototype.stop = function () {
5923
+ var _a;
5938
5924
  if (!this.stopped) {
5939
5925
  this.stopped = true;
5940
- this.reset();
5926
+ (_a = this.observableQuery) === null || _a === void 0 ? void 0 : _a["resetNotifications"]();
5941
5927
  this.cancel();
5942
5928
  var oq = this.observableQuery;
5943
5929
  if (oq)
@@ -5974,9 +5960,10 @@ var QueryInfo = (function () {
5974
5960
  };
5975
5961
  QueryInfo.prototype.markResult = function (result, document, options, cacheWriteBehavior) {
5976
5962
  var _this = this;
5963
+ var _a;
5977
5964
  var merger = new DeepMerger();
5978
5965
  var graphQLErrors = isNonEmptyArray(result.errors) ? result.errors.slice(0) : [];
5979
- this.reset();
5966
+ (_a = this.observableQuery) === null || _a === void 0 ? void 0 : _a["resetNotifications"]();
5980
5967
  if ("incremental" in result && isNonEmptyArray(result.incremental)) {
5981
5968
  var mergedData = mergeIncrementalData(this.getDiff().result, result);
5982
5969
  result.data = mergedData;
@@ -6032,9 +6019,10 @@ var QueryInfo = (function () {
6032
6019
  return (this.networkStatus = exports.NetworkStatus.ready);
6033
6020
  };
6034
6021
  QueryInfo.prototype.markError = function (error) {
6022
+ var _a;
6035
6023
  this.networkStatus = exports.NetworkStatus.error;
6036
6024
  this.lastWrite = void 0;
6037
- this.reset();
6025
+ (_a = this.observableQuery) === null || _a === void 0 ? void 0 : _a["resetNotifications"]();
6038
6026
  if (error.graphQLErrors) {
6039
6027
  this.graphQLErrors = error.graphQLErrors;
6040
6028
  }
@@ -6659,7 +6647,7 @@ var QueryManager = (function () {
6659
6647
  QueryManager.prototype.broadcastQueries = function () {
6660
6648
  if (this.onBroadcast)
6661
6649
  this.onBroadcast();
6662
- this.queries.forEach(function (info) { return info.notify(); });
6650
+ this.queries.forEach(function (info) { var _a; return (_a = info.observableQuery) === null || _a === void 0 ? void 0 : _a["notify"](); });
6663
6651
  };
6664
6652
  QueryManager.prototype.getLocalState = function () {
6665
6653
  return this.localState;
@@ -6857,9 +6845,7 @@ var QueryManager = (function () {
6857
6845
  var result;
6858
6846
  if (onQueryUpdated) {
6859
6847
  if (!diff) {
6860
- var info = oq["queryInfo"];
6861
- info.reset();
6862
- diff = info.getDiff();
6848
+ diff = _this.cache.diff(oq["queryInfo"]["getDiffOptions"]());
6863
6849
  }
6864
6850
  result = onQueryUpdated(oq, diff, lastDiff);
6865
6851
  }