@apollo/client 3.4.7 → 3.4.8

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.
@@ -1292,7 +1292,7 @@ var concat = ApolloLink.concat;
1292
1292
 
1293
1293
  var execute = ApolloLink.execute;
1294
1294
 
1295
- var version = '3.4.7';
1295
+ var version = '3.4.8';
1296
1296
 
1297
1297
  var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
1298
1298
  function parseAndCheckHttpResponse(operations) {
@@ -3360,24 +3360,27 @@ function makeAliasMap(selectionSet, fragmentMap) {
3360
3360
  }
3361
3361
  function computeKeyObject(response, specifier, strict, aliasMap) {
3362
3362
  var keyObj = Object.create(null);
3363
- var prevKey;
3363
+ var lastResponseKey;
3364
+ var lastActualKey;
3364
3365
  specifier.forEach(function (s) {
3365
3366
  if (Array.isArray(s)) {
3366
- if (typeof prevKey === "string") {
3367
+ if (typeof lastActualKey === "string" &&
3368
+ typeof lastResponseKey === "string") {
3367
3369
  var subsets = aliasMap && aliasMap.subsets;
3368
- var subset = subsets && subsets[prevKey];
3369
- keyObj[prevKey] = computeKeyObject(response[prevKey], s, strict, subset);
3370
+ var subset = subsets && subsets[lastActualKey];
3371
+ keyObj[lastActualKey] =
3372
+ computeKeyObject(response[lastResponseKey], s, strict, subset);
3370
3373
  }
3371
3374
  }
3372
3375
  else {
3373
3376
  var aliases = aliasMap && aliasMap.aliases;
3374
3377
  var responseName = aliases && aliases[s] || s;
3375
3378
  if (hasOwn.call(response, responseName)) {
3376
- keyObj[prevKey = s] = response[responseName];
3379
+ keyObj[lastActualKey = s] = response[lastResponseKey = responseName];
3377
3380
  }
3378
3381
  else {
3379
3382
  __DEV__ ? tsInvariant.invariant(!strict, "Missing field '" + responseName + "' while computing key fields") : tsInvariant.invariant(!strict, 5);
3380
- prevKey = void 0;
3383
+ lastResponseKey = lastActualKey = void 0;
3381
3384
  }
3382
3385
  }
3383
3386
  });
@@ -3736,11 +3739,12 @@ var ObservableQuery = (function (_super) {
3736
3739
  catch (_a) { }
3737
3740
  var first = !_this.observers.size;
3738
3741
  _this.observers.add(observer);
3739
- if (_this.lastError) {
3740
- observer.error && observer.error(_this.lastError);
3742
+ var last = _this.last;
3743
+ if (last && last.error) {
3744
+ observer.error && observer.error(last.error);
3741
3745
  }
3742
- else if (_this.lastResult) {
3743
- observer.next && observer.next(_this.lastResult);
3746
+ else if (last && last.result) {
3747
+ observer.next && observer.next(last.result);
3744
3748
  }
3745
3749
  if (first) {
3746
3750
  _this.reobserve().catch(function () { });
@@ -3753,18 +3757,6 @@ var ObservableQuery = (function (_super) {
3753
3757
  }) || this;
3754
3758
  _this.observers = new Set();
3755
3759
  _this.subscriptions = new Set();
3756
- _this.observer = {
3757
- next: function (result) {
3758
- if (_this.lastError || _this.isDifferentFromLastResult(result)) {
3759
- _this.updateLastResult(result);
3760
- iterateObserversSafely(_this.observers, 'next', result);
3761
- }
3762
- },
3763
- error: function (error) {
3764
- _this.updateLastResult(tslib.__assign(tslib.__assign({}, _this.lastResult), { error: error, errors: error.graphQLErrors, networkStatus: exports.NetworkStatus.error, loading: false }));
3765
- iterateObserversSafely(_this.observers, 'error', _this.lastError = error);
3766
- },
3767
- };
3768
3760
  _this.isTornDown = false;
3769
3761
  _this.options = options;
3770
3762
  _this.queryId = queryInfo.queryId || queryManager.generateQueryId();
@@ -3803,15 +3795,20 @@ var ObservableQuery = (function (_super) {
3803
3795
  };
3804
3796
  ObservableQuery.prototype.getCurrentResult = function (saveAsLastResult) {
3805
3797
  if (saveAsLastResult === void 0) { saveAsLastResult = true; }
3806
- var _a = this, lastResult = _a.lastResult, _b = _a.options.fetchPolicy, fetchPolicy = _b === void 0 ? "cache-first" : _b;
3798
+ var lastResult = this.getLastResult(true);
3807
3799
  var networkStatus = this.queryInfo.networkStatus ||
3808
3800
  (lastResult && lastResult.networkStatus) ||
3809
3801
  exports.NetworkStatus.ready;
3810
3802
  var result = tslib.__assign(tslib.__assign({}, lastResult), { loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus });
3811
3803
  if (!this.queryManager.transform(this.options.query).hasForcedResolvers) {
3812
3804
  var diff = this.queryInfo.getDiff();
3813
- result.data = (diff.complete ||
3814
- this.options.returnPartialData) ? diff.result : void 0;
3805
+ if (diff.complete || this.options.returnPartialData) {
3806
+ result.data = diff.result;
3807
+ }
3808
+ if (equality.equal(result.data, {})) {
3809
+ result.data = void 0;
3810
+ }
3811
+ var _a = this.options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a;
3815
3812
  if (diff.complete) {
3816
3813
  if (result.networkStatus === exports.NetworkStatus.loading &&
3817
3814
  (fetchPolicy === 'cache-first' ||
@@ -3839,18 +3836,24 @@ var ObservableQuery = (function (_super) {
3839
3836
  return result;
3840
3837
  };
3841
3838
  ObservableQuery.prototype.isDifferentFromLastResult = function (newResult) {
3842
- return !equality.equal(this.lastResultSnapshot, newResult);
3839
+ return !this.last || !equality.equal(this.last.result, newResult);
3843
3840
  };
3844
- ObservableQuery.prototype.getLastResult = function () {
3845
- return this.lastResult;
3841
+ ObservableQuery.prototype.getLast = function (key, variablesMustMatch) {
3842
+ var last = this.last;
3843
+ if (last &&
3844
+ last[key] &&
3845
+ (!variablesMustMatch || equality.equal(last.variables, this.variables))) {
3846
+ return last[key];
3847
+ }
3846
3848
  };
3847
- ObservableQuery.prototype.getLastError = function () {
3848
- return this.lastError;
3849
+ ObservableQuery.prototype.getLastResult = function (variablesMustMatch) {
3850
+ return this.getLast("result", variablesMustMatch);
3851
+ };
3852
+ ObservableQuery.prototype.getLastError = function (variablesMustMatch) {
3853
+ return this.getLast("error", variablesMustMatch);
3849
3854
  };
3850
3855
  ObservableQuery.prototype.resetLastResults = function () {
3851
- delete this.lastResult;
3852
- delete this.lastResultSnapshot;
3853
- delete this.lastError;
3856
+ delete this.last;
3854
3857
  this.isTornDown = false;
3855
3858
  };
3856
3859
  ObservableQuery.prototype.resetQueryStoreErrors = function () {
@@ -3963,12 +3966,10 @@ var ObservableQuery = (function (_super) {
3963
3966
  }, exports.NetworkStatus.setVariables);
3964
3967
  };
3965
3968
  ObservableQuery.prototype.updateQuery = function (mapFn) {
3966
- var _a;
3967
3969
  var queryManager = this.queryManager;
3968
3970
  var result = queryManager.cache.diff({
3969
3971
  query: this.options.query,
3970
3972
  variables: this.variables,
3971
- previousResult: (_a = this.lastResult) === null || _a === void 0 ? void 0 : _a.data,
3972
3973
  returnPartialData: true,
3973
3974
  optimistic: false,
3974
3975
  }).result;
@@ -4037,18 +4038,18 @@ var ObservableQuery = (function (_super) {
4037
4038
  };
4038
4039
  poll();
4039
4040
  };
4040
- ObservableQuery.prototype.updateLastResult = function (newResult) {
4041
- var previousResult = this.lastResult;
4042
- this.lastResult = newResult;
4043
- this.lastResultSnapshot = this.queryManager.assumeImmutableResults
4044
- ? newResult
4045
- : cloneDeep(newResult);
4041
+ ObservableQuery.prototype.updateLastResult = function (newResult, variables) {
4042
+ if (variables === void 0) { variables = this.variables; }
4043
+ this.last = tslib.__assign(tslib.__assign({}, this.last), { result: this.queryManager.assumeImmutableResults
4044
+ ? newResult
4045
+ : cloneDeep(newResult), variables: variables });
4046
4046
  if (!isNonEmptyArray(newResult.errors)) {
4047
- delete this.lastError;
4047
+ delete this.last.error;
4048
4048
  }
4049
- return previousResult;
4049
+ return this.last;
4050
4050
  };
4051
4051
  ObservableQuery.prototype.reobserve = function (newOptions, newNetworkStatus) {
4052
+ var _this = this;
4052
4053
  this.isTornDown = false;
4053
4054
  var useDisposableConcast = newNetworkStatus === exports.NetworkStatus.refetch ||
4054
4055
  newNetworkStatus === exports.NetworkStatus.fetchMore ||
@@ -4069,18 +4070,39 @@ var ObservableQuery = (function (_super) {
4069
4070
  }
4070
4071
  }
4071
4072
  }
4073
+ var variables = options.variables && tslib.__assign({}, options.variables);
4072
4074
  var concast = this.fetch(options, newNetworkStatus);
4075
+ var observer = {
4076
+ next: function (result) {
4077
+ _this.reportResult(result, variables);
4078
+ },
4079
+ error: function (error) {
4080
+ _this.reportError(error, variables);
4081
+ },
4082
+ };
4073
4083
  if (!useDisposableConcast) {
4074
- if (this.concast) {
4084
+ if (this.concast && this.observer) {
4075
4085
  this.concast.removeObserver(this.observer, true);
4076
4086
  }
4077
4087
  this.concast = concast;
4088
+ this.observer = observer;
4078
4089
  }
4079
- concast.addObserver(this.observer);
4090
+ concast.addObserver(observer);
4080
4091
  return concast.promise;
4081
4092
  };
4082
4093
  ObservableQuery.prototype.observe = function () {
4083
- this.observer.next(this.getCurrentResult(false));
4094
+ this.reportResult(this.getCurrentResult(false), this.variables);
4095
+ };
4096
+ ObservableQuery.prototype.reportResult = function (result, variables) {
4097
+ if (this.getLastError() || this.isDifferentFromLastResult(result)) {
4098
+ this.updateLastResult(result, variables);
4099
+ iterateObserversSafely(this.observers, 'next', result);
4100
+ }
4101
+ };
4102
+ ObservableQuery.prototype.reportError = function (error, variables) {
4103
+ var errorResult = tslib.__assign(tslib.__assign({}, this.getLastResult()), { error: error, errors: error.graphQLErrors, networkStatus: exports.NetworkStatus.error, loading: false });
4104
+ this.updateLastResult(errorResult, variables);
4105
+ iterateObserversSafely(this.observers, 'error', this.last.error = error);
4084
4106
  };
4085
4107
  ObservableQuery.prototype.hasObservers = function () {
4086
4108
  return this.observers.size > 0;
@@ -4088,9 +4110,10 @@ var ObservableQuery = (function (_super) {
4088
4110
  ObservableQuery.prototype.tearDownQuery = function () {
4089
4111
  if (this.isTornDown)
4090
4112
  return;
4091
- if (this.concast) {
4113
+ if (this.concast && this.observer) {
4092
4114
  this.concast.removeObserver(this.observer);
4093
4115
  delete this.concast;
4116
+ delete this.observer;
4094
4117
  }
4095
4118
  this.stopPolling();
4096
4119
  this.subscriptions.forEach(function (sub) { return sub.unsubscribe(); });