@apollo/client 3.6.0-beta.5 → 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.
Files changed (60) hide show
  1. package/apollo-client.cjs +322 -267
  2. package/apollo-client.cjs.map +1 -1
  3. package/apollo-client.min.cjs +1 -1
  4. package/cache/cache.cjs +21 -20
  5. package/cache/cache.cjs.map +1 -1
  6. package/cache/inmemory/helpers.d.ts +1 -0
  7. package/cache/inmemory/helpers.d.ts.map +1 -1
  8. package/cache/inmemory/helpers.js +3 -2
  9. package/cache/inmemory/helpers.js.map +1 -1
  10. package/cache/inmemory/key-extractor.js +5 -5
  11. package/cache/inmemory/key-extractor.js.map +1 -1
  12. package/cache/inmemory/object-canon.d.ts.map +1 -1
  13. package/cache/inmemory/object-canon.js +2 -1
  14. package/cache/inmemory/object-canon.js.map +1 -1
  15. package/cache/inmemory/policies.d.ts +1 -1
  16. package/cache/inmemory/policies.d.ts.map +1 -1
  17. package/cache/inmemory/policies.js +6 -6
  18. package/cache/inmemory/policies.js.map +1 -1
  19. package/cache/inmemory/readFromStore.js +3 -3
  20. package/cache/inmemory/readFromStore.js.map +1 -1
  21. package/cache/inmemory/writeToStore.js +7 -7
  22. package/cache/inmemory/writeToStore.js.map +1 -1
  23. package/core/ApolloClient.d.ts.map +1 -1
  24. package/core/ApolloClient.js +2 -2
  25. package/core/ApolloClient.js.map +1 -1
  26. package/core/QueryManager.d.ts +5 -2
  27. package/core/QueryManager.d.ts.map +1 -1
  28. package/core/QueryManager.js +10 -7
  29. package/core/QueryManager.js.map +1 -1
  30. package/core/core.cjs +13 -10
  31. package/core/core.cjs.map +1 -1
  32. package/invariantErrorCodes.js +1 -1
  33. package/package.json +13 -13
  34. package/react/hooks/hooks.cjs +262 -209
  35. package/react/hooks/hooks.cjs.map +1 -1
  36. package/react/hooks/options.d.ts +3 -0
  37. package/react/hooks/options.d.ts.map +1 -0
  38. package/react/hooks/options.js +20 -0
  39. package/react/hooks/options.js.map +1 -0
  40. package/react/hooks/useLazyQuery.d.ts +2 -2
  41. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  42. package/react/hooks/useLazyQuery.js +3 -1
  43. package/react/hooks/useLazyQuery.js.map +1 -1
  44. package/react/hooks/useQuery.d.ts +2 -2
  45. package/react/hooks/useQuery.d.ts.map +1 -1
  46. package/react/hooks/useQuery.js +237 -205
  47. package/react/hooks/useQuery.js.map +1 -1
  48. package/react/ssr/RenderPromises.d.ts +1 -1
  49. package/react/ssr/RenderPromises.d.ts.map +1 -1
  50. package/react/ssr/RenderPromises.js +2 -2
  51. package/react/ssr/RenderPromises.js.map +1 -1
  52. package/react/ssr/ssr.cjs +2 -2
  53. package/react/ssr/ssr.cjs.map +1 -1
  54. package/react/types/types.d.ts +3 -0
  55. package/react/types/types.d.ts.map +1 -1
  56. package/react/types/types.js.map +1 -1
  57. package/utilities/globals/global.d.ts +2 -8
  58. package/utilities/globals/global.d.ts.map +1 -1
  59. package/utilities/globals/global.js.map +1 -1
  60. 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.5';
1297
+ var version = '3.6.0-beta.8';
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, "'."));
@@ -1726,7 +1729,7 @@ function fieldNameFromStoreName(storeFieldName) {
1726
1729
  }
