@apollo/client 3.6.0-beta.7 → 3.6.0-beta.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.
package/apollo-client.cjs CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var tslib = require('tslib');
6
6
  var tsInvariant = require('ts-invariant');
7
- var equality = require('@wry/equality');
7
+ var equal = require('@wry/equality');
8
8
  var zenObservableTs = require('zen-observable-ts');
9
9
  require('symbol-observable');
10
10
  var graphql = require('graphql');
@@ -14,6 +14,8 @@ var trie = require('@wry/trie');
14
14
  var graphqlTag = require('graphql-tag');
15
15
  var React = require('react');
16
16
 
17
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
18
+
17
19
  function _interopNamespace(e) {
18
20
  if (e && e.__esModule) return e;
19
21
  var n = Object.create(null);
@@ -26,6 +28,7 @@ function _interopNamespace(e) {
26
28
  return Object.freeze(n);
27
29
  }
28
30
 
31
+ var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
29
32
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
30
33
 
31
34
  function maybe(thunk) {
@@ -1291,7 +1294,7 @@ var concat = ApolloLink.concat;
1291
1294
 
1292
1295
  var execute = ApolloLink.execute;
1293
1296
 
1294
- var version = '3.6.0-beta.7';
1297
+ var version = '3.6.0-beta.8';
1295
1298
 
1296
1299
  var hasOwnProperty$3 = Object.prototype.hasOwnProperty;
1297
1300
  function parseAndCheckHttpResponse(operations) {
@@ -2159,7 +2162,7 @@ var Layer = (function (_super) {
2159
2162
  }
2160
2163
  else if (ownStoreObject !== parentStoreObject) {
2161
2164
  Object.keys(ownStoreObject).forEach(function (storeFieldName) {
2162
- if (!equality.equal(ownStoreObject[storeFieldName], parentStoreObject[storeFieldName])) {
2165
+ if (!equal.equal(ownStoreObject[storeFieldName], parentStoreObject[storeFieldName])) {
2163
2166
  _this.group.dirty(dataId, storeFieldName);
2164
2167
  }
2165
2168
  });
@@ -2203,7 +2206,7 @@ var Stump = (function (_super) {
2203
2206
  function storeObjectReconciler(existingObject, incomingObject, property) {
2204
2207
  var existingValue = existingObject[property];
2205
2208
  var incomingValue = incomingObject[property];
2206
- return equality.equal(existingValue, incomingValue) ? existingValue : incomingValue;
2209
+ return equal.equal(existingValue, incomingValue) ? existingValue : incomingValue;
2207
2210
  }
2208
2211
  function supportsResultCaching(store) {
2209
2212
  return !!(store instanceof EntityStore && store.group.caching);
@@ -3533,7 +3536,7 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
3533
3536
  return;
3534
3537
  if (isReference(existing))
3535
3538
  return;
3536
- if (equality.equal(existing, incoming))
3539
+ if (equal.equal(existing, incoming))
3537
3540
  return;
3538
3541
  if (Object.keys(existing).every(function (key) { return store.getFieldValue(incoming, key) !== void 0; })) {
3539
3542
  return;
@@ -3847,7 +3850,7 @@ var InMemoryCache = (function (_super) {
3847
3850
  return;
3848
3851
  }
3849
3852
  }
3850
- if (!lastDiff || !equality.equal(lastDiff.result, diff.result)) {
3853
+ if (!lastDiff || !equal.equal(lastDiff.result, diff.result)) {
3851
3854
  c.callback(c.lastDiff = diff, lastDiff);
3852
3855
  }
3853
3856
  };
@@ -3992,7 +3995,7 @@ var ObservableQuery = (function (_super) {
3992
3995
  if (diff.complete || this.options.returnPartialData) {
3993
3996
  result.data = diff.result;
3994
3997
  }
3995
- if (equality.equal(result.data, {})) {
3998
+ if (equal.equal(result.data, {})) {
3996
3999
  result.data = void 0;
3997
4000
  }
3998
4001
  if (diff.complete) {
@@ -4023,13 +4026,13 @@ var ObservableQuery = (function (_super) {
4023
4026
  return result;
4024
4027
  };
4025
4028
  ObservableQuery.prototype.isDifferentFromLastResult = function (newResult) {
4026
- return !this.last || !equality.equal(this.last.result, newResult);
4029
+ return !this.last || !equal.equal(this.last.result, newResult);
4027
4030
  };
4028
4031
  ObservableQuery.prototype.getLast = function (key, variablesMustMatch) {
4029
4032
  var last = this.last;
4030
4033
  if (last &&
4031
4034
  last[key] &&
4032
- (!variablesMustMatch || equality.equal(last.variables, this.variables))) {
4035
+ (!variablesMustMatch || equal.equal(last.variables, this.variables))) {
4033
4036
  return last[key];
4034
4037
  }
4035
4038
  };
@@ -4068,7 +4071,7 @@ var ObservableQuery = (function (_super) {
4068
4071
  __DEV__ && tsInvariant.invariant.warn("Called refetch(".concat(JSON.stringify(variables), ") for query ").concat(((_a = queryDef.name) === null || _a === void 0 ? void 0 : _a.value) || JSON.stringify(queryDef), ", which does not declare a $variables variable.\nDid you mean to call refetch(variables) instead of refetch({ variables })?"));
4069
4072
  }
4070
4073
  }
4071
- if (variables && !equality.equal(this.options.variables, variables)) {
4074
+ if (variables && !equal.equal(this.options.variables, variables)) {
4072
4075
  reobserveOptions.variables = this.options.variables = tslib.__assign(tslib.__assign({}, this.options.variables), variables);
4073
4076
  }
4074
4077
  this.queryInfo.resetLastWrite();
@@ -4149,7 +4152,7 @@ var ObservableQuery = (function (_super) {
4149
4152
  return this.reobserve(newOptions);
4150
4153
  };
4151
4154
  ObservableQuery.prototype.setVariables = function (variables) {
4152
- if (equality.equal(this.variables, variables)) {
4155
+ if (equal.equal(this.variables, variables)) {
4153
4156
  return this.observers.size
4154
4157
  ? this.result()
4155
4158
  : Promise.resolve();
@@ -4261,7 +4264,7 @@ var ObservableQuery = (function (_super) {
4261
4264
  if (newOptions &&
4262
4265
  newOptions.variables &&
4263
4266
  !newOptions.fetchPolicy &&
4264
- !equality.equal(newOptions.variables, oldVariables)) {
4267
+ !equal.equal(newOptions.variables, oldVariables)) {
4265
4268
  options.fetchPolicy = this.initialFetchPolicy;
4266
4269
  if (newNetworkStatus === void 0) {
4267
4270
  newNetworkStatus = exports.NetworkStatus.setVariables;
@@ -4643,10 +4646,10 @@ var QueryInfo = (function () {
4643
4646
  var networkStatus = query.networkStatus || exports.NetworkStatus.loading;
4644
4647
  if (this.variables &&
4645
4648
  this.networkStatus !== exports.NetworkStatus.loading &&
4646
- !equality.equal(this.variables, query.variables)) {
4649
+ !equal.equal(this.variables, query.variables)) {
4647
4650
  networkStatus = exports.NetworkStatus.setVariables;
4648
4651
  }
4649
- if (!equality.equal(query.variables, this.variables)) {
4652
+ if (!equal.equal(query.variables, this.variables)) {
4650
4653
  this.lastDiff = void 0;
4651
4654
  }
4652
4655
  Object.assign(this, {
@@ -4672,7 +4675,7 @@ var QueryInfo = (function () {
4672
4675
  QueryInfo.prototype.getDiff = function (variables) {
4673
4676
  if (variables === void 0) { variables = this.variables; }
4674
4677
  var options = this.getDiffOptions(variables);
4675
- if (this.lastDiff && equality.equal(options, this.lastDiff.options)) {
4678
+ if (this.lastDiff && equal.equal(options, this.lastDiff.options)) {
4676
4679
  return this.lastDiff.diff;
4677
4680
  }
4678
4681
  this.updateWatch(this.variables = variables);
@@ -4706,7 +4709,7 @@ var QueryInfo = (function () {
4706
4709
  var oldDiff = this.lastDiff && this.lastDiff.diff;
4707
4710
  this.updateLastDiff(diff);
4708
4711
  if (!this.dirty &&
4709
- !equality.equal(oldDiff && oldDiff.result, diff && diff.result)) {
4712
+ !equal.equal(oldDiff && oldDiff.result, diff && diff.result)) {
4710
4713
  this.dirty = true;
4711
4714
  if (!this.notifyTimeout) {
4712
4715
  this.notifyTimeout = setTimeout(function () { return _this.notify(); }, 0);
@@ -4780,7 +4783,7 @@ var QueryInfo = (function () {
4780
4783
  }
4781
4784
  var watchOptions = tslib.__assign(tslib.__assign({}, this.getDiffOptions(variables)), { watcher: this, callback: function (diff) { return _this.setDiff(diff); } });
4782
4785
  if (!this.lastWatch ||
4783
- !equality.equal(watchOptions, this.lastWatch)) {
4786
+ !equal.equal(watchOptions, this.lastWatch)) {
4784
4787
  this.cancel();
4785
4788
  this.cancel = this.cache.watch(this.lastWatch = watchOptions);
4786
4789
  }
@@ -4792,8 +4795,8 @@ var QueryInfo = (function () {
4792
4795
  var lastWrite = this.lastWrite;
4793
4796
  return !(lastWrite &&
4794
4797
  lastWrite.dmCount === destructiveMethodCounts.get(this.cache) &&
4795
- equality.equal(variables, lastWrite.variables) &&
4796
- equality.equal(result.data, lastWrite.result.data));
4798
+ equal.equal(variables, lastWrite.variables) &&
4799
+ equal.equal(result.data, lastWrite.result.data));
4797
4800
  };
4798
4801
  QueryInfo.prototype.markResult = function (result, options, cacheWriteBehavior) {
4799
4802
  var _this = this;
@@ -5594,7 +5597,7 @@ var QueryManager = (function () {
5594
5597
  var data = diff.result;
5595
5598
  if (__DEV__ &&
5596
5599
  !returnPartialData &&
5597
- !equality.equal(data, {})) {
5600
+ !equal.equal(data, {})) {
5598
5601
  logMissingFieldErrors(diff.missing);
5599
5602
  }
5600
5603
  var fromData = function (data) { return zenObservableTs.Observable.of(tslib.__assign({ data: data, loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus }, (diff.complete ? null : { partial: true }))); };
@@ -6057,9 +6060,27 @@ function verifyDocumentType(document, type) {
6057
6060
  "".concat(requiredOperationName, ", but a ").concat(usedOperationName, " was used instead.")) : tsInvariant.invariant(operation.type === type, 34);
6058
6061
  }
6059
6062
 
6063
+ function useNormalizedOptions(optionsOrFunction) {
6064
+ var optionsRef = React.useRef();
6065
+ var options = optionsRef.current || Object.create(null);
6066
+ if (typeof optionsOrFunction === "function") {
6067
+ var newOptions = optionsOrFunction(options);
6068
+ if (newOptions !== options) {
6069
+ Object.assign(options, newOptions, newOptions.variables && {
6070
+ variables: tslib.__assign(tslib.__assign({}, options.variables), newOptions.variables),
6071
+ });
6072
+ }
6073
+ }
6074
+ else if (optionsOrFunction && !equal__default(optionsOrFunction, options)) {
6075
+ options = optionsOrFunction;
6076
+ }
6077
+ return optionsRef.current = options;
6078
+ }
6079
+
6060
6080
  var hasOwnProperty = Object.prototype.hasOwnProperty;
6061
- function useQuery(query, options) {
6062
- return useInternalState(useApolloClient(options && options.client), query).useQuery(options);
6081
+ function useQuery(query, optionsOrFunction) {
6082
+ var options = useNormalizedOptions(optionsOrFunction);
6083
+ return useInternalState(useApolloClient(options.client), query).useQuery(options);
6063
6084
  }
6064
6085
  function useInternalState(client, query) {
6065
6086
  var stateRef = React.useRef();
@@ -6094,8 +6115,8 @@ var InternalState = (function () {
6094
6115
  };
6095
6116
  InternalState.prototype.useOptions = function (options) {
6096
6117
  this.renderPromises = React.useContext(getApolloContext()).renderPromises;
6097
- var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options || {});
6098
- if (!equality.equal(watchQueryOptions, this.watchQueryOptions)) {
6118
+ var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
6119
+ if (!equal.equal(watchQueryOptions, this.watchQueryOptions)) {
6099
6120
  this.watchQueryOptions = watchQueryOptions;
6100
6121
  }
6101
6122
  this.ssrDisabled = !!(options && (options.ssr === false ||
@@ -6198,7 +6219,7 @@ var InternalState = (function () {
6198
6219
  if (previousResult &&
6199
6220
  previousResult.loading === result.loading &&
6200
6221
  previousResult.networkStatus === result.networkStatus &&
6201
- equality.equal(previousResult.data, result.data)) {
6222
+ equal.equal(previousResult.data, result.data)) {
6202
6223
  return;
6203
6224
  }
6204
6225
  _this.setResult(result);
@@ -6219,7 +6240,7 @@ var InternalState = (function () {
6219
6240
  var previousResult = _this.result;
6220
6241
  if (!previousResult ||
6221
6242
  (previousResult && previousResult.loading) ||
6222
- !equality.equal(error, previousResult.error)) {
6243
+ !equal.equal(error, previousResult.error)) {
6223
6244
  _this.setResult({
6224
6245
  data: (previousResult && previousResult.data),
6225
6246
  error: error,
@@ -6315,7 +6336,8 @@ var EAGER_METHODS = [
6315
6336
  'startPolling',
6316
6337
  'subscribeToMore',
6317
6338
  ];
6318
- function useLazyQuery(query, options) {
6339
+ function useLazyQuery(query, optionsOrFunction) {
6340
+ var options = useNormalizedOptions(optionsOrFunction);
6319
6341
  var _a = React.useState({
6320
6342
  called: false,
6321
6343
  }), execution = _a[0], setExecution = _a[1];
@@ -6406,7 +6428,7 @@ function useMutation(mutation, options) {
6406
6428
  error: error,
6407
6429
  client: client,
6408
6430
  };
6409
- if (ref.current.isMounted && !equality.equal(ref.current.result, result_1)) {
6431
+ if (ref.current.isMounted && !equal.equal(ref.current.result, result_1)) {
6410
6432
  setResult(ref.current.result = result_1);
6411
6433
  }
6412
6434
  }
@@ -6424,7 +6446,7 @@ function useMutation(mutation, options) {
6424
6446
  called: true,
6425
6447
  client: client,
6426
6448
  };
6427
- if (!equality.equal(ref.current.result, result_2)) {
6449
+ if (!equal.equal(ref.current.result, result_2)) {
6428
6450
  setResult(ref.current.result = result_2);
6429
6451
  }
6430
6452
  }
@@ -6487,7 +6509,7 @@ function useSubscription(subscription, options) {
6487
6509
  subscription !== ref.current.subscription ||
6488
6510
  (options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
6489
6511
  !(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
6490
- !equality.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) {
6512
+ !equal.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) {
6491
6513
  setResult({
6492
6514
  loading: true,
6493
6515
  data: void 0,