@apollo/client 3.6.0-beta.6 → 3.6.0-beta.9

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.
Files changed (49) hide show
  1. package/apollo-client.cjs +326 -258
  2. package/apollo-client.cjs.map +1 -1
  3. package/apollo-client.min.cjs +1 -1
  4. package/core/ApolloClient.d.ts.map +1 -1
  5. package/core/ApolloClient.js +2 -2
  6. package/core/ApolloClient.js.map +1 -1
  7. package/core/ObservableQuery.d.ts +1 -1
  8. package/core/ObservableQuery.d.ts.map +1 -1
  9. package/core/ObservableQuery.js +22 -9
  10. package/core/ObservableQuery.js.map +1 -1
  11. package/core/QueryManager.d.ts +5 -2
  12. package/core/QueryManager.d.ts.map +1 -1
  13. package/core/QueryManager.js +14 -9
  14. package/core/QueryManager.js.map +1 -1
  15. package/core/core.cjs +38 -21
  16. package/core/core.cjs.map +1 -1
  17. package/core/index.d.ts +1 -1
  18. package/core/index.d.ts.map +1 -1
  19. package/core/index.js +1 -1
  20. package/core/index.js.map +1 -1
  21. package/core/watchQueryOptions.d.ts +8 -1
  22. package/core/watchQueryOptions.d.ts.map +1 -1
  23. package/core/watchQueryOptions.js.map +1 -1
  24. package/invariantErrorCodes.js +1 -1
  25. package/package.json +11 -11
  26. package/react/hooks/hooks.cjs +262 -209
  27. package/react/hooks/hooks.cjs.map +1 -1
  28. package/react/hooks/options.d.ts +3 -0
  29. package/react/hooks/options.d.ts.map +1 -0
  30. package/react/hooks/options.js +20 -0
  31. package/react/hooks/options.js.map +1 -0
  32. package/react/hooks/useLazyQuery.d.ts +2 -2
  33. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  34. package/react/hooks/useLazyQuery.js +3 -1
  35. package/react/hooks/useLazyQuery.js.map +1 -1
  36. package/react/hooks/useQuery.d.ts +2 -2
  37. package/react/hooks/useQuery.d.ts.map +1 -1
  38. package/react/hooks/useQuery.js +237 -205
  39. package/react/hooks/useQuery.js.map +1 -1
  40. package/react/ssr/RenderPromises.d.ts +1 -1
  41. package/react/ssr/RenderPromises.d.ts.map +1 -1
  42. package/react/ssr/RenderPromises.js +2 -2
  43. package/react/ssr/RenderPromises.js.map +1 -1
  44. package/react/ssr/ssr.cjs +2 -2
  45. package/react/ssr/ssr.cjs.map +1 -1
  46. package/react/types/types.d.ts +3 -0
  47. package/react/types/types.d.ts.map +1 -1
  48. package/react/types/types.js.map +1 -1
  49. package/version.js +1 -1
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) {
@@ -703,7 +706,7 @@ function removeClientSetsFromDocument(document) {
703
706
  return modifiedDoc;
704
707
  }
705
708
 
706
- var hasOwnProperty$3 = Object.prototype.hasOwnProperty;
709
+ var hasOwnProperty$4 = Object.prototype.hasOwnProperty;
707
710
  function mergeDeep() {
708
711
  var sources = [];
709
712
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -740,7 +743,7 @@ var DeepMerger = (function () {
740
743
  }
741
744
  if (isNonNullObject(source) && isNonNullObject(target)) {
742
745
  Object.keys(source).forEach(function (sourceKey) {
743
- if (hasOwnProperty$3.call(target, sourceKey)) {
746
+ if (hasOwnProperty$4.call(target, sourceKey)) {
744
747
  var targetValue = target[sourceKey];
745
748
  if (source[sourceKey] !== targetValue) {
746
749
  var result = _this.reconciler.apply(_this, tslib.__spreadArray([target, source, sourceKey], context, false));
@@ -1291,9 +1294,9 @@ var concat = ApolloLink.concat;
1291
1294
 
1292
1295
  var execute = ApolloLink.execute;
1293
1296
 
1294
- var version = '3.6.0-beta.6';
1297
+ var version = '3.6.0-beta.9';
1295
1298
 
1296
- var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
1299
+ var hasOwnProperty$3 = Object.prototype.hasOwnProperty;
1297
1300
  function parseAndCheckHttpResponse(operations) {
1298
1301
  return function (response) { return response
1299
1302
  .text()
@@ -1315,8 +1318,8 @@ function parseAndCheckHttpResponse(operations) {
1315
1318
  throwServerError(response, result, "Response not successful: Received status code ".concat(response.status));
1316
1319
  }
1317
1320
  if (!Array.isArray(result) &&
1318
- !hasOwnProperty$2.call(result, 'data') &&
1319
- !hasOwnProperty$2.call(result, 'errors')) {
1321
+ !hasOwnProperty$3.call(result, 'data') &&
1322
+ !hasOwnProperty$3.call(result, 'errors')) {
1320
1323
  throwServerError(response, result, "Server response was missing for query '".concat(Array.isArray(operations)
1321
1324
  ? operations.map(function (op) { return op.operationName; })
1322
1325
  : operations.operationName, "'."));
@@ -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
  };
@@ -3905,7 +3908,7 @@ function isNetworkRequestInFlight(networkStatus) {
3905
3908
  return networkStatus ? networkStatus < 7 : false;
3906
3909
  }
3907
3910
 
3908
- var assign = Object.assign, hasOwnProperty$1 = Object.hasOwnProperty;
3911
+ var assign = Object.assign, hasOwnProperty$2 = Object.hasOwnProperty;
3909
3912
  var warnedAboutUpdateQuery = false;
3910
3913
  var ObservableQuery = (function (_super) {
3911
3914
  tslib.__extends(ObservableQuery, _super);
@@ -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
  };
@@ -4061,14 +4064,14 @@ var ObservableQuery = (function (_super) {
4061
4064
  else {
4062
4065
  reobserveOptions.fetchPolicy = 'network-only';
4063
4066
  }
4064
- if (__DEV__ && variables && hasOwnProperty$1.call(variables, "variables")) {
4067
+ if (__DEV__ && variables && hasOwnProperty$2.call(variables, "variables")) {
4065
4068
  var queryDef = getQueryDefinition(this.options.query);
4066
4069
  var vars = queryDef.variableDefinitions;
4067
4070
  if (!vars || !vars.some(function (v) { return v.variable.name.value === "variables"; })) {
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();
@@ -4191,6 +4194,27 @@ var ObservableQuery = (function (_super) {
4191
4194
  this.options.pollInterval = 0;
4192
4195
  this.updatePolling();
4193
4196
  };
4197
+ ObservableQuery.prototype.applyNextFetchPolicy = function (reason, options) {
4198
+ if (options === void 0) { options = this.options; }
4199
+ if (options.nextFetchPolicy) {
4200
+ var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a;
4201
+ if (typeof options.nextFetchPolicy === "function") {
4202
+ options.fetchPolicy = options.nextFetchPolicy(fetchPolicy, {
4203
+ reason: reason,
4204
+ options: options,
4205
+ observable: this,
4206
+ initialPolicy: this.initialFetchPolicy,
4207
+ });
4208
+ }
4209
+ else if (reason === "variables-changed") {
4210
+ options.fetchPolicy = this.initialFetchPolicy;
4211
+ }
4212
+ else {
4213
+ options.fetchPolicy = options.nextFetchPolicy;
4214
+ }
4215
+ }
4216
+ return options.fetchPolicy;
4217
+ };
4194
4218
  ObservableQuery.prototype.fetch = function (options, newNetworkStatus) {
4195
4219
  this.queryManager.setObservableQuery(this);
4196
4220
  return this.queryManager.fetchQueryObservable(this.queryId, options, newNetworkStatus);
@@ -4261,8 +4285,8 @@ var ObservableQuery = (function (_super) {
4261
4285
  if (newOptions &&
4262
4286
  newOptions.variables &&
4263
4287
  !newOptions.fetchPolicy &&
4264
- !equality.equal(newOptions.variables, oldVariables)) {
4265
- options.fetchPolicy = this.initialFetchPolicy;
4288
+ !equal.equal(newOptions.variables, oldVariables)) {
4289
+ this.applyNextFetchPolicy("variables-changed");
4266
4290
  if (newNetworkStatus === void 0) {
4267
4291
  newNetworkStatus = exports.NetworkStatus.setVariables;
4268
4292
  }
@@ -4334,14 +4358,6 @@ function logMissingFieldErrors(missing) {
4334
4358
  __DEV__ && tsInvariant.invariant.debug("Missing cache result fields: ".concat(JSON.stringify(missing)), missing);
4335
4359
  }
4336
4360
  }
4337
- function applyNextFetchPolicy(options) {
4338
- var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a, nextFetchPolicy = options.nextFetchPolicy;
4339
- if (nextFetchPolicy) {
4340
- options.fetchPolicy = typeof nextFetchPolicy === "function"
4341
- ? nextFetchPolicy.call(options, fetchPolicy)
4342
- : nextFetchPolicy;
4343
- }
4344
- }
4345
4361
 
4346
4362
  var LocalState = (function () {
4347
4363
  function LocalState(_a) {
@@ -4643,10 +4659,10 @@ var QueryInfo = (function () {
4643
4659
  var networkStatus = query.networkStatus || exports.NetworkStatus.loading;
4644
4660
  if (this.variables &&
4645
4661
  this.networkStatus !== exports.NetworkStatus.loading &&
4646
- !equality.equal(this.variables, query.variables)) {
4662
+ !equal.equal(this.variables, query.variables)) {
4647
4663
  networkStatus = exports.NetworkStatus.setVariables;
4648
4664
  }
4649
- if (!equality.equal(query.variables, this.variables)) {
4665
+ if (!equal.equal(query.variables, this.variables)) {
4650
4666
  this.lastDiff = void 0;
4651
4667
  }
4652
4668
  Object.assign(this, {
@@ -4672,7 +4688,7 @@ var QueryInfo = (function () {
4672
4688
  QueryInfo.prototype.getDiff = function (variables) {
4673
4689
  if (variables === void 0) { variables = this.variables; }
4674
4690
  var options = this.getDiffOptions(variables);
4675
- if (this.lastDiff && equality.equal(options, this.lastDiff.options)) {
4691
+ if (this.lastDiff && equal.equal(options, this.lastDiff.options)) {
4676
4692
  return this.lastDiff.diff;
4677
4693
  }
4678
4694
  this.updateWatch(this.variables = variables);
@@ -4706,7 +4722,7 @@ var QueryInfo = (function () {
4706
4722
  var oldDiff = this.lastDiff && this.lastDiff.diff;
4707
4723
  this.updateLastDiff(diff);
4708
4724
  if (!this.dirty &&
4709
- !equality.equal(oldDiff && oldDiff.result, diff && diff.result)) {
4725
+ !equal.equal(oldDiff && oldDiff.result, diff && diff.result)) {
4710
4726
  this.dirty = true;
4711
4727
  if (!this.notifyTimeout) {
4712
4728
  this.notifyTimeout = setTimeout(function () { return _this.notify(); }, 0);
@@ -4780,7 +4796,7 @@ var QueryInfo = (function () {
4780
4796
  }
4781
4797
  var watchOptions = tslib.__assign(tslib.__assign({}, this.getDiffOptions(variables)), { watcher: this, callback: function (diff) { return _this.setDiff(diff); } });
4782
4798
  if (!this.lastWatch ||
4783
- !equality.equal(watchOptions, this.lastWatch)) {
4799
+ !equal.equal(watchOptions, this.lastWatch)) {
4784
4800
  this.cancel();
4785
4801
  this.cancel = this.cache.watch(this.lastWatch = watchOptions);
4786
4802
  }
@@ -4792,8 +4808,8 @@ var QueryInfo = (function () {
4792
4808
  var lastWrite = this.lastWrite;
4793
4809
  return !(lastWrite &&
4794
4810
  lastWrite.dmCount === destructiveMethodCounts.get(this.cache) &&
4795
- equality.equal(variables, lastWrite.variables) &&
4796
- equality.equal(result.data, lastWrite.result.data));
4811
+ equal.equal(variables, lastWrite.variables) &&
4812
+ equal.equal(result.data, lastWrite.result.data));
4797
4813
  };
4798
4814
  QueryInfo.prototype.markResult = function (result, options, cacheWriteBehavior) {
4799
4815
  var _this = this;
@@ -4870,10 +4886,10 @@ function shouldWriteResult(result, errorPolicy) {
4870
4886
  return writeWithErrors;
4871
4887
  }
4872
4888
 
4873
- var hasOwnProperty = Object.prototype.hasOwnProperty;
4889
+ var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
4874
4890
  var QueryManager = (function () {
4875
4891
  function QueryManager(_a) {
4876
- var cache = _a.cache, link = _a.link, _b = _a.queryDeduplication, queryDeduplication = _b === void 0 ? false : _b, onBroadcast = _a.onBroadcast, _c = _a.ssrMode, ssrMode = _c === void 0 ? false : _c, _d = _a.clientAwareness, clientAwareness = _d === void 0 ? {} : _d, localState = _a.localState, assumeImmutableResults = _a.assumeImmutableResults;
4892
+ var cache = _a.cache, link = _a.link, defaultOptions = _a.defaultOptions, _b = _a.queryDeduplication, queryDeduplication = _b === void 0 ? false : _b, onBroadcast = _a.onBroadcast, _c = _a.ssrMode, ssrMode = _c === void 0 ? false : _c, _d = _a.clientAwareness, clientAwareness = _d === void 0 ? {} : _d, localState = _a.localState, assumeImmutableResults = _a.assumeImmutableResults;
4877
4893
  this.clientAwareness = {};
4878
4894
  this.queries = new Map();
4879
4895
  this.fetchCancelFns = new Map();
@@ -4884,6 +4900,7 @@ var QueryManager = (function () {
4884
4900
  this.inFlightLinkObservables = new Map();
4885
4901
  this.cache = cache;
4886
4902
  this.link = link;
4903
+ this.defaultOptions = defaultOptions || Object.create(null);
4887
4904
  this.queryDeduplication = queryDeduplication;
4888
4905
  this.clientAwareness = clientAwareness;
4889
4906
  this.localState = localState || new LocalState({ cache: cache });
@@ -4905,11 +4922,12 @@ var QueryManager = (function () {
4905
4922
  this.fetchCancelFns.clear();
4906
4923
  };
4907
4924
  QueryManager.prototype.mutate = function (_a) {
4908
- var mutation = _a.mutation, variables = _a.variables, optimisticResponse = _a.optimisticResponse, updateQueries = _a.updateQueries, _b = _a.refetchQueries, refetchQueries = _b === void 0 ? [] : _b, _c = _a.awaitRefetchQueries, awaitRefetchQueries = _c === void 0 ? false : _c, updateWithProxyFn = _a.update, onQueryUpdated = _a.onQueryUpdated, _d = _a.errorPolicy, errorPolicy = _d === void 0 ? 'none' : _d, _e = _a.fetchPolicy, fetchPolicy = _e === void 0 ? 'network-only' : _e, keepRootFields = _a.keepRootFields, context = _a.context;
4925
+ var _b, _c;
4926
+ var mutation = _a.mutation, variables = _a.variables, optimisticResponse = _a.optimisticResponse, updateQueries = _a.updateQueries, _d = _a.refetchQueries, refetchQueries = _d === void 0 ? [] : _d, _e = _a.awaitRefetchQueries, awaitRefetchQueries = _e === void 0 ? false : _e, updateWithProxyFn = _a.update, onQueryUpdated = _a.onQueryUpdated, _f = _a.fetchPolicy, fetchPolicy = _f === void 0 ? ((_b = this.defaultOptions.mutate) === null || _b === void 0 ? void 0 : _b.fetchPolicy) || "network-only" : _f, _g = _a.errorPolicy, errorPolicy = _g === void 0 ? ((_c = this.defaultOptions.mutate) === null || _c === void 0 ? void 0 : _c.errorPolicy) || "none" : _g, keepRootFields = _a.keepRootFields, context = _a.context;
4909
4927
  return tslib.__awaiter(this, void 0, void 0, function () {
4910
4928
  var mutationId, mutationStoreValue, self;
4911
- return tslib.__generator(this, function (_f) {
4912
- switch (_f.label) {
4929
+ return tslib.__generator(this, function (_h) {
4930
+ switch (_h.label) {
4913
4931
  case 0:
4914
4932
  __DEV__ ? tsInvariant.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : tsInvariant.invariant(mutation, 12);
4915
4933
  __DEV__ ? tsInvariant.invariant(fetchPolicy === 'network-only' ||
@@ -4921,8 +4939,8 @@ var QueryManager = (function () {
4921
4939
  if (!this.transform(mutation).hasClientExports) return [3, 2];
4922
4940
  return [4, this.localState.addExportedVariables(mutation, variables, context)];
4923
4941
  case 1:
4924
- variables = (_f.sent());
4925
- _f.label = 2;
4942
+ variables = (_h.sent());
4943
+ _h.label = 2;
4926
4944
  case 2:
4927
4945
  mutationStoreValue = this.mutationStore &&
4928
4946
  (this.mutationStore[mutationId] = {
@@ -5023,7 +5041,7 @@ var QueryManager = (function () {
5023
5041
  this.queries.forEach(function (_a, queryId) {
5024
5042
  var observableQuery = _a.observableQuery;
5025
5043
  var queryName = observableQuery && observableQuery.queryName;
5026
- if (!queryName || !hasOwnProperty.call(updateQueries_1, queryName)) {
5044
+ if (!queryName || !hasOwnProperty$1.call(updateQueries_1, queryName)) {
5027
5045
  return;
5028
5046
  }
5029
5047
  var updater = updateQueries_1[queryName];
@@ -5482,7 +5500,8 @@ var QueryManager = (function () {
5482
5500
  var query = this.transform(options.query).document;
5483
5501
  var variables = this.getVariables(query, options.variables);
5484
5502
  var queryInfo = this.getQuery(queryId);
5485
- var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a, _b = options.errorPolicy, errorPolicy = _b === void 0 ? "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;
5503
+ var defaults = this.defaultOptions.watchQuery;
5504
+ 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;
5486
5505
  var normalized = Object.assign({}, options, {
5487
5506
  query: query,
5488
5507
  variables: variables,
@@ -5504,7 +5523,9 @@ var QueryManager = (function () {
5504
5523
  : fromVariables(normalized.variables));
5505
5524
  concast.cleanup(function () {
5506
5525
  _this.fetchCancelFns.delete(queryId);
5507
- applyNextFetchPolicy(options);
5526
+ if (queryInfo.observableQuery) {
5527
+ queryInfo.observableQuery["applyNextFetchPolicy"]("after-fetch", options);
5528
+ }
5508
5529
  });
5509
5530
  return concast;
5510
5531
  };
@@ -5591,7 +5612,7 @@ var QueryManager = (function () {
5591
5612
  var data = diff.result;
5592
5613
  if (__DEV__ &&
5593
5614
  !returnPartialData &&
5594
- !equality.equal(data, {})) {
5615
+ !equal.equal(data, {})) {
5595
5616
  logMissingFieldErrors(diff.missing);
5596
5617
  }
5597
5618
  var fromData = function (data) { return zenObservableTs.Observable.of(tslib.__assign({ data: data, loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus }, (diff.complete ? null : { partial: true }))); };
@@ -5700,7 +5721,6 @@ function mergeOptions(defaults, options) {
5700
5721
  var ApolloClient = (function () {
5701
5722
  function ApolloClient(options) {
5702
5723
  var _this = this;
5703
- this.defaultOptions = {};
5704
5724
  this.resetStoreCallbacks = [];
5705
5725
  this.clearStoreCallbacks = [];
5706
5726
  var uri = options.uri, credentials = options.credentials, headers = options.headers, cache = options.cache, _a = options.ssrMode, ssrMode = _a === void 0 ? false : _a, _b = options.ssrForceFetchDelay, ssrForceFetchDelay = _b === void 0 ? 0 : _b, _c = options.connectToDevTools, connectToDevTools = _c === void 0 ? typeof window === 'object' &&
@@ -5721,7 +5741,7 @@ var ApolloClient = (function () {
5721
5741
  this.cache = cache;
5722
5742
  this.disableNetworkFetches = ssrMode || ssrForceFetchDelay > 0;
5723
5743
  this.queryDeduplication = queryDeduplication;
5724
- this.defaultOptions = defaultOptions || {};
5744
+ this.defaultOptions = defaultOptions || Object.create(null);
5725
5745
  this.typeDefs = typeDefs;
5726
5746
  if (ssrForceFetchDelay) {
5727
5747
  setTimeout(function () { return (_this.disableNetworkFetches = false); }, ssrForceFetchDelay);
@@ -5768,6 +5788,7 @@ var ApolloClient = (function () {
5768
5788
  this.queryManager = new QueryManager({
5769
5789
  cache: this.cache,
5770
5790
  link: this.link,
5791
+ defaultOptions: this.defaultOptions,
5771
5792
  queryDeduplication: queryDeduplication,
5772
5793
  ssrMode: ssrMode,
5773
5794
  clientAwareness: {
@@ -6054,227 +6075,274 @@ function verifyDocumentType(document, type) {
6054
6075
  "".concat(requiredOperationName, ", but a ").concat(usedOperationName, " was used instead.")) : tsInvariant.invariant(operation.type === type, 34);
6055
6076
  }
6056
6077
 
6057
- function useQuery(query, options) {
6058
- var _a;
6059
- var context = React.useContext(getApolloContext());
6060
- var client = useApolloClient(options === null || options === void 0 ? void 0 : options.client);
6061
- var defaultWatchQueryOptions = client.defaultOptions.watchQuery;
6062
- verifyDocumentType(query, exports.DocumentType.Query);
6063
- var _b = React.useState(function () {
6064
- var watchQueryOptions = createWatchQueryOptions(query, options, defaultWatchQueryOptions);
6065
- var obsQuery = null;
6066
- if (context.renderPromises) {
6067
- obsQuery = context.renderPromises.getSSRObservable(watchQueryOptions);
6068
- }
6069
- if (!obsQuery) {
6070
- obsQuery = client.watchQuery(watchQueryOptions);
6071
- if (context.renderPromises) {
6072
- context.renderPromises.registerSSRObservable(obsQuery, watchQueryOptions);
6073
- }
6074
- }
6075
- if (context.renderPromises &&
6076
- (options === null || options === void 0 ? void 0 : options.ssr) !== false &&
6077
- !(options === null || options === void 0 ? void 0 : options.skip) &&
6078
- obsQuery.getCurrentResult().loading) {
6079
- context.renderPromises.addQueryPromise({
6080
- getOptions: function () { return createWatchQueryOptions(query, options, defaultWatchQueryOptions); },
6081
- fetchData: function () { return new Promise(function (resolve) {
6082
- var sub = obsQuery.subscribe({
6083
- next: function (result) {
6084
- if (!result.loading) {
6078
+ function useNormalizedOptions(optionsOrFunction) {
6079
+ var optionsRef = React.useRef();
6080
+ var options = optionsRef.current || Object.create(null);
6081
+ if (typeof optionsOrFunction === "function") {
6082
+ var newOptions = optionsOrFunction(options);
6083
+ if (newOptions !== options) {
6084
+ Object.assign(options, newOptions, newOptions.variables && {
6085
+ variables: tslib.__assign(tslib.__assign({}, options.variables), newOptions.variables),
6086
+ });
6087
+ }
6088
+ }
6089
+ else if (optionsOrFunction && !equal__default(optionsOrFunction, options)) {
6090
+ options = optionsOrFunction;
6091
+ }
6092
+ return optionsRef.current = options;
6093
+ }
6094
+
6095
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
6096
+ function useQuery(query, optionsOrFunction) {
6097
+ var options = useNormalizedOptions(optionsOrFunction);
6098
+ return useInternalState(useApolloClient(options.client), query).useQuery(options);
6099
+ }
6100
+ function useInternalState(client, query) {
6101
+ var stateRef = React.useRef();
6102
+ if (!stateRef.current ||
6103
+ client !== stateRef.current.client ||
6104
+ query !== stateRef.current.query) {
6105
+ stateRef.current = new InternalState(client, query);
6106
+ }
6107
+ var state = stateRef.current;
6108
+ var _a = React.useState(0); _a[0]; var setTick = _a[1];
6109
+ state.forceUpdate = function () {
6110
+ setTick(function (tick) { return tick + 1; });
6111
+ };
6112
+ return state;
6113
+ }
6114
+ var InternalState = (function () {
6115
+ function InternalState(client, query) {
6116
+ this.client = client;
6117
+ this.query = query;
6118
+ this.toQueryResultCache = new (canUseWeakMap ? WeakMap : Map)();
6119
+ verifyDocumentType(query, exports.DocumentType.Query);
6120
+ }
6121
+ InternalState.prototype.forceUpdate = function () {
6122
+ };
6123
+ InternalState.prototype.useQuery = function (options) {
6124
+ this.useOptions(options);
6125
+ var obsQuery = this.useObservableQuery();
6126
+ this.useSubscriptionEffect(obsQuery);
6127
+ var result = this.getCurrentResult();
6128
+ this.unsafeHandlePartialRefetch(result);
6129
+ return this.toQueryResult(result);
6130
+ };
6131
+ InternalState.prototype.useOptions = function (options) {
6132
+ this.renderPromises = React.useContext(getApolloContext()).renderPromises;
6133
+ var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
6134
+ if (!equal.equal(watchQueryOptions, this.watchQueryOptions)) {
6135
+ this.watchQueryOptions = watchQueryOptions;
6136
+ }
6137
+ this.ssrDisabled = !!(options && (options.ssr === false ||
6138
+ options.skip));
6139
+ this.onCompleted = options
6140
+ && options.onCompleted
6141
+ || InternalState.prototype.onCompleted;
6142
+ this.onError = options
6143
+ && options.onError
6144
+ || InternalState.prototype.onError;
6145
+ };
6146
+ InternalState.prototype.createWatchQueryOptions = function (_a) {
6147
+ var _b;
6148
+ if (_a === void 0) { _a = {}; }
6149
+ var skip = _a.skip; _a.ssr; _a.onCompleted; _a.onError; _a.displayName; var otherOptions = tslib.__rest(_a, ["skip", "ssr", "onCompleted", "onError", "displayName"]);
6150
+ var watchQueryOptions = Object.assign(otherOptions, { query: this.query });
6151
+ if (skip) {
6152
+ watchQueryOptions.fetchPolicy = 'standby';
6153
+ }
6154
+ else if (((_b = watchQueryOptions.context) === null || _b === void 0 ? void 0 : _b.renderPromises) &&
6155
+ (watchQueryOptions.fetchPolicy === 'network-only' ||
6156
+ watchQueryOptions.fetchPolicy === 'cache-and-network')) {
6157
+ watchQueryOptions.fetchPolicy = 'cache-first';
6158
+ }
6159
+ else if (!watchQueryOptions.fetchPolicy) {
6160
+ var defaultOptions = this.client.defaultOptions.watchQuery;
6161
+ watchQueryOptions.fetchPolicy =
6162
+ defaultOptions && defaultOptions.fetchPolicy || 'cache-first';
6163
+ }
6164
+ if (!watchQueryOptions.variables) {
6165
+ watchQueryOptions.variables = {};
6166
+ }
6167
+ return watchQueryOptions;
6168
+ };
6169
+ InternalState.prototype.onCompleted = function (data) { };
6170
+ InternalState.prototype.onError = function (error) { };
6171
+ InternalState.prototype.useObservableQuery = function () {
6172
+ var _this = this;
6173
+ var obsQuery = this.observable =
6174
+ this.renderPromises
6175
+ && this.renderPromises.getSSRObservable(this.watchQueryOptions)
6176
+ || this.observable
6177
+ || this.client.watchQuery(this.watchQueryOptions);
6178
+ this.obsQueryFields = React.useMemo(function () { return ({
6179
+ refetch: obsQuery.refetch.bind(obsQuery),
6180
+ fetchMore: obsQuery.fetchMore.bind(obsQuery),
6181
+ updateQuery: obsQuery.updateQuery.bind(obsQuery),
6182
+ startPolling: obsQuery.startPolling.bind(obsQuery),
6183
+ stopPolling: obsQuery.stopPolling.bind(obsQuery),
6184
+ subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
6185
+ }); }, [obsQuery]);
6186
+ if (this.renderPromises) {
6187
+ this.renderPromises.registerSSRObservable(obsQuery);
6188
+ if (!this.ssrDisabled && obsQuery.getCurrentResult().loading) {
6189
+ this.renderPromises.addQueryPromise({
6190
+ getOptions: function () { return obsQuery.options; },
6191
+ fetchData: function () { return new Promise(function (resolve) {
6192
+ var sub = obsQuery.subscribe({
6193
+ next: function (result) {
6194
+ if (!result.loading) {
6195
+ resolve();
6196
+ sub.unsubscribe();
6197
+ }
6198
+ },
6199
+ error: function () {
6085
6200
  resolve();
6086
6201
  sub.unsubscribe();
6087
- }
6088
- },
6089
- error: function () {
6090
- resolve();
6091
- sub.unsubscribe();
6092
- },
6093
- complete: function () {
6094
- resolve();
6095
- },
6096
- });
6097
- }); },
6098
- }, function () { return null; });
6202
+ },
6203
+ complete: function () {
6204
+ resolve();
6205
+ },
6206
+ });
6207
+ }); },
6208
+ }, function () { return null; });
6209
+ obsQuery.setOptions(this.watchQueryOptions).catch(function () { });
6210
+ }
6099
6211
  }
6212
+ var prevOptionsRef = React.useRef({
6213
+ watchQueryOptions: this.watchQueryOptions,
6214
+ });
6215
+ React.useEffect(function () {
6216
+ if (_this.renderPromises) ;
6217
+ else if (_this.watchQueryOptions !== prevOptionsRef.current.watchQueryOptions) {
6218
+ obsQuery.setOptions(_this.watchQueryOptions).catch(function () { });
6219
+ prevOptionsRef.current.watchQueryOptions = _this.watchQueryOptions;
6220
+ _this.setResult(obsQuery.getCurrentResult());
6221
+ }
6222
+ }, [obsQuery, this.watchQueryOptions]);
6100
6223
  return obsQuery;
6101
- }), obsQuery = _b[0], setObsQuery = _b[1];
6102
- var _c = React.useState(function () {
6103
- var _a, _b;
6104
- var result = obsQuery.getCurrentResult();
6105
- if (!result.loading && options) {
6224
+ };
6225
+ InternalState.prototype.useSubscriptionEffect = function (obsQuery) {
6226
+ var _this = this;
6227
+ React.useEffect(function () {
6228
+ if (_this.renderPromises) {
6229
+ return;
6230
+ }
6231
+ var onNext = function () {
6232
+ var previousResult = _this.result;
6233
+ var result = obsQuery.getCurrentResult();
6234
+ if (previousResult &&
6235
+ previousResult.loading === result.loading &&
6236
+ previousResult.networkStatus === result.networkStatus &&
6237
+ equal.equal(previousResult.data, result.data)) {
6238
+ return;
6239
+ }
6240
+ _this.setResult(result);
6241
+ };
6242
+ var onError = function (error) {
6243
+ var last = obsQuery["last"];
6244
+ subscription.unsubscribe();
6245
+ try {
6246
+ obsQuery.resetLastResults();
6247
+ subscription = obsQuery.subscribe(onNext, onError);
6248
+ }
6249
+ finally {
6250
+ obsQuery["last"] = last;
6251
+ }
6252
+ if (!hasOwnProperty.call(error, 'graphQLErrors')) {
6253
+ throw error;
6254
+ }
6255
+ var previousResult = _this.result;
6256
+ if (!previousResult ||
6257
+ (previousResult && previousResult.loading) ||
6258
+ !equal.equal(error, previousResult.error)) {
6259
+ _this.setResult({
6260
+ data: (previousResult && previousResult.data),
6261
+ error: error,
6262
+ loading: false,
6263
+ networkStatus: exports.NetworkStatus.error,
6264
+ });
6265
+ }
6266
+ };
6267
+ var subscription = obsQuery.subscribe(onNext, onError);
6268
+ return function () { return subscription.unsubscribe(); };
6269
+ }, [
6270
+ obsQuery,
6271
+ this.renderPromises,
6272
+ this.client.disableNetworkFetches,
6273
+ ]);
6274
+ };
6275
+ InternalState.prototype.setResult = function (nextResult) {
6276
+ var previousResult = this.result;
6277
+ if (previousResult && previousResult.data) {
6278
+ this.previousData = previousResult.data;
6279
+ }
6280
+ this.result = nextResult;
6281
+ this.forceUpdate();
6282
+ this.handleErrorOrCompleted(nextResult);
6283
+ };
6284
+ InternalState.prototype.handleErrorOrCompleted = function (result) {
6285
+ if (!result.loading) {
6106
6286
  if (result.error) {
6107
- (_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, result.error);
6287
+ this.onError(result.error);
6108
6288
  }
6109
6289
  else if (result.data) {
6110
- (_b = options.onCompleted) === null || _b === void 0 ? void 0 : _b.call(options, result.data);
6290
+ this.onCompleted(result.data);
6111
6291
  }
6112
6292
  }
6113
- return result;
6114
- }), result = _c[0], setResult = _c[1];
6115
- var ref = React.useRef({
6116
- client: client,
6117
- query: query,
6118
- options: options,
6119
- result: result,
6120
- previousData: void 0,
6121
- watchQueryOptions: createWatchQueryOptions(query, options, defaultWatchQueryOptions),
6122
- });
6123
- React.useEffect(function () {
6124
- var _a, _b;
6125
- var watchQueryOptions = createWatchQueryOptions(query, options, defaultWatchQueryOptions);
6126
- var nextResult;
6127
- if (ref.current.client !== client || !equality.equal(ref.current.query, query)) {
6128
- var obsQuery_1 = client.watchQuery(watchQueryOptions);
6129
- setObsQuery(obsQuery_1);
6130
- nextResult = obsQuery_1.getCurrentResult();
6131
- }
6132
- else if (!equality.equal(ref.current.watchQueryOptions, watchQueryOptions)) {
6133
- obsQuery.setOptions(watchQueryOptions).catch(function () { });
6134
- nextResult = obsQuery.getCurrentResult();
6135
- ref.current.watchQueryOptions = watchQueryOptions;
6136
- }
6137
- if (nextResult) {
6138
- var previousResult = ref.current.result;
6139
- if (previousResult.data) {
6140
- ref.current.previousData = previousResult.data;
6141
- }
6142
- setResult(ref.current.result = nextResult);
6143
- if (!nextResult.loading && options) {
6144
- if (nextResult.error) {
6145
- (_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, nextResult.error);
6146
- }
6147
- else if (nextResult.data) {
6148
- (_b = options.onCompleted) === null || _b === void 0 ? void 0 : _b.call(options, nextResult.data);
6149
- }
6150
- }
6293
+ };
6294
+ InternalState.prototype.getCurrentResult = function () {
6295
+ var result = this.result;
6296
+ if (!result) {
6297
+ result = this.result = this.observable.getCurrentResult();
6298
+ this.handleErrorOrCompleted(result);
6151
6299
  }
6152
- Object.assign(ref.current, { client: client, query: query });
6153
- }, [obsQuery, client, query, options]);
6154
- React.useEffect(function () {
6155
- if (context.renderPromises) {
6156
- return;
6300
+ if ((this.renderPromises || this.client.disableNetworkFetches) &&
6301
+ this.queryHookOptions.ssr === false) {
6302
+ result = {
6303
+ loading: true,
6304
+ data: void 0,
6305
+ error: void 0,
6306
+ networkStatus: exports.NetworkStatus.loading,
6307
+ };
6157
6308
  }
6158
- var subscription = obsQuery.subscribe(onNext, onError);
6159
- function onNext() {
6160
- var _a, _b;
6161
- var previousResult = ref.current.result;
6162
- var result = obsQuery.getCurrentResult();
6163
- if (previousResult &&
6164
- previousResult.loading === result.loading &&
6165
- previousResult.networkStatus === result.networkStatus &&
6166
- equality.equal(previousResult.data, result.data)) {
6167
- return;
6168
- }
6169
- if (previousResult.data) {
6170
- ref.current.previousData = previousResult.data;
6171
- }
6172
- setResult(ref.current.result = result);
6173
- if (!result.loading) {
6174
- (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onCompleted) === null || _b === void 0 ? void 0 : _b.call(_a, result.data);
6175
- }
6309
+ else if (this.queryHookOptions.skip ||
6310
+ this.queryHookOptions.fetchPolicy === 'standby') {
6311
+ result = {
6312
+ loading: false,
6313
+ data: void 0,
6314
+ error: void 0,
6315
+ networkStatus: exports.NetworkStatus.ready,
6316
+ };
6176
6317
  }
6177
- function onError(error) {
6178
- var _a, _b;
6179
- var last = obsQuery["last"];
6180
- subscription.unsubscribe();
6181
- try {
6182
- obsQuery.resetLastResults();
6183
- subscription = obsQuery.subscribe(onNext, onError);
6184
- }
6185
- finally {
6186
- obsQuery["last"] = last;
6187
- }
6188
- if (!error.hasOwnProperty('graphQLErrors')) {
6189
- throw error;
6190
- }
6191
- var previousResult = ref.current.result;
6192
- if ((previousResult && previousResult.loading) ||
6193
- !equality.equal(error, previousResult.error)) {
6194
- setResult(ref.current.result = {
6195
- data: previousResult.data,
6196
- error: error,
6197
- loading: false,
6198
- networkStatus: exports.NetworkStatus.error,
6199
- });
6200
- (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
6201
- }
6318
+ return result;
6319
+ };
6320
+ InternalState.prototype.toQueryResult = function (result) {
6321
+ var queryResult = this.toQueryResultCache.get(result);
6322
+ if (queryResult)
6323
+ return queryResult;
6324
+ var data = result.data; result.partial; var resultWithoutPartial = tslib.__rest(result, ["data", "partial"]);
6325
+ this.toQueryResultCache.set(result, queryResult = tslib.__assign(tslib.__assign(tslib.__assign({ data: data }, resultWithoutPartial), this.obsQueryFields), { client: this.client, observable: this.observable, variables: this.observable.variables, called: true, previousData: this.previousData }));
6326
+ if (!queryResult.error && isNonEmptyArray(result.errors)) {
6327
+ queryResult.error = new ApolloError({ graphQLErrors: result.errors });
6202
6328
  }
6203
- return function () { return subscription.unsubscribe(); };
6204
- }, [obsQuery, context.renderPromises, client.disableNetworkFetches]);
6205
- var partial;
6206
- (_a = result, partial = _a.partial, result = tslib.__rest(_a, ["partial"]));
6207
- {
6208
- if (partial &&
6209
- (options === null || options === void 0 ? void 0 : options.partialRefetch) &&
6329
+ return queryResult;
6330
+ };
6331
+ InternalState.prototype.unsafeHandlePartialRefetch = function (result) {
6332
+ if (result.partial &&
6333
+ this.queryHookOptions.partialRefetch &&
6210
6334
  !result.loading &&
6211
6335
  (!result.data || Object.keys(result.data).length === 0) &&
6212
- obsQuery.options.fetchPolicy !== 'cache-only') {
6213
- result = tslib.__assign(tslib.__assign({}, result), { loading: true, networkStatus: exports.NetworkStatus.refetch });
6214
- obsQuery.refetch();
6215
- }
6216
- if (context.renderPromises &&
6217
- (options === null || options === void 0 ? void 0 : options.ssr) !== false &&
6218
- !(options === null || options === void 0 ? void 0 : options.skip) &&
6219
- result.loading) {
6220
- obsQuery.setOptions(createWatchQueryOptions(query, options, defaultWatchQueryOptions)).catch(function () { });
6336
+ this.observable.options.fetchPolicy !== 'cache-only') {
6337
+ Object.assign(result, {
6338
+ loading: true,
6339
+ networkStatus: exports.NetworkStatus.refetch,
6340
+ });
6341
+ this.observable.refetch();
6221
6342
  }
6222
- Object.assign(ref.current, { options: options });
6223
- }
6224
- if ((context.renderPromises || client.disableNetworkFetches) &&
6225
- (options === null || options === void 0 ? void 0 : options.ssr) === false) {
6226
- result = ref.current.result = {
6227
- loading: true,
6228
- data: void 0,
6229
- error: void 0,
6230
- networkStatus: exports.NetworkStatus.loading,
6231
- };
6232
- }
6233
- else if ((options === null || options === void 0 ? void 0 : options.skip) || (options === null || options === void 0 ? void 0 : options.fetchPolicy) === 'standby') {
6234
- result = {
6235
- loading: false,
6236
- data: void 0,
6237
- error: void 0,
6238
- networkStatus: exports.NetworkStatus.ready,
6239
- };
6240
- }
6241
- if (result.errors && result.errors.length) {
6242
- result = tslib.__assign(tslib.__assign({}, result), { error: result.error || new ApolloError({ graphQLErrors: result.errors }) });
6243
- }
6244
- var obsQueryFields = React.useMemo(function () { return ({
6245
- refetch: obsQuery.refetch.bind(obsQuery),
6246
- fetchMore: obsQuery.fetchMore.bind(obsQuery),
6247
- updateQuery: obsQuery.updateQuery.bind(obsQuery),
6248
- startPolling: obsQuery.startPolling.bind(obsQuery),
6249
- stopPolling: obsQuery.stopPolling.bind(obsQuery),
6250
- subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
6251
- }); }, [obsQuery]);
6252
- return tslib.__assign(tslib.__assign(tslib.__assign({}, obsQueryFields), { variables: createWatchQueryOptions(query, options, defaultWatchQueryOptions).variables, client: client, called: true, previousData: ref.current.previousData }), result);
6253
- }
6254
- function createWatchQueryOptions(query, options, defaultOptions) {
6255
- var _a;
6256
- if (options === void 0) { options = {}; }
6257
- var skip = options.skip; options.ssr; options.onCompleted; options.onError; options.displayName; var otherOptions = tslib.__rest(options, ["skip", "ssr", "onCompleted", "onError", "displayName"]);
6258
- var watchQueryOptions = tslib.__assign({ query: query }, otherOptions);
6259
- if (defaultOptions) {
6260
- watchQueryOptions = mergeOptions(defaultOptions, watchQueryOptions);
6261
- }
6262
- if (skip) {
6263
- watchQueryOptions.fetchPolicy = 'standby';
6264
- }
6265
- else if (((_a = watchQueryOptions.context) === null || _a === void 0 ? void 0 : _a.renderPromises) &&
6266
- (watchQueryOptions.fetchPolicy === 'network-only' ||
6267
- watchQueryOptions.fetchPolicy === 'cache-and-network')) {
6268
- watchQueryOptions.fetchPolicy = 'cache-first';
6269
- }
6270
- else if (!watchQueryOptions.fetchPolicy) {
6271
- watchQueryOptions.fetchPolicy = 'cache-first';
6272
- }
6273
- if (!watchQueryOptions.variables) {
6274
- watchQueryOptions.variables = {};
6275
- }
6276
- return watchQueryOptions;
6277
- }
6343
+ };
6344
+ return InternalState;
6345
+ }());
6278
6346
 
6279
6347
  var EAGER_METHODS = [
6280
6348
  'refetch',
@@ -6283,7 +6351,8 @@ var EAGER_METHODS = [
6283
6351
  'startPolling',
6284
6352
  'subscribeToMore',
6285
6353
  ];
6286
- function useLazyQuery(query, options) {
6354
+ function useLazyQuery(query, optionsOrFunction) {
6355
+ var options = useNormalizedOptions(optionsOrFunction);
6287
6356
  var _a = React.useState({
6288
6357
  called: false,
6289
6358
  }), execution = _a[0], setExecution = _a[1];
@@ -6374,7 +6443,7 @@ function useMutation(mutation, options) {
6374
6443
  error: error,
6375
6444
  client: client,
6376
6445
  };
6377
- if (ref.current.isMounted && !equality.equal(ref.current.result, result_1)) {
6446
+ if (ref.current.isMounted && !equal.equal(ref.current.result, result_1)) {
6378
6447
  setResult(ref.current.result = result_1);
6379
6448
  }
6380
6449
  }
@@ -6392,7 +6461,7 @@ function useMutation(mutation, options) {
6392
6461
  called: true,
6393
6462
  client: client,
6394
6463
  };
6395
- if (!equality.equal(ref.current.result, result_2)) {
6464
+ if (!equal.equal(ref.current.result, result_2)) {
6396
6465
  setResult(ref.current.result = result_2);
6397
6466
  }
6398
6467
  }
@@ -6455,7 +6524,7 @@ function useSubscription(subscription, options) {
6455
6524
  subscription !== ref.current.subscription ||
6456
6525
  (options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
6457
6526
  !(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
6458
- !equality.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) {
6527
+ !equal.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) {
6459
6528
  setResult({
6460
6529
  loading: true,
6461
6530
  data: void 0,
@@ -6542,7 +6611,6 @@ exports.HttpLink = HttpLink;
6542
6611
  exports.InMemoryCache = InMemoryCache;
6543
6612
  exports.MissingFieldError = MissingFieldError;
6544
6613
  exports.ObservableQuery = ObservableQuery;
6545
- exports.applyNextFetchPolicy = applyNextFetchPolicy;
6546
6614
  exports.checkFetcher = checkFetcher;
6547
6615
  exports.concat = concat;
6548
6616
  exports.createHttpLink = createHttpLink;