1727
1730
  function selectionSetMatchesResult(selectionSet, result, variables) {
1728
1731
  if (isNonNullObject(result)) {
1729
- return Array.isArray(result)
1732
+ return isArray(result)
1730
1733
  ? result.every(function (item) { return selectionSetMatchesResult(selectionSet, item, variables); })
1731
1734
  : selectionSet.selections.every(function (field) {
1732
1735
  if (isField(field) && shouldInclude(field, variables)) {
@@ -1743,11 +1746,12 @@ function selectionSetMatchesResult(selectionSet, result, variables) {
1743
1746
  function storeValueIsStoreObject(value) {
1744
1747
  return isNonNullObject(value) &&
1745
1748
  !isReference(value) &&
1746
- !Array.isArray(value);
1749
+ !isArray(value);
1747
1750
  }
1748
1751
  function makeProcessedFieldsMerger() {
1749
1752
  return new DeepMerger;
1750
1753
  }
1754
+ var isArray = function (a) { return Array.isArray(a); };
1751
1755
 
1752
1756
  var DELETE = Object.create(null);
1753
1757
  var delModifier = function () { return DELETE; };
@@ -2158,7 +2162,7 @@ var Layer = (function (_super) {
2158
2162
  }
2159
2163
  else if (ownStoreObject !== parentStoreObject) {
2160
2164
  Object.keys(ownStoreObject).forEach(function (storeFieldName) {
2161
- if (!equality.equal(ownStoreObject[storeFieldName], parentStoreObject[storeFieldName])) {
2165
+ if (!equal.equal(ownStoreObject[storeFieldName], parentStoreObject[storeFieldName])) {
2162
2166
  _this.group.dirty(dataId, storeFieldName);
2163
2167
  }
2164
2168
  });
@@ -2202,7 +2206,7 @@ var Stump = (function (_super) {
2202
2206
  function storeObjectReconciler(existingObject, incomingObject, property) {
2203
2207
  var existingValue = existingObject[property];
2204
2208
  var incomingValue = incomingObject[property];
2205
- return equality.equal(existingValue, incomingValue) ? existingValue : incomingValue;
2209
+ return equal.equal(existingValue, incomingValue) ? existingValue : incomingValue;
2206
2210
  }
2207
2211
  function supportsResultCaching(store) {
2208
2212
  return !!(store instanceof EntityStore && store.group.caching);
@@ -2210,7 +2214,7 @@ function supportsResultCaching(store) {
2210
2214
 
2211
2215
  function shallowCopy(value) {
2212
2216
  if (isNonNullObject(value)) {
2213
- return Array.isArray(value)
2217
+ return isArray(value)
2214
2218
  ? value.slice(0)
2215
2219
  : tslib.__assign({ __proto__: Object.getPrototypeOf(value) }, value);
2216
2220
  }
@@ -2473,7 +2477,7 @@ var StoreReader = (function () {
2473
2477
  _a));
2474
2478
  }
2475
2479
  }
2476
- else if (Array.isArray(fieldValue)) {
2480
+ else if (isArray(fieldValue)) {
2477
2481
  fieldValue = handleMissing(_this.executeSubSelectedArray({
2478
2482
  field: selection,
2479
2483
  array: fieldValue,
@@ -2532,7 +2536,7 @@ var StoreReader = (function () {
2532
2536
  if (item === null) {
2533
2537
  return null;
2534
2538
  }
2535
- if (Array.isArray(item)) {
2539
+ if (isArray(item)) {
2536
2540
  return handleMissing(_this.executeSubSelectedArray({
2537
2541
  field: field,
2538
2542
  array: item,
@@ -2726,13 +2730,13 @@ function getSpecifierPaths(spec) {
2726
2730
  var paths_1 = info.paths = [];
2727
2731
  var currentPath_1 = [];
2728
2732
  spec.forEach(function (s, i) {
2729
- if (Array.isArray(s)) {
2733
+ if (isArray(s)) {
2730
2734
  getSpecifierPaths(s).forEach(function (p) { return paths_1.push(currentPath_1.concat(p)); });
2731
2735
  currentPath_1.length = 0;
2732
2736
  }
2733
2737
  else {
2734
2738
  currentPath_1.push(s);
2735
- if (!Array.isArray(spec[i + 1])) {
2739
+ if (!isArray(spec[i + 1])) {
2736
2740
  paths_1.push(currentPath_1.slice(0));
2737
2741
  currentPath_1.length = 0;
2738
2742
  }
@@ -2747,14 +2751,14 @@ function extractKey(object, key) {
2747
2751
  function extractKeyPath(object, path, extract) {
2748
2752
  extract = extract || extractKey;
2749
2753
  return normalize(path.reduce(function reducer(obj, key) {
2750
- return Array.isArray(obj)
2754
+ return isArray(obj)
2751
2755
  ? obj.map(function (child) { return reducer(child, key); })
2752
2756
  : obj && extract(obj, key);
2753
2757
  }, object));
2754
2758
  }
2755
2759
  function normalize(value) {
2756
2760
  if (isNonNullObject(value)) {
2757
- if (Array.isArray(value)) {
2761
+ if (isArray(value)) {
2758
2762
  return value.map(normalize);
2759
2763
  }
2760
2764
  return collectSpecifierPaths(Object.keys(value).sort(), function (path) { return extractKeyPath(value, path); });
@@ -2817,7 +2821,7 @@ var Policies = (function () {
2817
2821
  var keyFn = policy && policy.keyFn || this.config.dataIdFromObject;
2818
2822
  while (keyFn) {
2819
2823
  var specifierOrId = keyFn(object, context);
2820
- if (Array.isArray(specifierOrId)) {
2824
+ if (isArray(specifierOrId)) {
2821
2825
  keyFn = keyFieldsFnFromSpecifier(specifierOrId);
2822
2826
  }
2823
2827
  else {
@@ -2860,7 +2864,7 @@ var Policies = (function () {
2860
2864
  setMerge(existing, incoming.merge);
2861
2865
  existing.keyFn =
2862
2866
  keyFields === false ? nullKeyFieldsFn :
2863
- Array.isArray(keyFields) ? keyFieldsFnFromSpecifier(keyFields) :
2867
+ isArray(keyFields) ? keyFieldsFnFromSpecifier(keyFields) :
2864
2868
  typeof keyFields === "function" ? keyFields :
2865
2869
  existing.keyFn;
2866
2870
  if (fields) {
@@ -2874,7 +2878,7 @@ var Policies = (function () {
2874
2878
  var keyArgs = incoming.keyArgs, read = incoming.read, merge = incoming.merge;
2875
2879
  existing.keyFn =
2876
2880
  keyArgs === false ? simpleKeyArgsFn :
2877
- Array.isArray(keyArgs) ? keyArgsFnFromSpecifier(keyArgs) :
2881
+ isArray(keyArgs) ? keyArgsFnFromSpecifier(keyArgs) :
2878
2882
  typeof keyArgs === "function" ? keyArgs :
2879
2883
  existing.keyFn;
2880
2884
  if (typeof read === "function") {
@@ -3019,7 +3023,7 @@ var Policies = (function () {
3019
3023
  var args = argsFromFieldSpecifier(fieldSpec);
3020
3024
  while (keyFn) {
3021
3025
  var specifierOrString = keyFn(args, context);
3022
- if (Array.isArray(specifierOrString)) {
3026
+ if (isArray(specifierOrString)) {
3023
3027
  keyFn = keyArgsFnFromSpecifier(specifierOrString);
3024
3028
  }
3025
3029
  else {
@@ -3140,7 +3144,7 @@ function normalizeReadFieldOptions(readFieldArgs, objectOrReference, variables)
3140
3144
  }
3141
3145
  function makeMergeObjectsFunction(store) {
3142
3146
  return function mergeObjects(existing, incoming) {
3143
- if (Array.isArray(existing) || Array.isArray(incoming)) {
3147
+ if (isArray(existing) || isArray(incoming)) {
3144
3148
  throw __DEV__ ? new tsInvariant.InvariantError("Cannot automatically merge arrays") : new tsInvariant.InvariantError(4);
3145
3149
  }
3146
3150
  if (isNonNullObject(existing) &&
@@ -3369,7 +3373,7 @@ var StoreWriter = (function () {
3369
3373
  if (!field.selectionSet || value === null) {
3370
3374
  return __DEV__ ? cloneDeep(value) : value;
3371
3375
  }
3372
- if (Array.isArray(value)) {
3376
+ if (isArray(value)) {
3373
3377
  return value.map(function (item, i) {
3374
3378
  var value = _this.processFieldValue(item, field, context, getChildMergeTree(mergeTree, i));
3375
3379
  maybeRecycleChildMergeTree(mergeTree, i);
@@ -3434,7 +3438,7 @@ var StoreWriter = (function () {
3434
3438
  var _a;
3435
3439
  var _this = this;
3436
3440
  if (mergeTree.map.size && !isReference(incoming)) {
3437
- var e_1 = (!Array.isArray(incoming) &&
3441
+ var e_1 = (!isArray(incoming) &&
3438
3442
  (isReference(existing) || storeValueIsStoreObject(existing))) ? existing : void 0;
3439
3443
  var i_1 = incoming;
3440
3444
  if (e_1 && !getStorageArgs) {
@@ -3442,7 +3446,7 @@ var StoreWriter = (function () {
3442
3446
  }
3443
3447
  var changedFields_1;
3444
3448
  var getValue_1 = function (from, name) {
3445
- return Array.isArray(from)
3449
+ return isArray(from)
3446
3450
  ? (typeof name === "number" ? from[name] : void 0)
3447
3451
  : context.store.getFieldValue(from, String(name));
3448
3452
  };
@@ -3464,7 +3468,7 @@ var StoreWriter = (function () {
3464
3468
  }
3465
3469
  });
3466
3470
  if (changedFields_1) {
3467
- incoming = (Array.isArray(i_1) ? i_1.slice(0) : tslib.__assign({}, i_1));
3471
+ incoming = (isArray(i_1) ? i_1.slice(0) : tslib.__assign({}, i_1));
3468
3472
  changedFields_1.forEach(function (value, name) {
3469
3473
  incoming[name] = value;
3470
3474
  });
@@ -3532,7 +3536,7 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
3532
3536
  return;
3533
3537
  if (isReference(existing))
3534
3538
  return;
3535
- if (equality.equal(existing, incoming))
3539
+ if (equal.equal(existing, incoming))
3536
3540
  return;
3537
3541
  if (Object.keys(existing).every(function (key) { return store.getFieldValue(incoming, key) !== void 0; })) {
3538
3542
  return;
@@ -3545,8 +3549,8 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
3545
3549
  return;
3546
3550
  warnings.add(typeDotName);
3547
3551
  var childTypenames = [];
3548
- if (!Array.isArray(existing) &&
3549
- !Array.isArray(incoming)) {
3552
+ if (!isArray(existing) &&
3553
+ !isArray(incoming)) {
3550
3554
  [existing, incoming].forEach(function (child) {
3551
3555
  var typename = store.getFieldValue(child, "__typename");
3552
3556
  if (typeof typename === "string" &&
@@ -3846,7 +3850,7 @@ var InMemoryCache = (function (_super) {
3846
3850
  return;
3847
3851
  }
3848
3852
  }
3849
- if (!lastDiff || !equality.equal(lastDiff.result, diff.result)) {
3853
+ if (!lastDiff || !equal.equal(lastDiff.result, diff.result)) {
3850
3854
  c.callback(c.lastDiff = diff, lastDiff);
3851
3855
  }
3852
3856
  };
@@ -3904,7 +3908,7 @@ function isNetworkRequestInFlight(networkStatus) {
3904
3908
  return networkStatus ? networkStatus < 7 : false;
3905
3909
  }
3906
3910
 
3907
- var assign = Object.assign, hasOwnProperty$1 = Object.hasOwnProperty;
3911
+ var assign = Object.assign, hasOwnProperty$2 = Object.hasOwnProperty;
3908
3912
  var warnedAboutUpdateQuery = false;
3909
3913
  var ObservableQuery = (function (_super) {
3910
3914
  tslib.__extends(ObservableQuery, _super);
@@ -3991,7 +3995,7 @@ var ObservableQuery = (function (_super) {
3991
3995
  if (diff.complete || this.options.returnPartialData) {
3992
3996
  result.data = diff.result;
3993
3997
  }
3994
- if (equality.equal(result.data, {})) {
3998
+ if (equal.equal(result.data, {})) {
3995
3999
  result.data = void 0;
3996
4000
  }
3997
4001
  if (diff.complete) {
@@ -4022,13 +4026,13 @@ var ObservableQuery = (function (_super) {
4022
4026
  return result;
4023
4027
  };
4024
4028
  ObservableQuery.prototype.isDifferentFromLastResult = function (newResult) {
4025
- return !this.last || !equality.equal(this.last.result, newResult);
4029
+ return !this.last || !equal.equal(this.last.result, newResult);
4026
4030
  };
4027
4031
  ObservableQuery.prototype.getLast = function (key, variablesMustMatch) {
4028
4032
  var last = this.last;
4029
4033
  if (last &&
4030
4034
  last[key] &&
4031
- (!variablesMustMatch || equality.equal(last.variables, this.variables))) {
4035
+ (!variablesMustMatch || equal.equal(last.variables, this.variables))) {
4032
4036
  return last[key];
4033
4037
  }
4034
4038
  };
@@ -4060,14 +4064,14 @@ var ObservableQuery = (function (_super) {
4060
4064
  else {
4061
4065
  reobserveOptions.fetchPolicy = 'network-only';
4062
4066
  }
4063
- if (__DEV__ && variables && hasOwnProperty$1.call(variables, "variables")) {
4067
+ if (__DEV__ && variables && hasOwnProperty$2.call(variables, "variables")) {
4064
4068
  var queryDef = getQueryDefinition(this.options.query);
4065
4069
  var vars = queryDef.variableDefinitions;
4066
4070
  if (!vars || !vars.some(function (v) { return v.variable.name.value === "variables"; })) {
4067
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 })?"));
4068
4072
  }
4069
4073
  }
4070
- if (variables && !equality.equal(this.options.variables, variables)) {
4074
+ if (variables && !equal.equal(this.options.variables, variables)) {
4071
4075
  reobserveOptions.variables = this.options.variables = tslib.__assign(tslib.__assign({}, this.options.variables), variables);
4072
4076
  }
4073
4077
  this.queryInfo.resetLastWrite();
@@ -4148,7 +4152,7 @@ var ObservableQuery = (function (_super) {
4148
4152
  return this.reobserve(newOptions);
4149
4153
  };
4150
4154
  ObservableQuery.prototype.setVariables = function (variables) {
4151
- if (equality.equal(this.variables, variables)) {
4155
+ if (equal.equal(this.variables, variables)) {
4152
4156
  return this.observers.size
4153
4157
  ? this.result()
4154
4158
  : Promise.resolve();
@@ -4260,7 +4264,7 @@ var ObservableQuery = (function (_super) {
4260
4264
  if (newOptions &&
4261
4265
  newOptions.variables &&
4262
4266
  !newOptions.fetchPolicy &&
4263
- !equality.equal(newOptions.variables, oldVariables)) {
4267
+ !equal.equal(newOptions.variables, oldVariables)) {
4264
4268
  options.fetchPolicy = this.initialFetchPolicy;
4265
4269
  if (newNetworkStatus === void 0) {
4266
4270
  newNetworkStatus = exports.NetworkStatus.setVariables;
@@ -4642,10 +4646,10 @@ var QueryInfo = (function () {
4642
4646
  var networkStatus = query.networkStatus || exports.NetworkStatus.loading;
4643
4647
  if (this.variables &&
4644
4648
  this.networkStatus !== exports.NetworkStatus.loading &&
4645
- !equality.equal(this.variables, query.variables)) {
4649
+ !equal.equal(this.variables, query.variables)) {
4646
4650
  networkStatus = exports.NetworkStatus.setVariables;
4647
4651
  }
4648
- if (!equality.equal(query.variables, this.variables)) {
4652
+ if (!equal.equal(query.variables, this.variables)) {
4649
4653
  this.lastDiff = void 0;
4650
4654
  }
4651
4655
  Object.assign(this, {
@@ -4671,7 +4675,7 @@ var QueryInfo = (function () {
4671
4675
  QueryInfo.prototype.getDiff = function (variables) {
4672
4676
  if (variables === void 0) { variables = this.variables; }
4673
4677
  var options = this.getDiffOptions(variables);
4674
- if (this.lastDiff && equality.equal(options, this.lastDiff.options)) {
4678
+ if (this.lastDiff && equal.equal(options, this.lastDiff.options)) {
4675
4679
  return this.lastDiff.diff;
4676
4680
  }
4677
4681
  this.updateWatch(this.variables = variables);
@@ -4705,7 +4709,7 @@ var QueryInfo = (function () {
4705
4709
  var oldDiff = this.lastDiff && this.lastDiff.diff;
4706
4710
  this.updateLastDiff(diff);
4707
4711
  if (!this.dirty &&
4708
- !equality.equal(oldDiff && oldDiff.result, diff && diff.result)) {
4712
+ !equal.equal(oldDiff && oldDiff.result, diff && diff.result)) {
4709
4713
  this.dirty = true;
4710
4714
  if (!this.notifyTimeout) {
4711
4715
  this.notifyTimeout = setTimeout(function () { return _this.notify(); }, 0);
@@ -4779,7 +4783,7 @@ var QueryInfo = (function () {
4779
4783
  }
4780
4784
  var watchOptions = tslib.__assign(tslib.__assign({}, this.getDiffOptions(variables)), { watcher: this, callback: function (diff) { return _this.setDiff(diff); } });
4781
4785
  if (!this.lastWatch ||
4782
- !equality.equal(watchOptions, this.lastWatch)) {
4786
+ !equal.equal(watchOptions, this.lastWatch)) {
4783
4787
  this.cancel();
4784
4788
  this.cancel = this.cache.watch(this.lastWatch = watchOptions);
4785
4789
  }
@@ -4791,8 +4795,8 @@ var QueryInfo = (function () {
4791
4795
  var lastWrite = this.lastWrite;
4792
4796
  return !(lastWrite &&
4793
4797
  lastWrite.dmCount === destructiveMethodCounts.get(this.cache) &&
4794
- equality.equal(variables, lastWrite.variables) &&
4795
- equality.equal(result.data, lastWrite.result.data));
4798
+ equal.equal(variables, lastWrite.variables) &&
4799
+ equal.equal(result.data, lastWrite.result.data));
4796
4800
  };
4797
4801
  QueryInfo.prototype.markResult = function (result, options, cacheWriteBehavior) {
4798
4802
  var _this = this;
@@ -4869,10 +4873,10 @@ function shouldWriteResult(result, errorPolicy) {
4869
4873
  return writeWithErrors;
4870
4874
  }
4871
4875
 
4872
- var hasOwnProperty = Object.prototype.hasOwnProperty;
4876
+ var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
4873
4877
  var QueryManager = (function () {
4874
4878
  function QueryManager(_a) {
4875
- 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;
4879
+ 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;
4876
4880
  this.clientAwareness = {};
4877
4881
  this.queries = new Map();
4878
4882
  this.fetchCancelFns = new Map();
@@ -4883,6 +4887,7 @@ var QueryManager = (function () {
4883
4887
  this.inFlightLinkObservables = new Map();
4884
4888
  this.cache = cache;
4885
4889
  this.link = link;
4890
+ this.defaultOptions = defaultOptions || Object.create(null);
4886
4891
  this.queryDeduplication = queryDeduplication;
4887
4892
  this.clientAwareness = clientAwareness;
4888
4893
  this.localState = localState || new LocalState({ cache: cache });
@@ -4904,11 +4909,12 @@ var QueryManager = (function () {
4904
4909
  this.fetchCancelFns.clear();
4905
4910
  };
4906
4911
  QueryManager.prototype.mutate = function (_a) {
4907
- 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;
4912
+ var _b, _c;
4913
+ 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;
4908
4914
  return tslib.__awaiter(this, void 0, void 0, function () {
4909
4915
  var mutationId, mutationStoreValue, self;
4910
- return tslib.__generator(this, function (_f) {
4911
- switch (_f.label) {
4916
+ return tslib.__generator(this, function (_h) {
4917
+ switch (_h.label) {
4912
4918
  case 0:
4913
4919
  __DEV__ ? tsInvariant.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : tsInvariant.invariant(mutation, 12);
4914
4920
  __DEV__ ? tsInvariant.invariant(fetchPolicy === 'network-only' ||
@@ -4920,8 +4926,8 @@ var QueryManager = (function () {
4920
4926
  if (!this.transform(mutation).hasClientExports) return [3, 2];
4921
4927
  return [4, this.localState.addExportedVariables(mutation, variables, context)];
4922
4928
  case 1:
4923
- variables = (_f.sent());
4924
- _f.label = 2;
4929
+ variables = (_h.sent());
4930
+ _h.label = 2;
4925
4931
  case 2:
4926
4932
  mutationStoreValue = this.mutationStore &&
4927
4933
  (this.mutationStore[mutationId] = {
@@ -5022,7 +5028,7 @@ var QueryManager = (function () {
5022
5028
  this.queries.forEach(function (_a, queryId) {
5023
5029
  var observableQuery = _a.observableQuery;
5024
5030
  var queryName = observableQuery && observableQuery.queryName;
5025
- if (!queryName || !hasOwnProperty.call(updateQueries_1, queryName)) {
5031
+ if (!queryName || !hasOwnProperty$1.call(updateQueries_1, queryName)) {
5026
5032
  return;
5027
5033
  }
5028
5034
  var updater = updateQueries_1[queryName];
@@ -5481,7 +5487,8 @@ var QueryManager = (function () {
5481
5487
  var query = this.transform(options.query).document;
5482
5488
  var variables = this.getVariables(query, options.variables);
5483
5489
  var queryInfo = this.getQuery(queryId);
5484
- 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;
5490
+ var defaults = this.defaultOptions.watchQuery;
5491
+ 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;
5485
5492
  var normalized = Object.assign({}, options, {
5486
5493
  query: query,
5487
5494
  variables: variables,
@@ -5590,7 +5597,7 @@ var QueryManager = (function () {
5590
5597
  var data = diff.result;
5591
5598
  if (__DEV__ &&
5592
5599
  !returnPartialData &&
5593
- !equality.equal(data, {})) {
5600
+ !equal.equal(data, {})) {
5594
5601
  logMissingFieldErrors(diff.missing);
5595
5602
  }
5596
5603
  var fromData = function (data) { return zenObservableTs.Observable.of(tslib.__assign({ data: data, loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus }, (diff.complete ? null : { partial: true }))); };
@@ -5699,7 +5706,6 @@ function mergeOptions(defaults, options) {
5699
5706
  var ApolloClient = (function () {
5700
5707
  function ApolloClient(options) {
5701
5708
  var _this = this;
5702
- this.defaultOptions = {};
5703
5709
  this.resetStoreCallbacks = [];
5704
5710
  this.clearStoreCallbacks = [];
5705
5711
  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' &&
@@ -5720,7 +5726,7 @@ var ApolloClient = (function () {
5720
5726
  this.cache = cache;
5721
5727
  this.disableNetworkFetches = ssrMode || ssrForceFetchDelay > 0;
5722
5728
  this.queryDeduplication = queryDeduplication;
5723
- this.defaultOptions = defaultOptions || {};
5729
+ this.defaultOptions = defaultOptions || Object.create(null);
5724
5730
  this.typeDefs = typeDefs;
5725
5731
  if (ssrForceFetchDelay) {
5726
5732
  setTimeout(function () { return (_this.disableNetworkFetches = false); }, ssrForceFetchDelay);
@@ -5767,6 +5773,7 @@ var ApolloClient = (function () {
5767
5773
  this.queryManager = new QueryManager({
5768
5774
  cache: this.cache,
5769
5775
  link: this.link,
5776
+ defaultOptions: this.defaultOptions,
5770
5777
  queryDeduplication: queryDeduplication,
5771
5778
  ssrMode: ssrMode,
5772
5779
  clientAwareness: {
@@ -6053,227 +6060,274 @@ function verifyDocumentType(document, type) {
6053
6060
  "".concat(requiredOperationName, ", but a ").concat(usedOperationName, " was used instead.")) : tsInvariant.invariant(operation.type === type, 34);
6054
6061
  }
6055
6062
 
6056
- function useQuery(query, options) {
6057
- var _a;
6058
- var context = React.useContext(getApolloContext());
6059
- var client = useApolloClient(options === null || options === void 0 ? void 0 : options.client);
6060
- var defaultWatchQueryOptions = client.defaultOptions.watchQuery;
6061
- verifyDocumentType(query, exports.DocumentType.Query);
6062
- var _b = React.useState(function () {
6063
- var watchQueryOptions = createWatchQueryOptions(query, options, defaultWatchQueryOptions);
6064
- var obsQuery = null;
6065
- if (context.renderPromises) {
6066
- obsQuery = context.renderPromises.getSSRObservable(watchQueryOptions);
6067
- }
6068
- if (!obsQuery) {
6069
- obsQuery = client.watchQuery(watchQueryOptions);
6070
- if (context.renderPromises) {
6071
- context.renderPromises.registerSSRObservable(obsQuery, watchQueryOptions);
6072
- }
6073
- }
6074
- if (context.renderPromises &&
6075
- (options === null || options === void 0 ? void 0 : options.ssr) !== false &&
6076
- !(options === null || options === void 0 ? void 0 : options.skip) &&
6077
- obsQuery.getCurrentResult().loading) {
6078
- context.renderPromises.addQueryPromise({
6079
- getOptions: function () { return createWatchQueryOptions(query, options, defaultWatchQueryOptions); },
6080
- fetchData: function () { return new Promise(function (resolve) {
6081
- var sub = obsQuery.subscribe({
6082
- next: function (result) {
6083
- if (!result.loading) {
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
+
6080
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
6081
+ function useQuery(query, optionsOrFunction) {
6082
+ var options = useNormalizedOptions(optionsOrFunction);
6083
+ return useInternalState(useApolloClient(options.client), query).useQuery(options);
6084
+ }
6085
+ function useInternalState(client, query) {
6086
+ var stateRef = React.useRef();
6087
+ if (!stateRef.current ||
6088
+ client !== stateRef.current.client ||
6089
+ query !== stateRef.current.query) {
6090
+ stateRef.current = new InternalState(client, query);
6091
+ }
6092
+ var state = stateRef.current;
6093
+ var _a = React.useState(0); _a[0]; var setTick = _a[1];
6094
+ state.forceUpdate = function () {
6095
+ setTick(function (tick) { return tick + 1; });
6096
+ };
6097
+ return state;
6098
+ }
6099
+ var InternalState = (function () {
6100
+ function InternalState(client, query) {
6101
+ this.client = client;
6102
+ this.query = query;
6103
+ this.toQueryResultCache = new (canUseWeakMap ? WeakMap : Map)();
6104
+ verifyDocumentType(query, exports.DocumentType.Query);
6105
+ }
6106
+ InternalState.prototype.forceUpdate = function () {
6107
+ };
6108
+ InternalState.prototype.useQuery = function (options) {
6109
+ this.useOptions(options);
6110
+ var obsQuery = this.useObservableQuery();
6111
+ this.useSubscriptionEffect(obsQuery);
6112
+ var result = this.getCurrentResult();
6113
+ this.unsafeHandlePartialRefetch(result);
6114
+ return this.toQueryResult(result);
6115
+ };
6116
+ InternalState.prototype.useOptions = function (options) {
6117
+ this.renderPromises = React.useContext(getApolloContext()).renderPromises;
6118
+ var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
6119
+ if (!equal.equal(watchQueryOptions, this.watchQueryOptions)) {
6120
+ this.watchQueryOptions = watchQueryOptions;
6121
+ }
6122
+ this.ssrDisabled = !!(options && (options.ssr === false ||
6123
+ options.skip));
6124
+ this.onCompleted = options
6125
+ && options.onCompleted
6126
+ || InternalState.prototype.onCompleted;
6127
+ this.onError = options
6128
+ && options.onError
6129
+ || InternalState.prototype.onError;
6130
+ };
6131
+ InternalState.prototype.createWatchQueryOptions = function (_a) {
6132
+ var _b;
6133
+ if (_a === void 0) { _a = {}; }
6134
+ var skip = _a.skip; _a.ssr; _a.onCompleted; _a.onError; _a.displayName; var otherOptions = tslib.__rest(_a, ["skip", "ssr", "onCompleted", "onError", "displayName"]);
6135
+ var watchQueryOptions = Object.assign(otherOptions, { query: this.query });
6136
+ if (skip) {
6137
+ watchQueryOptions.fetchPolicy = 'standby';
6138
+ }
6139
+ else if (((_b = watchQueryOptions.context) === null || _b === void 0 ? void 0 : _b.renderPromises) &&
6140
+ (watchQueryOptions.fetchPolicy === 'network-only' ||
6141
+ watchQueryOptions.fetchPolicy === 'cache-and-network')) {
6142
+ watchQueryOptions.fetchPolicy = 'cache-first';
6143
+ }
6144
+ else if (!watchQueryOptions.fetchPolicy) {
6145
+ var defaultOptions = this.client.defaultOptions.watchQuery;
6146
+ watchQueryOptions.fetchPolicy =
6147
+ defaultOptions && defaultOptions.fetchPolicy || 'cache-first';
6148
+ }
6149
+ if (!watchQueryOptions.variables) {
6150
+ watchQueryOptions.variables = {};
6151
+ }
6152
+ return watchQueryOptions;
6153
+ };
6154
+ InternalState.prototype.onCompleted = function (data) { };
6155
+ InternalState.prototype.onError = function (error) { };
6156
+ InternalState.prototype.useObservableQuery = function () {
6157
+ var _this = this;
6158
+ var obsQuery = this.observable =
6159
+ this.renderPromises
6160
+ && this.renderPromises.getSSRObservable(this.watchQueryOptions)
6161
+ || this.observable
6162
+ || this.client.watchQuery(this.watchQueryOptions);
6163
+ this.obsQueryFields = React.useMemo(function () { return ({
6164
+ refetch: obsQuery.refetch.bind(obsQuery),
6165
+ fetchMore: obsQuery.fetchMore.bind(obsQuery),
6166
+ updateQuery: obsQuery.updateQuery.bind(obsQuery),
6167
+ startPolling: obsQuery.startPolling.bind(obsQuery),
6168
+ stopPolling: obsQuery.stopPolling.bind(obsQuery),
6169
+ subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
6170
+ }); }, [obsQuery]);
6171
+ if (this.renderPromises) {
6172
+ this.renderPromises.registerSSRObservable(obsQuery);
6173
+ if (!this.ssrDisabled && obsQuery.getCurrentResult().loading) {
6174
+ this.renderPromises.addQueryPromise({
6175
+ getOptions: function () { return obsQuery.options; },
6176
+ fetchData: function () { return new Promise(function (resolve) {
6177
+ var sub = obsQuery.subscribe({
6178
+ next: function (result) {
6179
+ if (!result.loading) {
6180
+ resolve();
6181
+ sub.unsubscribe();
6182
+ }
6183
+ },
6184
+ error: function () {
6084
6185
  resolve();
6085
6186
  sub.unsubscribe();
6086
- }
6087
- },
6088
- error: function () {
6089
- resolve();
6090
- sub.unsubscribe();
6091
- },
6092
- complete: function () {
6093
- resolve();
6094
- },
6095
- });
6096
- }); },
6097
- }, function () { return null; });
6187
+ },
6188
+ complete: function () {
6189
+ resolve();
6190
+ },
6191
+ });
6192
+ }); },
6193
+ }, function () { return null; });
6194
+ obsQuery.setOptions(this.watchQueryOptions).catch(function () { });
6195
+ }
6098
6196
  }
6197
+ var prevOptionsRef = React.useRef({
6198
+ watchQueryOptions: this.watchQueryOptions,
6199
+ });
6200
+ React.useEffect(function () {
6201
+ if (_this.renderPromises) ;
6202
+ else if (_this.watchQueryOptions !== prevOptionsRef.current.watchQueryOptions) {
6203
+ obsQuery.setOptions(_this.watchQueryOptions).catch(function () { });
6204
+ prevOptionsRef.current.watchQueryOptions = _this.watchQueryOptions;
6205
+ _this.setResult(obsQuery.getCurrentResult());
6206
+ }
6207
+ }, [obsQuery, this.watchQueryOptions]);
6099
6208
  return obsQuery;
6100
- }), obsQuery = _b[0], setObsQuery = _b[1];
6101
- var _c = React.useState(function () {
6102
- var _a, _b;
6103
- var result = obsQuery.getCurrentResult();
6104
- if (!result.loading && options) {
6209
+ };
6210
+ InternalState.prototype.useSubscriptionEffect = function (obsQuery) {
6211
+ var _this = this;
6212
+ React.useEffect(function () {
6213
+ if (_this.renderPromises) {
6214
+ return;
6215
+ }
6216
+ var onNext = function () {
6217
+ var previousResult = _this.result;
6218
+ var result = obsQuery.getCurrentResult();
6219
+ if (previousResult &&
6220
+ previousResult.loading === result.loading &&
6221
+ previousResult.networkStatus === result.networkStatus &&
6222
+ equal.equal(previousResult.data, result.data)) {
6223
+ return;
6224
+ }
6225
+ _this.setResult(result);
6226
+ };
6227
+ var onError = function (error) {
6228
+ var last = obsQuery["last"];
6229
+ subscription.unsubscribe();
6230
+ try {
6231
+ obsQuery.resetLastResults();
6232
+ subscription = obsQuery.subscribe(onNext, onError);
6233
+ }
6234
+ finally {
6235
+ obsQuery["last"] = last;
6236
+ }
6237
+ if (!hasOwnProperty.call(error, 'graphQLErrors')) {
6238
+ throw error;
6239
+ }
6240
+ var previousResult = _this.result;
6241
+ if (!previousResult ||
6242
+ (previousResult && previousResult.loading) ||
6243
+ !equal.equal(error, previousResult.error)) {
6244
+ _this.setResult({
6245
+ data: (previousResult && previousResult.data),
6246
+ error: error,
6247
+ loading: false,
6248
+ networkStatus: exports.NetworkStatus.error,
6249
+ });
6250
+ }
6251
+ };
6252
+ var subscription = obsQuery.subscribe(onNext, onError);
6253
+ return function () { return subscription.unsubscribe(); };
6254
+ }, [
6255
+ obsQuery,
6256
+ this.renderPromises,
6257
+ this.client.disableNetworkFetches,
6258
+ ]);
6259
+ };
6260
+ InternalState.prototype.setResult = function (nextResult) {
6261
+ var previousResult = this.result;
6262
+ if (previousResult && previousResult.data) {
6263
+ this.previousData = previousResult.data;
6264
+ }
6265
+ this.result = nextResult;
6266
+ this.forceUpdate();
6267
+ this.handleErrorOrCompleted(nextResult);
6268
+ };
6269
+ InternalState.prototype.handleErrorOrCompleted = function (result) {
6270
+ if (!result.loading) {
6105
6271
  if (result.error) {
6106
- (_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, result.error);
6272
+ this.onError(result.error);
6107
6273
  }
6108
6274
  else if (result.data) {
6109
- (_b = options.onCompleted) === null || _b === void 0 ? void 0 : _b.call(options, result.data);
6275
+ this.onCompleted(result.data);
6110
6276
  }
6111
6277
  }
6112
- return result;
6113
- }), result = _c[0], setResult = _c[1];
6114
- var ref = React.useRef({
6115
- client: client,
6116
- query: query,
6117
- options: options,
6118
- result: result,
6119
- previousData: void 0,
6120
- watchQueryOptions: createWatchQueryOptions(query, options, defaultWatchQueryOptions),
6121
- });
6122
- React.useEffect(function () {
6123
- var _a, _b;
6124
- var watchQueryOptions = createWatchQueryOptions(query, options, defaultWatchQueryOptions);
6125
- var nextResult;
6126
- if (ref.current.client !== client || !equality.equal(ref.current.query, query)) {
6127
- var obsQuery_1 = client.watchQuery(watchQueryOptions);
6128
- setObsQuery(obsQuery_1);
6129
- nextResult = obsQuery_1.getCurrentResult();
6130
- }
6131
- else if (!equality.equal(ref.current.watchQueryOptions, watchQueryOptions)) {
6132
- obsQuery.setOptions(watchQueryOptions).catch(function () { });
6133
- nextResult = obsQuery.getCurrentResult();
6134
- ref.current.watchQueryOptions = watchQueryOptions;
6135
- }
6136
- if (nextResult) {
6137
- var previousResult = ref.current.result;
6138
- if (previousResult.data) {
6139
- ref.current.previousData = previousResult.data;
6140
- }
6141
- setResult(ref.current.result = nextResult);
6142
- if (!nextResult.loading && options) {
6143
- if (nextResult.error) {
6144
- (_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, nextResult.error);
6145
- }
6146
- else if (nextResult.data) {
6147
- (_b = options.onCompleted) === null || _b === void 0 ? void 0 : _b.call(options, nextResult.data);
6148
- }
6149
- }
6278
+ };
6279
+ InternalState.prototype.getCurrentResult = function () {
6280
+ var result = this.result;
6281
+ if (!result) {
6282
+ result = this.result = this.observable.getCurrentResult();
6283
+ this.handleErrorOrCompleted(result);
6150
6284
  }
6151
- Object.assign(ref.current, { client: client, query: query });
6152
- }, [obsQuery, client, query, options]);
6153
- React.useEffect(function () {
6154
- if (context.renderPromises) {
6155
- return;
6285
+ if ((this.renderPromises || this.client.disableNetworkFetches) &&
6286
+ this.queryHookOptions.ssr === false) {
6287
+ result = {
6288
+ loading: true,
6289
+ data: void 0,
6290
+ error: void 0,
6291
+ networkStatus: exports.NetworkStatus.loading,
6292
+ };
6156
6293
  }
6157
- var subscription = obsQuery.subscribe(onNext, onError);
6158
- function onNext() {
6159
- var _a, _b;
6160
- var previousResult = ref.current.result;
6161
- var result = obsQuery.getCurrentResult();
6162
- if (previousResult &&
6163
- previousResult.loading === result.loading &&
6164
- previousResult.networkStatus === result.networkStatus &&
6165
- equality.equal(previousResult.data, result.data)) {
6166
- return;
6167
- }
6168
- if (previousResult.data) {
6169
- ref.current.previousData = previousResult.data;
6170
- }
6171
- setResult(ref.current.result = result);
6172
- if (!result.loading) {
6173
- (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onCompleted) === null || _b === void 0 ? void 0 : _b.call(_a, result.data);
6174
- }
6294
+ else if (this.queryHookOptions.skip ||
6295
+ this.queryHookOptions.fetchPolicy === 'standby') {
6296
+ result = {
6297
+ loading: false,
6298
+ data: void 0,
6299
+ error: void 0,
6300
+ networkStatus: exports.NetworkStatus.ready,
6301
+ };
6175
6302
  }
6176
- function onError(error) {
6177
- var _a, _b;
6178
- var last = obsQuery["last"];
6179
- subscription.unsubscribe();
6180
- try {
6181
- obsQuery.resetLastResults();
6182
- subscription = obsQuery.subscribe(onNext, onError);
6183
- }
6184
- finally {
6185
- obsQuery["last"] = last;
6186
- }
6187
- if (!error.hasOwnProperty('graphQLErrors')) {
6188
- throw error;
6189
- }
6190
- var previousResult = ref.current.result;
6191
- if ((previousResult && previousResult.loading) ||
6192
- !equality.equal(error, previousResult.error)) {
6193
- setResult(ref.current.result = {
6194
- data: previousResult.data,
6195
- error: error,
6196
- loading: false,
6197
- networkStatus: exports.NetworkStatus.error,
6198
- });
6199
- (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
6200
- }
6303
+ return result;
6304
+ };
6305
+ InternalState.prototype.toQueryResult = function (result) {
6306
+ var queryResult = this.toQueryResultCache.get(result);
6307
+ if (queryResult)
6308
+ return queryResult;
6309
+ var data = result.data; result.partial; var resultWithoutPartial = tslib.__rest(result, ["data", "partial"]);
6310
+ 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 }));
6311
+ if (!queryResult.error && isNonEmptyArray(result.errors)) {
6312
+ queryResult.error = new ApolloError({ graphQLErrors: result.errors });
6201
6313
  }
6202
- return function () { return subscription.unsubscribe(); };
6203
- }, [obsQuery, context.renderPromises, client.disableNetworkFetches]);
6204
- var partial;
6205
- (_a = result, partial = _a.partial, result = tslib.__rest(_a, ["partial"]));
6206
- {
6207
- if (partial &&
6208
- (options === null || options === void 0 ? void 0 : options.partialRefetch) &&
6314
+ return queryResult;
6315
+ };
6316
+ InternalState.prototype.unsafeHandlePartialRefetch = function (result) {
6317
+ if (result.partial &&
6318
+ this.queryHookOptions.partialRefetch &&
6209
6319
  !result.loading &&
6210
6320
  (!result.data || Object.keys(result.data).length === 0) &&
6211
- obsQuery.options.fetchPolicy !== 'cache-only') {
6212
- result = tslib.__assign(tslib.__assign({}, result), { loading: true, networkStatus: exports.NetworkStatus.refetch });
6213
- obsQuery.refetch();
6214
- }
6215
- if (context.renderPromises &&
6216
- (options === null || options === void 0 ? void 0 : options.ssr) !== false &&
6217
- !(options === null || options === void 0 ? void 0 : options.skip) &&
6218
- result.loading) {
6219
- obsQuery.setOptions(createWatchQueryOptions(query, options, defaultWatchQueryOptions)).catch(function () { });
6321
+ this.observable.options.fetchPolicy !== 'cache-only') {
6322
+ Object.assign(result, {
6323
+ loading: true,
6324
+ networkStatus: exports.NetworkStatus.refetch,
6325
+ });
6326
+ this.observable.refetch();
6220
6327
  }
6221
- Object.assign(ref.current, { options: options });
6222
- }
6223
- if ((context.renderPromises || client.disableNetworkFetches) &&
6224
- (options === null || options === void 0 ? void 0 : options.ssr) === false) {
6225
- result = ref.current.result = {
6226
- loading: true,
6227
- data: void 0,
6228
- error: void 0,
6229
- networkStatus: exports.NetworkStatus.loading,
6230
- };
6231
- }
6232
- else if ((options === null || options === void 0 ? void 0 : options.skip) || (options === null || options === void 0 ? void 0 : options.fetchPolicy) === 'standby') {
6233
- result = {
6234
- loading: false,
6235
- data: void 0,
6236
- error: void 0,
6237
- networkStatus: exports.NetworkStatus.ready,
6238
- };
6239
- }
6240
- if (result.errors && result.errors.length) {
6241
- result = tslib.__assign(tslib.__assign({}, result), { error: result.error || new ApolloError({ graphQLErrors: result.errors }) });
6242
- }
6243
- var obsQueryFields = React.useMemo(function () { return ({
6244
- refetch: obsQuery.refetch.bind(obsQuery),
6245
- fetchMore: obsQuery.fetchMore.bind(obsQuery),
6246
- updateQuery: obsQuery.updateQuery.bind(obsQuery),
6247
- startPolling: obsQuery.startPolling.bind(obsQuery),
6248
- stopPolling: obsQuery.stopPolling.bind(obsQuery),
6249
- subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
6250
- }); }, [obsQuery]);
6251
- return tslib.__assign(tslib.__assign(tslib.__assign({}, obsQueryFields), { variables: createWatchQueryOptions(query, options, defaultWatchQueryOptions).variables, client: client, called: true, previousData: ref.current.previousData }), result);
6252
- }
6253
- function createWatchQueryOptions(query, options, defaultOptions) {
6254
- var _a;
6255
- if (options === void 0) { options = {}; }
6256
- var skip = options.skip; options.ssr; options.onCompleted; options.onError; options.displayName; var otherOptions = tslib.__rest(options, ["skip", "ssr", "onCompleted", "onError", "displayName"]);
6257
- var watchQueryOptions = tslib.__assign({ query: query }, otherOptions);
6258
- if (defaultOptions) {
6259
- watchQueryOptions = mergeOptions(defaultOptions, watchQueryOptions);
6260
- }
6261
- if (skip) {
6262
- watchQueryOptions.fetchPolicy = 'standby';
6263
- }
6264
- else if (((_a = watchQueryOptions.context) === null || _a === void 0 ? void 0 : _a.renderPromises) &&
6265
- (watchQueryOptions.fetchPolicy === 'network-only' ||
6266
- watchQueryOptions.fetchPolicy === 'cache-and-network')) {
6267
- watchQueryOptions.fetchPolicy = 'cache-first';
6268
- }
6269
- else if (!watchQueryOptions.fetchPolicy) {
6270
- watchQueryOptions.fetchPolicy = 'cache-first';
6271
- }
6272
- if (!watchQueryOptions.variables) {
6273
- watchQueryOptions.variables = {};
6274
- }
6275
- return watchQueryOptions;
6276
- }
6328
+ };
6329
+ return InternalState;
6330
+ }());
6277
6331
 
6278
6332
  var EAGER_METHODS = [
6279
6333
  'refetch',
@@ -6282,7 +6336,8 @@ var EAGER_METHODS = [
6282
6336
  'startPolling',
6283
6337
  'subscribeToMore',
6284
6338
  ];
6285
- function useLazyQuery(query, options) {
6339
+ function useLazyQuery(query, optionsOrFunction) {
6340
+ var options = useNormalizedOptions(optionsOrFunction);
6286
6341
  var _a = React.useState({
6287
6342
  called: false,
6288
6343
  }), execution = _a[0], setExecution = _a[1];
@@ -6373,7 +6428,7 @@ function useMutation(mutation, options) {
6373
6428
  error: error,
6374
6429
  client: client,
6375
6430
  };
6376
- if (ref.current.isMounted && !equality.equal(ref.current.result, result_1)) {
6431
+ if (ref.current.isMounted && !equal.equal(ref.current.result, result_1)) {
6377
6432
  setResult(ref.current.result = result_1);
6378
6433
  }
6379
6434
  }
@@ -6391,7 +6446,7 @@ function useMutation(mutation, options) {
6391
6446
  called: true,
6392
6447
  client: client,
6393
6448
  };
6394
- if (!equality.equal(ref.current.result, result_2)) {
6449
+ if (!equal.equal(ref.current.result, result_2)) {
6395
6450
  setResult(ref.current.result = result_2);
6396
6451
  }
6397
6452
  }
@@ -6454,7 +6509,7 @@ function useSubscription(subscription, options) {
6454
6509
  subscription !== ref.current.subscription ||
6455
6510
  (options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
6456
6511
  !(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
6457
- !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))) {
6458
6513
  setResult({
6459
6514
  loading: true,
6460
6515
  data: void 0,