@apollo/client 3.5.10 → 3.6.5

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 (152) hide show
  1. package/LICENSE +1 -1
  2. package/apollo-client.cjs +541 -369
  3. package/apollo-client.cjs.map +1 -1
  4. package/apollo-client.min.cjs +1 -1
  5. package/cache/cache.cjs +9 -10
  6. package/cache/cache.cjs.map +1 -1
  7. package/cache/cache.cjs.native.js +2288 -0
  8. package/cache/inmemory/readFromStore.d.ts.map +1 -1
  9. package/cache/inmemory/readFromStore.js +10 -11
  10. package/cache/inmemory/readFromStore.js.map +1 -1
  11. package/core/ApolloClient.d.ts +2 -3
  12. package/core/ApolloClient.d.ts.map +1 -1
  13. package/core/ApolloClient.js +4 -8
  14. package/core/ApolloClient.js.map +1 -1
  15. package/core/ObservableQuery.d.ts +10 -4
  16. package/core/ObservableQuery.d.ts.map +1 -1
  17. package/core/ObservableQuery.js +97 -45
  18. package/core/ObservableQuery.js.map +1 -1
  19. package/core/QueryInfo.d.ts.map +1 -1
  20. package/core/QueryInfo.js +4 -2
  21. package/core/QueryInfo.js.map +1 -1
  22. package/core/QueryManager.d.ts +5 -2
  23. package/core/QueryManager.d.ts.map +1 -1
  24. package/core/QueryManager.js +29 -23
  25. package/core/QueryManager.js.map +1 -1
  26. package/core/core.cjs +138 -85
  27. package/core/core.cjs.map +1 -1
  28. package/core/core.cjs.native.js +2141 -0
  29. package/core/index.d.ts +1 -1
  30. package/core/index.d.ts.map +1 -1
  31. package/core/index.js +1 -1
  32. package/core/index.js.map +1 -1
  33. package/core/watchQueryOptions.d.ts +9 -1
  34. package/core/watchQueryOptions.d.ts.map +1 -1
  35. package/core/watchQueryOptions.js.map +1 -1
  36. package/errors/errors.cjs.native.js +48 -0
  37. package/invariantErrorCodes.js +1 -1
  38. package/link/batch/batch.cjs +47 -37
  39. package/link/batch/batch.cjs.map +1 -1
  40. package/link/batch/batch.cjs.native.js +161 -0
  41. package/link/batch/batching.d.ts +2 -6
  42. package/link/batch/batching.d.ts.map +1 -1
  43. package/link/batch/batching.js +47 -37
  44. package/link/batch/batching.js.map +1 -1
  45. package/link/batch-http/batch-http.cjs.native.js +127 -0
  46. package/link/context/context.cjs.native.js +38 -0
  47. package/link/core/core.cjs.native.js +121 -0
  48. package/link/error/error.cjs.native.js +90 -0
  49. package/link/http/http.cjs.native.js +320 -0
  50. package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
  51. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  52. package/link/persisted-queries/index.d.ts +2 -1
  53. package/link/persisted-queries/index.d.ts.map +1 -1
  54. package/link/persisted-queries/index.js +26 -13
  55. package/link/persisted-queries/index.js.map +1 -1
  56. package/link/persisted-queries/persisted-queries.cjs +25 -12
  57. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  58. package/link/persisted-queries/persisted-queries.cjs.native.js +174 -0
  59. package/link/retry/retry.cjs.native.js +170 -0
  60. package/link/schema/schema.cjs.native.js +56 -0
  61. package/link/subscriptions/subscriptions.cjs.native.js +45 -0
  62. package/link/utils/utils.cjs.native.js +115 -0
  63. package/link/ws/ws.cjs.native.js +28 -0
  64. package/main.cjs.native.js +16 -0
  65. package/package.json +28 -26
  66. package/react/components/components.cjs.native.js +79 -0
  67. package/react/context/ApolloConsumer.js +2 -2
  68. package/react/context/ApolloProvider.js +2 -2
  69. package/react/context/context.cjs +4 -4
  70. package/react/context/context.cjs.map +1 -1
  71. package/react/context/context.cjs.native.js +67 -0
  72. package/react/hoc/hoc.cjs.native.js +325 -0
  73. package/react/hooks/hooks.cjs +365 -253
  74. package/react/hooks/hooks.cjs.map +1 -1
  75. package/react/hooks/hooks.cjs.native.js +612 -0
  76. package/react/hooks/index.d.ts +1 -1
  77. package/react/hooks/index.d.ts.map +1 -1
  78. package/react/hooks/index.js +1 -1
  79. package/react/hooks/index.js.map +1 -1
  80. package/react/hooks/useLazyQuery.d.ts +2 -2
  81. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  82. package/react/hooks/useLazyQuery.js +26 -21
  83. package/react/hooks/useLazyQuery.js.map +1 -1
  84. package/react/hooks/useMutation.d.ts.map +1 -1
  85. package/react/hooks/useMutation.js +13 -10
  86. package/react/hooks/useMutation.js.map +1 -1
  87. package/react/hooks/useQuery.d.ts +36 -2
  88. package/react/hooks/useQuery.d.ts.map +1 -1
  89. package/react/hooks/useQuery.js +245 -206
  90. package/react/hooks/useQuery.js.map +1 -1
  91. package/react/hooks/useSubscription.d.ts.map +1 -1
  92. package/react/hooks/useSubscription.js +17 -7
  93. package/react/hooks/useSubscription.js.map +1 -1
  94. package/react/hooks/useSyncExternalStore.d.ts +4 -0
  95. package/react/hooks/useSyncExternalStore.d.ts.map +1 -0
  96. package/react/hooks/useSyncExternalStore.js +48 -0
  97. package/react/hooks/useSyncExternalStore.js.map +1 -0
  98. package/react/parser/index.d.ts.map +1 -1
  99. package/react/parser/index.js +24 -10
  100. package/react/parser/index.js.map +1 -1
  101. package/react/parser/parser.cjs +24 -10
  102. package/react/parser/parser.cjs.map +1 -1
  103. package/react/parser/parser.cjs.native.js +103 -0
  104. package/react/react.cjs.native.js +22 -0
  105. package/react/ssr/RenderPromises.d.ts +3 -2
  106. package/react/ssr/RenderPromises.d.ts.map +1 -1
  107. package/react/ssr/RenderPromises.js +25 -3
  108. package/react/ssr/RenderPromises.js.map +1 -1
  109. package/react/ssr/ssr.cjs +25 -3
  110. package/react/ssr/ssr.cjs.map +1 -1
  111. package/react/ssr/ssr.cjs.native.js +150 -0
  112. package/react/types/types.d.ts +10 -11
  113. package/react/types/types.d.ts.map +1 -1
  114. package/react/types/types.js.map +1 -1
  115. package/testing/core/core.cjs.native.js +288 -0
  116. package/testing/core/mocking/mockFetch.js +1 -1
  117. package/testing/core/mocking/mockFetch.js.map +1 -1
  118. package/testing/core/mocking/mockQueryManager.js +1 -1
  119. package/testing/core/mocking/mockWatchQuery.js +1 -1
  120. package/testing/core/wrap.js +1 -1
  121. package/testing/testing.cjs.native.js +58 -0
  122. package/utilities/common/canUse.d.ts +2 -0
  123. package/utilities/common/canUse.d.ts.map +1 -1
  124. package/utilities/common/canUse.js +6 -2
  125. package/utilities/common/canUse.js.map +1 -1
  126. package/utilities/common/mergeDeep.d.ts.map +1 -1
  127. package/utilities/common/mergeDeep.js +8 -11
  128. package/utilities/common/mergeDeep.js.map +1 -1
  129. package/utilities/common/mergeOptions.d.ts +5 -0
  130. package/utilities/common/mergeOptions.d.ts.map +1 -0
  131. package/utilities/common/mergeOptions.js +8 -0
  132. package/utilities/common/mergeOptions.js.map +1 -0
  133. package/utilities/globals/global.js +1 -2
  134. package/utilities/globals/globals.cjs.native.js +56 -0
  135. package/utilities/graphql/transform.d.ts +2 -2
  136. package/utilities/graphql/transform.d.ts.map +1 -1
  137. package/utilities/graphql/transform.js +1 -1
  138. package/utilities/graphql/transform.js.map +1 -1
  139. package/utilities/index.d.ts +1 -0
  140. package/utilities/index.d.ts.map +1 -1
  141. package/utilities/index.js +1 -0
  142. package/utilities/index.js.map +1 -1
  143. package/utilities/observables/Concast.d.ts.map +1 -1
  144. package/utilities/observables/Concast.js +5 -2
  145. package/utilities/observables/Concast.js.map +1 -1
  146. package/utilities/policies/pagination.d.ts.map +1 -1
  147. package/utilities/policies/pagination.js +9 -7
  148. package/utilities/policies/pagination.js.map +1 -1
  149. package/utilities/utilities.cjs +37 -23
  150. package/utilities/utilities.cjs.map +1 -1
  151. package/utilities/utilities.cjs.native.js +1281 -0
  152. package/version.js +1 -1
package/apollo-client.cjs CHANGED
@@ -539,7 +539,7 @@ function removeDirectivesFromDocument(directives, doc) {
539
539
  return modifiedDoc;
540
540
  }
541
541
  var addTypenameToDocument = Object.assign(function (doc) {
542
- return graphql.visit(checkDocument(doc), {
542
+ return graphql.visit(doc, {
543
543
  SelectionSet: {
544
544
  enter: function (node, _key, parent) {
545
545
  if (parent &&
@@ -703,7 +703,7 @@ function removeClientSetsFromDocument(document) {
703
703
  return modifiedDoc;
704
704
  }
705
705
 
706
- var hasOwnProperty$3 = Object.prototype.hasOwnProperty;
706
+ var hasOwnProperty$4 = Object.prototype.hasOwnProperty;
707
707
  function mergeDeep() {
708
708
  var sources = [];
709
709
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -740,7 +740,7 @@ var DeepMerger = (function () {
740
740
  }
741
741
  if (isNonNullObject(source) && isNonNullObject(target)) {
742
742
  Object.keys(source).forEach(function (sourceKey) {
743
- if (hasOwnProperty$3.call(target, sourceKey)) {
743
+ if (hasOwnProperty$4.call(target, sourceKey)) {
744
744
  var targetValue = target[sourceKey];
745
745
  if (source[sourceKey] !== targetValue) {
746
746
  var result = _this.reconciler.apply(_this, tslib.__spreadArray([target, source, sourceKey], context, false));
@@ -761,18 +761,15 @@ var DeepMerger = (function () {
761
761
  };
762
762
  DeepMerger.prototype.shallowCopyForMerge = function (value) {
763
763
  if (isNonNullObject(value)) {
764
- if (this.pastCopies.has(value)) {
765
- if (!Object.isFrozen(value))
766
- return value;
767
- this.pastCopies.delete(value);
768
- }
769
- if (Array.isArray(value)) {
770
- value = value.slice(0);
771
- }
772
- else {
773
- value = tslib.__assign({ __proto__: Object.getPrototypeOf(value) }, value);
764
+ if (!this.pastCopies.has(value)) {
765
+ if (Array.isArray(value)) {
766
+ value = value.slice(0);
767
+ }
768
+ else {
769
+ value = tslib.__assign({ __proto__: Object.getPrototypeOf(value) }, value);
770
+ }
771
+ this.pastCopies.add(value);
774
772
  }
775
- this.pastCopies.add(value);
776
773
  }
777
774
  return value;
778
775
  };
@@ -898,11 +895,14 @@ function asyncMap(observable, mapFn, catchFn) {
898
895
  });
899
896
  }
900
897
 
901
- var canUseWeakMap = typeof WeakMap === 'function' && !(typeof navigator === 'object' &&
902
- navigator.product === 'ReactNative');
898
+ var canUseWeakMap = typeof WeakMap === 'function' &&
899
+ maybe(function () { return navigator.product; }) !== 'ReactNative';
903
900
  var canUseWeakSet = typeof WeakSet === 'function';
904
901
  var canUseSymbol = typeof Symbol === 'function' &&
905
902
  typeof Symbol.for === 'function';
903
+ var canUseDOM = typeof maybe(function () { return window.document.createElement; }) === "function";
904
+ var usingJSDOM = maybe(function () { return navigator.userAgent.indexOf("jsdom") >= 0; }) || false;
905
+ var canUseLayoutEffect = canUseDOM && !usingJSDOM;
906
906
 
907
907
  function fixObservableSubclass(subclass) {
908
908
  function set(key) {
@@ -950,9 +950,12 @@ var Concast = (function (_super) {
950
950
  }
951
951
  },
952
952
  complete: function () {
953
- if (_this.sub !== null) {
953
+ var sub = _this.sub;
954
+ if (sub !== null) {
954
955
  var value = _this.sources.shift();
955
956
  if (!value) {
957
+ if (sub)
958
+ setTimeout(function () { return sub.unsubscribe(); });
956
959
  _this.sub = null;
957
960
  if (_this.latest &&
958
961
  _this.latest[0] === "next") {
@@ -1020,7 +1023,7 @@ var Concast = (function (_super) {
1020
1023
  if (this.observers.delete(observer) &&
1021
1024
  --this.addCount < 1 &&
1022
1025
  !quietly) {
1023
- this.handlers.error(new Error("Observable cancelled prematurely"));
1026
+ this.handlers.complete();
1024
1027
  }
1025
1028
  };
1026
1029
  Concast.prototype.cleanup = function (callback) {
@@ -1087,6 +1090,12 @@ function stringifyForDisplay(value) {
1087
1090
  }).split(JSON.stringify(undefId)).join("<undefined>");
1088
1091
  }
1089
1092
 
1093
+ function mergeOptions(defaults, options) {
1094
+ return compact(defaults, options, options.variables && {
1095
+ variables: tslib.__assign(tslib.__assign({}, (defaults && defaults.variables)), options.variables),
1096
+ });
1097
+ }
1098
+
1090
1099
  function fromError(errorValue) {
1091
1100
  return new zenObservableTs.Observable(function (observer) {
1092
1101
  observer.error(errorValue);
@@ -1291,9 +1300,9 @@ var concat = ApolloLink.concat;
1291
1300
 
1292
1301
  var execute = ApolloLink.execute;
1293
1302
 
1294
- var version = '3.5.10';
1303
+ var version = '3.6.5';
1295
1304
 
1296
- var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
1305
+ var hasOwnProperty$3 = Object.prototype.hasOwnProperty;
1297
1306
  function parseAndCheckHttpResponse(operations) {
1298
1307
  return function (response) { return response
1299
1308
  .text()
@@ -1315,8 +1324,8 @@ function parseAndCheckHttpResponse(operations) {
1315
1324
  throwServerError(response, result, "Response not successful: Received status code ".concat(response.status));
1316
1325
  }
1317
1326
  if (!Array.isArray(result) &&
1318
- !hasOwnProperty$2.call(result, 'data') &&
1319
- !hasOwnProperty$2.call(result, 'errors')) {
1327
+ !hasOwnProperty$3.call(result, 'data') &&
1328
+ !hasOwnProperty$3.call(result, 'errors')) {
1320
1329
  throwServerError(response, result, "Server response was missing for query '".concat(Array.isArray(operations)
1321
1330
  ? operations.map(function (op) { return op.operationName; })
1322
1331
  : operations.operationName, "'."));
@@ -2384,7 +2393,6 @@ var StoreReader = (function () {
2384
2393
  var policies = this.config.cache.policies;
2385
2394
  variables = tslib.__assign(tslib.__assign({}, getDefaultValues(getQueryDefinition(query))), variables);
2386
2395
  var rootRef = makeReference(rootId);
2387
- var merger = new DeepMerger;
2388
2396
  var execResult = this.executeSelectionSet({
2389
2397
  selectionSet: getMainDefinition(query).selectionSet,
2390
2398
  objectOrReference: rootRef,
@@ -2397,9 +2405,6 @@ var StoreReader = (function () {
2397
2405
  varString: canonicalStringify(variables),
2398
2406
  canonizeResults: canonizeResults,
2399
2407
  fragmentMap: createFragmentMap(getFragmentDefinitions(query)),
2400
- merge: function (a, b) {
2401
- return merger.merge(a, b);
2402
- },
2403
2408
  },
2404
2409
  });
2405
2410
  var missing;
@@ -2438,17 +2443,18 @@ var StoreReader = (function () {
2438
2443
  }
2439
2444
  var variables = context.variables, policies = context.policies, store = context.store;
2440
2445
  var typename = store.getFieldValue(objectOrReference, "__typename");
2441
- var result = {};
2446
+ var objectsToMerge = [];
2442
2447
  var missing;
2448
+ var missingMerger = new DeepMerger();
2443
2449
  if (this.config.addTypename &&
2444
2450
  typeof typename === "string" &&
2445
2451
  !policies.rootIdsByTypename[typename]) {
2446
- result = { __typename: typename };
2452
+ objectsToMerge.push({ __typename: typename });
2447
2453
  }
2448
2454
  function handleMissing(result, resultName) {
2449
2455
  var _a;
2450
2456
  if (result.missing) {
2451
- missing = context.merge(missing, (_a = {}, _a[resultName] = result.missing, _a));
2457
+ missing = missingMerger.merge(missing, (_a = {}, _a[resultName] = result.missing, _a));
2452
2458
  }
2453
2459
  return result.result;
2454
2460
  }
@@ -2467,7 +2473,7 @@ var StoreReader = (function () {
2467
2473
  var resultName = resultKeyNameFromField(selection);
2468
2474
  if (fieldValue === void 0) {
2469
2475
  if (!addTypenameToDocument.added(selection)) {
2470
- missing = context.merge(missing, (_a = {},
2476
+ missing = missingMerger.merge(missing, (_a = {},
2471
2477
  _a[resultName] = "Can't find field '".concat(selection.name.value, "' on ").concat(isReference(objectOrReference)
2472
2478
  ? objectOrReference.__ref + " object"
2473
2479
  : "object " + JSON.stringify(objectOrReference, null, 2)),
@@ -2496,7 +2502,7 @@ var StoreReader = (function () {
2496
2502
  }), resultName);
2497
2503
  }
2498
2504
  if (fieldValue !== void 0) {
2499
- result = context.merge(result, (_b = {}, _b[resultName] = fieldValue, _b));
2505
+ objectsToMerge.push((_b = {}, _b[resultName] = fieldValue, _b));
2500
2506
  }
2501
2507
  }
2502
2508
  else {
@@ -2506,6 +2512,7 @@ var StoreReader = (function () {
2506
2512
  }
2507
2513
  }
2508
2514
  });
2515
+ var result = mergeDeepArray(objectsToMerge);
2509
2516
  var finalResult = { result: result, missing: missing };
2510
2517
  var frozen = context.canonizeResults
2511
2518
  ? this.canon.admit(finalResult)
@@ -2519,10 +2526,11 @@ var StoreReader = (function () {
2519
2526
  var _this = this;
2520
2527
  var field = _a.field, array = _a.array, enclosingRef = _a.enclosingRef, context = _a.context;
2521
2528
  var missing;
2529
+ var missingMerger = new DeepMerger();
2522
2530
  function handleMissing(childResult, i) {
2523
2531
  var _a;
2524
2532
  if (childResult.missing) {
2525
- missing = context.merge(missing, (_a = {}, _a[i] = childResult.missing, _a));
2533
+ missing = missingMerger.merge(missing, (_a = {}, _a[i] = childResult.missing, _a));
2526
2534
  }
2527
2535
  return childResult.result;
2528
2536
  }
@@ -3905,8 +3913,7 @@ function isNetworkRequestInFlight(networkStatus) {
3905
3913
  return networkStatus ? networkStatus < 7 : false;
3906
3914
  }
3907
3915
 
3908
- var assign = Object.assign, hasOwnProperty$1 = Object.hasOwnProperty;
3909
- var warnedAboutUpdateQuery = false;
3916
+ var assign = Object.assign, hasOwnProperty$2 = Object.hasOwnProperty;
3910
3917
  var ObservableQuery = (function (_super) {
3911
3918
  tslib.__extends(ObservableQuery, _super);
3912
3919
  function ObservableQuery(_a) {
@@ -3939,16 +3946,24 @@ var ObservableQuery = (function (_super) {
3939
3946
  }) || this;
3940
3947
  _this.observers = new Set();
3941
3948
  _this.subscriptions = new Set();
3949
+ _this.queryInfo = queryInfo;
3950
+ _this.queryManager = queryManager;
3942
3951
  _this.isTornDown = false;
3943
- _this.options = options;
3952
+ var _b = queryManager.defaultOptions.watchQuery, _c = _b === void 0 ? {} : _b, _d = _c.fetchPolicy, defaultFetchPolicy = _d === void 0 ? "cache-first" : _d;
3953
+ var _e = options.fetchPolicy, fetchPolicy = _e === void 0 ? defaultFetchPolicy : _e, _f = options.initialFetchPolicy, initialFetchPolicy = _f === void 0 ? (fetchPolicy === "standby" ? defaultFetchPolicy : fetchPolicy) : _f;
3954
+ _this.options = tslib.__assign(tslib.__assign({}, options), { initialFetchPolicy: initialFetchPolicy, fetchPolicy: fetchPolicy });
3944
3955
  _this.queryId = queryInfo.queryId || queryManager.generateQueryId();
3945
- var opDef = getOperationDefinition(options.query);
3956
+ var opDef = getOperationDefinition(_this.query);
3946
3957
  _this.queryName = opDef && opDef.name && opDef.name.value;
3947
- _this.initialFetchPolicy = options.fetchPolicy || "cache-first";
3948
- _this.queryManager = queryManager;
3949
- _this.queryInfo = queryInfo;
3950
3958
  return _this;
3951
3959
  }
3960
+ Object.defineProperty(ObservableQuery.prototype, "query", {
3961
+ get: function () {
3962
+ return this.queryManager.transform(this.options.query).document;
3963
+ },
3964
+ enumerable: false,
3965
+ configurable: true
3966
+ });
3952
3967
  Object.defineProperty(ObservableQuery.prototype, "variables", {
3953
3968
  get: function () {
3954
3969
  return this.options.variables;
@@ -4061,8 +4076,8 @@ var ObservableQuery = (function (_super) {
4061
4076
  else {
4062
4077
  reobserveOptions.fetchPolicy = 'network-only';
4063
4078
  }
4064
- if (__DEV__ && variables && hasOwnProperty$1.call(variables, "variables")) {
4065
- var queryDef = getQueryDefinition(this.options.query);
4079
+ if (__DEV__ && variables && hasOwnProperty$2.call(variables, "variables")) {
4080
+ var queryDef = getQueryDefinition(this.query);
4066
4081
  var vars = queryDef.variableDefinitions;
4067
4082
  if (!vars || !vars.some(function (v) { return v.variable.name.value === "variables"; })) {
4068
4083
  __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 })?"));
@@ -4076,37 +4091,51 @@ var ObservableQuery = (function (_super) {
4076
4091
  };
4077
4092
  ObservableQuery.prototype.fetchMore = function (fetchMoreOptions) {
4078
4093
  var _this = this;
4079
- var combinedOptions = tslib.__assign(tslib.__assign({}, (fetchMoreOptions.query ? fetchMoreOptions : tslib.__assign(tslib.__assign(tslib.__assign({}, this.options), fetchMoreOptions), { variables: tslib.__assign(tslib.__assign({}, this.options.variables), fetchMoreOptions.variables) }))), { fetchPolicy: "no-cache" });
4094
+ var combinedOptions = tslib.__assign(tslib.__assign({}, (fetchMoreOptions.query ? fetchMoreOptions : tslib.__assign(tslib.__assign(tslib.__assign(tslib.__assign({}, this.options), { query: this.query }), fetchMoreOptions), { variables: tslib.__assign(tslib.__assign({}, this.options.variables), fetchMoreOptions.variables) }))), { fetchPolicy: "no-cache" });
4080
4095
  var qid = this.queryManager.generateQueryId();
4096
+ var queryInfo = this.queryInfo;
4097
+ var originalNetworkStatus = queryInfo.networkStatus;
4098
+ queryInfo.networkStatus = exports.NetworkStatus.fetchMore;
4081
4099
  if (combinedOptions.notifyOnNetworkStatusChange) {
4082
- this.queryInfo.networkStatus = exports.NetworkStatus.fetchMore;
4083
4100
  this.observe();
4084
4101
  }
4102
+ var updatedQuerySet = new Set();
4085
4103
  return this.queryManager.fetchQuery(qid, combinedOptions, exports.NetworkStatus.fetchMore).then(function (fetchMoreResult) {
4086
- var data = fetchMoreResult.data;
4087
- var updateQuery = fetchMoreOptions.updateQuery;
4088
- if (updateQuery) {
4089
- if (__DEV__ &&
4090
- !warnedAboutUpdateQuery) {
4091
- __DEV__ && tsInvariant.invariant.warn("The updateQuery callback for fetchMore is deprecated, and will be removed\nin the next major version of Apollo Client.\n\nPlease convert updateQuery functions to field policies with appropriate\nread and merge functions, or use/adapt a helper function (such as\nconcatPagination, offsetLimitPagination, or relayStylePagination) from\n@apollo/client/utilities.\n\nThe field policy system handles pagination more effectively than a\nhand-written updateQuery function, and you only need to define the policy\nonce, rather than every time you call fetchMore.");
4092
- warnedAboutUpdateQuery = true;
4093
- }
4094
- _this.updateQuery(function (previous) { return updateQuery(previous, {
4095
- fetchMoreResult: data,
4096
- variables: combinedOptions.variables,
4097
- }); });
4098
- }
4099
- else {
4100
- _this.queryManager.cache.writeQuery({
4101
- query: combinedOptions.query,
4102
- variables: combinedOptions.variables,
4103
- data: data,
4104
- });
4105
- }
4104
+ _this.queryManager.removeQuery(qid);
4105
+ if (queryInfo.networkStatus === exports.NetworkStatus.fetchMore) {
4106
+ queryInfo.networkStatus = originalNetworkStatus;
4107
+ }
4108
+ _this.queryManager.cache.batch({
4109
+ update: function (cache) {
4110
+ var updateQuery = fetchMoreOptions.updateQuery;
4111
+ if (updateQuery) {
4112
+ cache.updateQuery({
4113
+ query: _this.query,
4114
+ variables: _this.variables,
4115
+ returnPartialData: true,
4116
+ optimistic: false,
4117
+ }, function (previous) { return updateQuery(previous, {
4118
+ fetchMoreResult: fetchMoreResult.data,
4119
+ variables: combinedOptions.variables,
4120
+ }); });
4121
+ }
4122
+ else {
4123
+ cache.writeQuery({
4124
+ query: combinedOptions.query,
4125
+ variables: combinedOptions.variables,
4126
+ data: fetchMoreResult.data,
4127
+ });
4128
+ }
4129
+ },
4130
+ onWatchUpdated: function (watch) {
4131
+ updatedQuerySet.add(watch.query);
4132
+ },
4133
+ });
4106
4134
  return fetchMoreResult;
4107
4135
  }).finally(function () {
4108
- _this.queryManager.stopQuery(qid);
4109
- _this.reobserve();
4136
+ if (!updatedQuerySet.has(_this.query)) {
4137
+ reobserveCacheFirst(_this);
4138
+ }
4110
4139
  });
4111
4140
  };
4112
4141
  ObservableQuery.prototype.subscribeToMore = function (options) {
@@ -4159,7 +4188,7 @@ var ObservableQuery = (function (_super) {
4159
4188
  return Promise.resolve();
4160
4189
  }
4161
4190
  return this.reobserve({
4162
- fetchPolicy: this.initialFetchPolicy,
4191
+ fetchPolicy: this.options.initialFetchPolicy,
4163
4192
  variables: variables,
4164
4193
  }, exports.NetworkStatus.setVariables);
4165
4194
  };
@@ -4191,6 +4220,26 @@ var ObservableQuery = (function (_super) {
4191
4220
  this.options.pollInterval = 0;
4192
4221
  this.updatePolling();
4193
4222
  };
4223
+ ObservableQuery.prototype.applyNextFetchPolicy = function (reason, options) {
4224
+ if (options.nextFetchPolicy) {
4225
+ var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a, _b = options.initialFetchPolicy, initialFetchPolicy = _b === void 0 ? fetchPolicy : _b;
4226
+ if (typeof options.nextFetchPolicy === "function") {
4227
+ options.fetchPolicy = options.nextFetchPolicy(fetchPolicy, {
4228
+ reason: reason,
4229
+ options: options,
4230
+ observable: this,
4231
+ initialFetchPolicy: initialFetchPolicy,
4232
+ });
4233
+ }
4234
+ else if (reason === "variables-changed") {
4235
+ options.fetchPolicy = initialFetchPolicy;
4236
+ }
4237
+ else {
4238
+ options.fetchPolicy = options.nextFetchPolicy;
4239
+ }
4240
+ }
4241
+ return options.fetchPolicy;
4242
+ };
4194
4243
  ObservableQuery.prototype.fetch = function (options, newNetworkStatus) {
4195
4244
  this.queryManager.setObservableQuery(this);
4196
4245
  return this.queryManager.fetchQueryObservable(this.queryId, options, newNetworkStatus);
@@ -4253,16 +4302,18 @@ var ObservableQuery = (function (_super) {
4253
4302
  newNetworkStatus === exports.NetworkStatus.fetchMore ||
4254
4303
  newNetworkStatus === exports.NetworkStatus.poll;
4255
4304
  var oldVariables = this.options.variables;
4305
+ var oldFetchPolicy = this.options.fetchPolicy;
4306
+ var mergedOptions = compact(this.options, newOptions || {});
4256
4307
  var options = useDisposableConcast
4257
- ? compact(this.options, newOptions)
4258
- : assign(this.options, compact(newOptions));
4308
+ ? mergedOptions
4309
+ : assign(this.options, mergedOptions);
4259
4310
  if (!useDisposableConcast) {
4260
4311
  this.updatePolling();
4261
4312
  if (newOptions &&
4262
4313
  newOptions.variables &&
4263
- !newOptions.fetchPolicy &&
4264
- !equality.equal(newOptions.variables, oldVariables)) {
4265
- options.fetchPolicy = this.initialFetchPolicy;
4314
+ !equality.equal(newOptions.variables, oldVariables) &&
4315
+ (!newOptions.fetchPolicy || newOptions.fetchPolicy === oldFetchPolicy)) {
4316
+ this.applyNextFetchPolicy("variables-changed", options);
4266
4317
  if (newNetworkStatus === void 0) {
4267
4318
  newNetworkStatus = exports.NetworkStatus.setVariables;
4268
4319
  }
@@ -4326,6 +4377,23 @@ var ObservableQuery = (function (_super) {
4326
4377
  return ObservableQuery;
4327
4378
  }(zenObservableTs.Observable));
4328
4379
  fixObservableSubclass(ObservableQuery);
4380
+ function reobserveCacheFirst(obsQuery) {
4381
+ var _a = obsQuery.options, fetchPolicy = _a.fetchPolicy, nextFetchPolicy = _a.nextFetchPolicy;
4382
+ if (fetchPolicy === "cache-and-network" ||
4383
+ fetchPolicy === "network-only") {
4384
+ return obsQuery.reobserve({
4385
+ fetchPolicy: "cache-first",
4386
+ nextFetchPolicy: function () {
4387
+ this.nextFetchPolicy = nextFetchPolicy;
4388
+ if (typeof nextFetchPolicy === "function") {
4389
+ return nextFetchPolicy.apply(this, arguments);
4390
+ }
4391
+ return fetchPolicy;
4392
+ },
4393
+ });
4394
+ }
4395
+ return obsQuery.reobserve();
4396
+ }
4329
4397
  function defaultSubscriptionObserverErrorCallback(error) {
4330
4398
  __DEV__ && tsInvariant.invariant.error('Unhandled error', error.message, error.stack);
4331
4399
  }
@@ -4334,14 +4402,6 @@ function logMissingFieldErrors(missing) {
4334
4402
  __DEV__ && tsInvariant.invariant.debug("Missing cache result fields: ".concat(JSON.stringify(missing)), missing);
4335
4403
  }
4336
4404
  }
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
4405
 
4346
4406
  var LocalState = (function () {
4347
4407
  function LocalState(_a) {
@@ -4724,11 +4784,12 @@ var QueryInfo = (function () {
4724
4784
  if (oq) {
4725
4785
  oq["queryInfo"] = this;
4726
4786
  this.listeners.add(this.oqListener = function () {
4727
- if (_this.getDiff().fromOptimisticTransaction) {
4787
+ var diff = _this.getDiff();
4788
+ if (diff.fromOptimisticTransaction) {
4728
4789
  oq["observe"]();
4729
4790
  }
4730
4791
  else {
4731
- oq.reobserve();
4792
+ reobserveCacheFirst(oq);
4732
4793
  }
4733
4794
  });
4734
4795
  }
@@ -4870,10 +4931,10 @@ function shouldWriteResult(result, errorPolicy) {
4870
4931
  return writeWithErrors;
4871
4932
  }
4872
4933
 
4873
- var hasOwnProperty = Object.prototype.hasOwnProperty;
4934
+ var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
4874
4935
  var QueryManager = (function () {
4875
4936
  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;
4937
+ 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
4938
  this.clientAwareness = {};
4878
4939
  this.queries = new Map();
4879
4940
  this.fetchCancelFns = new Map();
@@ -4884,6 +4945,7 @@ var QueryManager = (function () {
4884
4945
  this.inFlightLinkObservables = new Map();
4885
4946
  this.cache = cache;
4886
4947
  this.link = link;
4948
+ this.defaultOptions = defaultOptions || Object.create(null);
4887
4949
  this.queryDeduplication = queryDeduplication;
4888
4950
  this.clientAwareness = clientAwareness;
4889
4951
  this.localState = localState || new LocalState({ cache: cache });
@@ -4905,11 +4967,12 @@ var QueryManager = (function () {
4905
4967
  this.fetchCancelFns.clear();
4906
4968
  };
4907
4969
  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;
4970
+ var _b, _c;
4971
+ 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
4972
  return tslib.__awaiter(this, void 0, void 0, function () {
4910
4973
  var mutationId, mutationStoreValue, self;
4911
- return tslib.__generator(this, function (_f) {
4912
- switch (_f.label) {
4974
+ return tslib.__generator(this, function (_h) {
4975
+ switch (_h.label) {
4913
4976
  case 0:
4914
4977
  __DEV__ ? tsInvariant.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : tsInvariant.invariant(mutation, 12);
4915
4978
  __DEV__ ? tsInvariant.invariant(fetchPolicy === 'network-only' ||
@@ -4921,8 +4984,8 @@ var QueryManager = (function () {
4921
4984
  if (!this.transform(mutation).hasClientExports) return [3, 2];
4922
4985
  return [4, this.localState.addExportedVariables(mutation, variables, context)];
4923
4986
  case 1:
4924
- variables = (_f.sent());
4925
- _f.label = 2;
4987
+ variables = (_h.sent());
4988
+ _h.label = 2;
4926
4989
  case 2:
4927
4990
  mutationStoreValue = this.mutationStore &&
4928
4991
  (this.mutationStore[mutationId] = {
@@ -5023,7 +5086,7 @@ var QueryManager = (function () {
5023
5086
  this.queries.forEach(function (_a, queryId) {
5024
5087
  var observableQuery = _a.observableQuery;
5025
5088
  var queryName = observableQuery && observableQuery.queryName;
5026
- if (!queryName || !hasOwnProperty.call(updateQueries_1, queryName)) {
5089
+ if (!queryName || !hasOwnProperty$1.call(updateQueries_1, queryName)) {
5027
5090
  return;
5028
5091
  }
5029
5092
  var updater = updateQueries_1[queryName];
@@ -5189,9 +5252,9 @@ var QueryManager = (function () {
5189
5252
  });
5190
5253
  this.queries.set(observable.queryId, queryInfo);
5191
5254
  queryInfo.init({
5192
- document: options.query,
5255
+ document: observable.query,
5193
5256
  observableQuery: observable,
5194
- variables: options.variables,
5257
+ variables: observable.variables,
5195
5258
  });
5196
5259
  return observable;
5197
5260
  };
@@ -5375,8 +5438,10 @@ var QueryManager = (function () {
5375
5438
  };
5376
5439
  QueryManager.prototype.removeQuery = function (queryId) {
5377
5440
  this.fetchCancelFns.delete(queryId);
5378
- this.getQuery(queryId).stop();
5379
- this.queries.delete(queryId);
5441
+ if (this.queries.has(queryId)) {
5442
+ this.getQuery(queryId).stop();
5443
+ this.queries.delete(queryId);
5444
+ }
5380
5445
  };
5381
5446
  QueryManager.prototype.broadcastQueries = function () {
5382
5447
  if (this.onBroadcast)
@@ -5460,10 +5525,11 @@ var QueryManager = (function () {
5460
5525
  var aqr = {
5461
5526
  data: result.data,
5462
5527
  loading: false,
5463
- networkStatus: queryInfo.networkStatus || exports.NetworkStatus.ready,
5528
+ networkStatus: exports.NetworkStatus.ready,
5464
5529
  };
5465
5530
  if (hasErrors && options.errorPolicy !== "ignore") {
5466
5531
  aqr.errors = result.errors;
5532
+ aqr.networkStatus = exports.NetworkStatus.error;
5467
5533
  }
5468
5534
  return aqr;
5469
5535
  }, function (networkError) {
@@ -5482,7 +5548,8 @@ var QueryManager = (function () {
5482
5548
  var query = this.transform(options.query).document;
5483
5549
  var variables = this.getVariables(query, options.variables);
5484
5550
  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;
5551
+ var defaults = this.defaultOptions.watchQuery;
5552
+ 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
5553
  var normalized = Object.assign({}, options, {
5487
5554
  query: query,
5488
5555
  variables: variables,
@@ -5504,7 +5571,9 @@ var QueryManager = (function () {
5504
5571
  : fromVariables(normalized.variables));
5505
5572
  concast.cleanup(function () {
5506
5573
  _this.fetchCancelFns.delete(queryId);
5507
- applyNextFetchPolicy(options);
5574
+ if (queryInfo.observableQuery) {
5575
+ queryInfo.observableQuery["applyNextFetchPolicy"]("after-fetch", options);
5576
+ }
5508
5577
  });
5509
5578
  return concast;
5510
5579
  };
@@ -5581,7 +5650,7 @@ var QueryManager = (function () {
5581
5650
  var query = _a.query, variables = _a.variables, fetchPolicy = _a.fetchPolicy, refetchWritePolicy = _a.refetchWritePolicy, errorPolicy = _a.errorPolicy, returnPartialData = _a.returnPartialData, context = _a.context, notifyOnNetworkStatusChange = _a.notifyOnNetworkStatusChange;
5582
5651
  var oldNetworkStatus = queryInfo.networkStatus;
5583
5652
  queryInfo.init({
5584
- document: query,
5653
+ document: this.transform(query).document,
5585
5654
  variables: variables,
5586
5655
  networkStatus: networkStatus,
5587
5656
  });
@@ -5610,14 +5679,12 @@ var QueryManager = (function () {
5610
5679
  (networkStatus === exports.NetworkStatus.refetch &&
5611
5680
  refetchWritePolicy !== "merge") ? 1
5612
5681
  : 2;
5613
- var resultsFromLink = function () {
5614
- return _this.getResultsFromLink(queryInfo, cacheWriteBehavior, {
5615
- variables: variables,
5616
- context: context,
5617
- fetchPolicy: fetchPolicy,
5618
- errorPolicy: errorPolicy,
5619
- });
5620
- };
5682
+ var resultsFromLink = function () { return _this.getResultsFromLink(queryInfo, cacheWriteBehavior, {
5683
+ variables: variables,
5684
+ context: context,
5685
+ fetchPolicy: fetchPolicy,
5686
+ errorPolicy: errorPolicy,
5687
+ }); };
5621
5688
  var shouldNotify = notifyOnNetworkStatusChange &&
5622
5689
  typeof oldNetworkStatus === "number" &&
5623
5690
  oldNetworkStatus !== networkStatus &&
@@ -5692,15 +5759,9 @@ var QueryManager = (function () {
5692
5759
  }());
5693
5760
 
5694
5761
  var hasSuggestedDevtools = false;
5695
- function mergeOptions(defaults, options) {
5696
- return compact(defaults, options, options.variables && {
5697
- variables: tslib.__assign(tslib.__assign({}, defaults.variables), options.variables),
5698
- });
5699
- }
5700
5762
  var ApolloClient = (function () {
5701
5763
  function ApolloClient(options) {
5702
5764
  var _this = this;
5703
- this.defaultOptions = {};
5704
5765
  this.resetStoreCallbacks = [];
5705
5766
  this.clearStoreCallbacks = [];
5706
5767
  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 +5782,7 @@ var ApolloClient = (function () {
5721
5782
  this.cache = cache;
5722
5783
  this.disableNetworkFetches = ssrMode || ssrForceFetchDelay > 0;
5723
5784
  this.queryDeduplication = queryDeduplication;
5724
- this.defaultOptions = defaultOptions || {};
5785
+ this.defaultOptions = defaultOptions || Object.create(null);
5725
5786
  this.typeDefs = typeDefs;
5726
5787
  if (ssrForceFetchDelay) {
5727
5788
  setTimeout(function () { return (_this.disableNetworkFetches = false); }, ssrForceFetchDelay);
@@ -5768,6 +5829,7 @@ var ApolloClient = (function () {
5768
5829
  this.queryManager = new QueryManager({
5769
5830
  cache: this.cache,
5770
5831
  link: this.link,
5832
+ defaultOptions: this.defaultOptions,
5771
5833
  queryDeduplication: queryDeduplication,
5772
5834
  ssrMode: ssrMode,
5773
5835
  clientAwareness: {
@@ -5945,17 +6007,17 @@ function getApolloContext() {
5945
6007
 
5946
6008
  var ApolloConsumer = function (props) {
5947
6009
  var ApolloContext = getApolloContext();
5948
- return React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
6010
+ return (React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
5949
6011
  __DEV__ ? tsInvariant.invariant(context && context.client, 'Could not find "client" in the context of ApolloConsumer. ' +
5950
6012
  'Wrap the root component in an <ApolloProvider>.') : tsInvariant.invariant(context && context.client, 25);
5951
6013
  return props.children(context.client);
5952
- });
6014
+ }));
5953
6015
  };
5954
6016
 
5955
6017
  var ApolloProvider = function (_a) {
5956
6018
  var client = _a.client, children = _a.children;
5957
6019
  var ApolloContext = getApolloContext();
5958
- return React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
6020
+ return (React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
5959
6021
  if (context === void 0) { context = {}; }
5960
6022
  if (client && context.client !== client) {
5961
6023
  context = Object.assign({}, context, { client: client });
@@ -5963,7 +6025,7 @@ var ApolloProvider = function (_a) {
5963
6025
  __DEV__ ? tsInvariant.invariant(context.client, 'ApolloProvider was not passed a client instance. Make ' +
5964
6026
  'sure you pass in your client via the "client" prop.') : tsInvariant.invariant(context.client, 26);
5965
6027
  return (React__namespace.createElement(ApolloContext.Provider, { value: context }, children));
5966
- });
6028
+ }));
5967
6029
  };
5968
6030
 
5969
6031
  function useApolloClient(override) {
@@ -5975,6 +6037,51 @@ function useApolloClient(override) {
5975
6037
  return client;
5976
6038
  }
5977
6039
 
6040
+ var didWarnUncachedGetSnapshot = false;
6041
+ var uSESKey = "useSyncExternalStore";
6042
+ var realHook = React__namespace[uSESKey];
6043
+ var useSyncExternalStore = realHook || (function (subscribe, getSnapshot, getServerSnapshot) {
6044
+ var value = getSnapshot();
6045
+ if (__DEV__ &&
6046
+ !didWarnUncachedGetSnapshot &&
6047
+ value !== getSnapshot()) {
6048
+ didWarnUncachedGetSnapshot = true;
6049
+ __DEV__ && tsInvariant.invariant.error('The result of getSnapshot should be cached to avoid an infinite loop');
6050
+ }
6051
+ var _a = React__namespace.useState({ inst: { value: value, getSnapshot: getSnapshot } }), inst = _a[0].inst, forceUpdate = _a[1];
6052
+ if (canUseLayoutEffect) {
6053
+ React__namespace.useLayoutEffect(function () {
6054
+ Object.assign(inst, { value: value, getSnapshot: getSnapshot });
6055
+ if (checkIfSnapshotChanged(inst)) {
6056
+ forceUpdate({ inst: inst });
6057
+ }
6058
+ }, [subscribe, value, getSnapshot]);
6059
+ }
6060
+ else {
6061
+ Object.assign(inst, { value: value, getSnapshot: getSnapshot });
6062
+ }
6063
+ React__namespace.useEffect(function () {
6064
+ if (checkIfSnapshotChanged(inst)) {
6065
+ forceUpdate({ inst: inst });
6066
+ }
6067
+ return subscribe(function handleStoreChange() {
6068
+ if (checkIfSnapshotChanged(inst)) {
6069
+ forceUpdate({ inst: inst });
6070
+ }
6071
+ });
6072
+ }, [subscribe]);
6073
+ return value;
6074
+ });
6075
+ function checkIfSnapshotChanged(_a) {
6076
+ var value = _a.value, getSnapshot = _a.getSnapshot;
6077
+ try {
6078
+ return value !== getSnapshot();
6079
+ }
6080
+ catch (_b) {
6081
+ return true;
6082
+ }
6083
+ }
6084
+
5978
6085
  exports.DocumentType = void 0;
5979
6086
  (function (DocumentType) {
5980
6087
  DocumentType[DocumentType["Query"] = 0] = "Query";
@@ -6005,16 +6112,30 @@ function parser(document) {
6005
6112
  __DEV__ ? tsInvariant.invariant(!!document && !!document.kind, "Argument of ".concat(document, " passed to parser was not a valid GraphQL ") +
6006
6113
  "DocumentNode. You may need to use 'graphql-tag' or another method " +
6007
6114
  "to convert your operation into a document") : tsInvariant.invariant(!!document && !!document.kind, 30);
6008
- var fragments = document.definitions.filter(function (x) { return x.kind === 'FragmentDefinition'; });
6009
- var queries = document.definitions.filter(function (x) {
6010
- return x.kind === 'OperationDefinition' && x.operation === 'query';
6011
- });
6012
- var mutations = document.definitions.filter(function (x) {
6013
- return x.kind === 'OperationDefinition' && x.operation === 'mutation';
6014
- });
6015
- var subscriptions = document.definitions.filter(function (x) {
6016
- return x.kind === 'OperationDefinition' && x.operation === 'subscription';
6017
- });
6115
+ var fragments = [];
6116
+ var queries = [];
6117
+ var mutations = [];
6118
+ var subscriptions = [];
6119
+ for (var _i = 0, _a = document.definitions; _i < _a.length; _i++) {
6120
+ var x = _a[_i];
6121
+ if (x.kind === 'FragmentDefinition') {
6122
+ fragments.push(x);
6123
+ continue;
6124
+ }
6125
+ if (x.kind === 'OperationDefinition') {
6126
+ switch (x.operation) {
6127
+ case 'query':
6128
+ queries.push(x);
6129
+ break;
6130
+ case 'mutation':
6131
+ mutations.push(x);
6132
+ break;
6133
+ case 'subscription':
6134
+ subscriptions.push(x);
6135
+ break;
6136
+ }
6137
+ }
6138
+ }
6018
6139
  __DEV__ ? tsInvariant.invariant(!fragments.length ||
6019
6140
  (queries.length || mutations.length || subscriptions.length), "Passing only a fragment to 'graphql' is not yet supported. " +
6020
6141
  "You must include a query, subscription or mutation as well") : tsInvariant.invariant(!fragments.length ||
@@ -6054,254 +6175,294 @@ function verifyDocumentType(document, type) {
6054
6175
  "".concat(requiredOperationName, ", but a ").concat(usedOperationName, " was used instead.")) : tsInvariant.invariant(operation.type === type, 34);
6055
6176
  }
6056
6177
 
6178
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
6057
6179
  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) {
6085
- resolve();
6086
- sub.unsubscribe();
6087
- }
6088
- },
6089
- error: function () {
6090
- resolve();
6091
- sub.unsubscribe();
6092
- },
6093
- complete: function () {
6094
- resolve();
6095
- },
6180
+ if (options === void 0) { options = Object.create(null); }
6181
+ return useInternalState(useApolloClient(options.client), query).useQuery(options);
6182
+ }
6183
+ function useInternalState(client, query) {
6184
+ var stateRef = React.useRef();
6185
+ if (!stateRef.current ||
6186
+ client !== stateRef.current.client ||
6187
+ query !== stateRef.current.query) {
6188
+ stateRef.current = new InternalState(client, query, stateRef.current);
6189
+ }
6190
+ var state = stateRef.current;
6191
+ var _a = React.useState(0); _a[0]; var setTick = _a[1];
6192
+ state.forceUpdate = function () {
6193
+ setTick(function (tick) { return tick + 1; });
6194
+ };
6195
+ return state;
6196
+ }
6197
+ var InternalState = (function () {
6198
+ function InternalState(client, query, previous) {
6199
+ this.client = client;
6200
+ this.query = query;
6201
+ this.asyncResolveFns = new Set();
6202
+ this.optionsToIgnoreOnce = new (canUseWeakSet ? WeakSet : Set)();
6203
+ this.ssrDisabledResult = maybeDeepFreeze({
6204
+ loading: true,
6205
+ data: void 0,
6206
+ error: void 0,
6207
+ networkStatus: exports.NetworkStatus.loading,
6208
+ });
6209
+ this.skipStandbyResult = maybeDeepFreeze({
6210
+ loading: false,
6211
+ data: void 0,
6212
+ error: void 0,
6213
+ networkStatus: exports.NetworkStatus.ready,
6214
+ });
6215
+ this.toQueryResultCache = new (canUseWeakMap ? WeakMap : Map)();
6216
+ verifyDocumentType(query, exports.DocumentType.Query);
6217
+ var previousResult = previous && previous.result;
6218
+ var previousData = previousResult && previousResult.data;
6219
+ if (previousData) {
6220
+ this.previousData = previousData;
6221
+ }
6222
+ }
6223
+ InternalState.prototype.forceUpdate = function () {
6224
+ __DEV__ && tsInvariant.invariant.warn("Calling default no-op implementation of InternalState#forceUpdate");
6225
+ };
6226
+ InternalState.prototype.asyncUpdate = function () {
6227
+ var _this = this;
6228
+ return new Promise(function (resolve) {
6229
+ _this.asyncResolveFns.add(resolve);
6230
+ _this.optionsToIgnoreOnce.add(_this.watchQueryOptions);
6231
+ _this.forceUpdate();
6232
+ });
6233
+ };
6234
+ InternalState.prototype.useQuery = function (options) {
6235
+ var _this = this;
6236
+ this.renderPromises = React.useContext(getApolloContext()).renderPromises;
6237
+ this.useOptions(options);
6238
+ var obsQuery = this.useObservableQuery();
6239
+ var result = useSyncExternalStore(React.useCallback(function () {
6240
+ if (_this.renderPromises) {
6241
+ return function () { };
6242
+ }
6243
+ var onNext = function () {
6244
+ var previousResult = _this.result;
6245
+ var result = obsQuery.getCurrentResult();
6246
+ if (previousResult &&
6247
+ previousResult.loading === result.loading &&
6248
+ previousResult.networkStatus === result.networkStatus &&
6249
+ equality.equal(previousResult.data, result.data)) {
6250
+ return;
6251
+ }
6252
+ _this.setResult(result);
6253
+ };
6254
+ var onError = function (error) {
6255
+ var last = obsQuery["last"];
6256
+ subscription.unsubscribe();
6257
+ try {
6258
+ obsQuery.resetLastResults();
6259
+ subscription = obsQuery.subscribe(onNext, onError);
6260
+ }
6261
+ finally {
6262
+ obsQuery["last"] = last;
6263
+ }
6264
+ if (!hasOwnProperty.call(error, 'graphQLErrors')) {
6265
+ throw error;
6266
+ }
6267
+ var previousResult = _this.result;
6268
+ if (!previousResult ||
6269
+ (previousResult && previousResult.loading) ||
6270
+ !equality.equal(error, previousResult.error)) {
6271
+ _this.setResult({
6272
+ data: (previousResult && previousResult.data),
6273
+ error: error,
6274
+ loading: false,
6275
+ networkStatus: exports.NetworkStatus.error,
6096
6276
  });
6097
- }); },
6098
- }, function () { return null; });
6277
+ }
6278
+ };
6279
+ var subscription = obsQuery.subscribe(onNext, onError);
6280
+ return function () { return subscription.unsubscribe(); };
6281
+ }, [
6282
+ obsQuery,
6283
+ this.renderPromises,
6284
+ this.client.disableNetworkFetches,
6285
+ ]), function () { return _this.getCurrentResult(); }, function () { return _this.getCurrentResult(); });
6286
+ this.unsafeHandlePartialRefetch(result);
6287
+ var queryResult = this.toQueryResult(result);
6288
+ if (!queryResult.loading && this.asyncResolveFns.size) {
6289
+ this.asyncResolveFns.forEach(function (resolve) { return resolve(queryResult); });
6290
+ this.asyncResolveFns.clear();
6291
+ }
6292
+ return queryResult;
6293
+ };
6294
+ InternalState.prototype.useOptions = function (options) {
6295
+ var _a;
6296
+ var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
6297
+ var currentWatchQueryOptions = this.watchQueryOptions;
6298
+ if (this.optionsToIgnoreOnce.has(currentWatchQueryOptions) ||
6299
+ !equality.equal(watchQueryOptions, currentWatchQueryOptions)) {
6300
+ this.watchQueryOptions = watchQueryOptions;
6301
+ if (currentWatchQueryOptions && this.observable) {
6302
+ this.optionsToIgnoreOnce.delete(currentWatchQueryOptions);
6303
+ this.observable.reobserve(watchQueryOptions);
6304
+ this.previousData = ((_a = this.result) === null || _a === void 0 ? void 0 : _a.data) || this.previousData;
6305
+ this.result = void 0;
6306
+ }
6307
+ }
6308
+ this.onCompleted = options.onCompleted || InternalState.prototype.onCompleted;
6309
+ this.onError = options.onError || InternalState.prototype.onError;
6310
+ if ((this.renderPromises || this.client.disableNetworkFetches) &&
6311
+ this.queryHookOptions.ssr === false &&
6312
+ !this.queryHookOptions.skip) {
6313
+ this.result = this.ssrDisabledResult;
6314
+ }
6315
+ else if (this.queryHookOptions.skip ||
6316
+ this.watchQueryOptions.fetchPolicy === 'standby') {
6317
+ this.result = this.skipStandbyResult;
6318
+ }
6319
+ else if (this.result === this.ssrDisabledResult ||
6320
+ this.result === this.skipStandbyResult) {
6321
+ this.result = void 0;
6322
+ }
6323
+ };
6324
+ InternalState.prototype.createWatchQueryOptions = function (_a) {
6325
+ var _b;
6326
+ if (_a === void 0) { _a = {}; }
6327
+ var skip = _a.skip; _a.ssr; _a.onCompleted; _a.onError; _a.displayName; _a.defaultOptions; var otherOptions = tslib.__rest(_a, ["skip", "ssr", "onCompleted", "onError", "displayName", "defaultOptions"]);
6328
+ var watchQueryOptions = Object.assign(otherOptions, { query: this.query });
6329
+ if (this.renderPromises &&
6330
+ (watchQueryOptions.fetchPolicy === 'network-only' ||
6331
+ watchQueryOptions.fetchPolicy === 'cache-and-network')) {
6332
+ watchQueryOptions.fetchPolicy = 'cache-first';
6333
+ }
6334
+ if (!watchQueryOptions.variables) {
6335
+ watchQueryOptions.variables = {};
6336
+ }
6337
+ if (skip) {
6338
+ var _c = watchQueryOptions.fetchPolicy, fetchPolicy = _c === void 0 ? this.getDefaultFetchPolicy() : _c, _d = watchQueryOptions.initialFetchPolicy, initialFetchPolicy = _d === void 0 ? fetchPolicy : _d;
6339
+ Object.assign(watchQueryOptions, {
6340
+ initialFetchPolicy: initialFetchPolicy,
6341
+ fetchPolicy: 'standby',
6342
+ });
6099
6343
  }
6100
- 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) {
6106
- if (result.error) {
6107
- (_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, result.error);
6108
- }
6109
- else if (result.data) {
6110
- (_b = options.onCompleted) === null || _b === void 0 ? void 0 : _b.call(options, result.data);
6111
- }
6344
+ else if (!watchQueryOptions.fetchPolicy) {
6345
+ watchQueryOptions.fetchPolicy =
6346
+ ((_b = this.observable) === null || _b === void 0 ? void 0 : _b.options.initialFetchPolicy) ||
6347
+ this.getDefaultFetchPolicy();
6112
6348
  }
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 () {
6349
+ return watchQueryOptions;
6350
+ };
6351
+ InternalState.prototype.getDefaultFetchPolicy = function () {
6124
6352
  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
- }
6353
+ return (((_a = this.queryHookOptions.defaultOptions) === null || _a === void 0 ? void 0 : _a.fetchPolicy) ||
6354
+ ((_b = this.client.defaultOptions.watchQuery) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
6355
+ "cache-first");
6356
+ };
6357
+ InternalState.prototype.onCompleted = function (data) { };
6358
+ InternalState.prototype.onError = function (error) { };
6359
+ InternalState.prototype.useObservableQuery = function () {
6360
+ var obsQuery = this.observable =
6361
+ this.renderPromises
6362
+ && this.renderPromises.getSSRObservable(this.watchQueryOptions)
6363
+ || this.observable
6364
+ || this.client.watchQuery(mergeOptions(this.queryHookOptions.defaultOptions, this.watchQueryOptions));
6365
+ this.obsQueryFields = React.useMemo(function () { return ({
6366
+ refetch: obsQuery.refetch.bind(obsQuery),
6367
+ reobserve: obsQuery.reobserve.bind(obsQuery),
6368
+ fetchMore: obsQuery.fetchMore.bind(obsQuery),
6369
+ updateQuery: obsQuery.updateQuery.bind(obsQuery),
6370
+ startPolling: obsQuery.startPolling.bind(obsQuery),
6371
+ stopPolling: obsQuery.stopPolling.bind(obsQuery),
6372
+ subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
6373
+ }); }, [obsQuery]);
6374
+ var ssrAllowed = !(this.queryHookOptions.ssr === false ||
6375
+ this.queryHookOptions.skip);
6376
+ if (this.renderPromises && ssrAllowed) {
6377
+ this.renderPromises.registerSSRObservable(obsQuery);
6378
+ if (obsQuery.getCurrentResult().loading) {
6379
+ this.renderPromises.addObservableQueryPromise(obsQuery);
6150
6380
  }
6151
6381
  }
6152
- Object.assign(ref.current, { client: client, query: query });
6153
- }, [obsQuery, client, query, options]);
6154
- React.useEffect(function () {
6155
- if (context.renderPromises) {
6156
- return;
6382
+ return obsQuery;
6383
+ };
6384
+ InternalState.prototype.setResult = function (nextResult) {
6385
+ var previousResult = this.result;
6386
+ if (previousResult && previousResult.data) {
6387
+ this.previousData = previousResult.data;
6157
6388
  }
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;
6389
+ this.result = nextResult;
6390
+ this.forceUpdate();
6391
+ this.handleErrorOrCompleted(nextResult);
6392
+ };
6393
+ InternalState.prototype.handleErrorOrCompleted = function (result) {
6394
+ if (!result.loading) {
6395
+ if (result.error) {
6396
+ this.onError(result.error);
6171
6397
  }
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);
6398
+ else if (result.data) {
6399
+ this.onCompleted(result.data);
6175
6400
  }
6176
6401
  }
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
- }
6402
+ };
6403
+ InternalState.prototype.getCurrentResult = function () {
6404
+ if (!this.result) {
6405
+ this.handleErrorOrCompleted(this.result = this.observable.getCurrentResult());
6202
6406
  }
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) &&
6407
+ return this.result;
6408
+ };
6409
+ InternalState.prototype.toQueryResult = function (result) {
6410
+ var queryResult = this.toQueryResultCache.get(result);
6411
+ if (queryResult)
6412
+ return queryResult;
6413
+ var data = result.data; result.partial; var resultWithoutPartial = tslib.__rest(result, ["data", "partial"]);
6414
+ 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 }));
6415
+ if (!queryResult.error && isNonEmptyArray(result.errors)) {
6416
+ queryResult.error = new ApolloError({ graphQLErrors: result.errors });
6417
+ }
6418
+ return queryResult;
6419
+ };
6420
+ InternalState.prototype.unsafeHandlePartialRefetch = function (result) {
6421
+ if (result.partial &&
6422
+ this.queryHookOptions.partialRefetch &&
6210
6423
  !result.loading &&
6211
6424
  (!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 () { });
6425
+ this.observable.options.fetchPolicy !== 'cache-only') {
6426
+ Object.assign(result, {
6427
+ loading: true,
6428
+ networkStatus: exports.NetworkStatus.refetch,
6429
+ });
6430
+ this.observable.refetch();
6221
6431
  }
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
- }
6432
+ };
6433
+ return InternalState;
6434
+ }());
6278
6435
 
6279
6436
  var EAGER_METHODS = [
6280
6437
  'refetch',
6438
+ 'reobserve',
6281
6439
  'fetchMore',
6282
6440
  'updateQuery',
6283
6441
  'startPolling',
6284
6442
  'subscribeToMore',
6285
6443
  ];
6286
6444
  function useLazyQuery(query, options) {
6287
- var _a = React.useState({
6288
- called: false,
6289
- }), execution = _a[0], setExecution = _a[1];
6290
- var result = useQuery(query, tslib.__assign(tslib.__assign(tslib.__assign({}, options), execution.options), { fetchPolicy: execution.called ? options === null || options === void 0 ? void 0 : options.fetchPolicy : 'standby', skip: undefined }));
6291
- if (!execution.called) {
6292
- result = tslib.__assign(tslib.__assign({}, result), { loading: false, data: void 0, error: void 0, called: false });
6293
- }
6445
+ var internalState = useInternalState(useApolloClient(options && options.client), query);
6446
+ var execOptionsRef = React.useRef();
6447
+ var merged = execOptionsRef.current
6448
+ ? mergeOptions(options, execOptionsRef.current)
6449
+ : options;
6450
+ var useQueryResult = internalState.useQuery(tslib.__assign(tslib.__assign({}, merged), { skip: !execOptionsRef.current }));
6451
+ var initialFetchPolicy = useQueryResult.observable.options.initialFetchPolicy ||
6452
+ internalState.getDefaultFetchPolicy();
6453
+ var result = Object.assign(useQueryResult, {
6454
+ called: !!execOptionsRef.current,
6455
+ });
6294
6456
  var eagerMethods = React.useMemo(function () {
6295
6457
  var eagerMethods = {};
6296
6458
  var _loop_1 = function (key) {
6297
6459
  var method = result[key];
6298
6460
  eagerMethods[key] = function () {
6299
- var args = [];
6300
- for (var _i = 0; _i < arguments.length; _i++) {
6301
- args[_i] = arguments[_i];
6461
+ if (!execOptionsRef.current) {
6462
+ execOptionsRef.current = Object.create(null);
6463
+ internalState.forceUpdate();
6302
6464
  }
6303
- setExecution(function (execution) { return (tslib.__assign(tslib.__assign({}, execution), { called: true })); });
6304
- return method.apply(void 0, args);
6465
+ return method.apply(this, arguments);
6305
6466
  };
6306
6467
  };
6307
6468
  for (var _i = 0, EAGER_METHODS_1 = EAGER_METHODS; _i < EAGER_METHODS_1.length; _i++) {
@@ -6310,15 +6471,14 @@ function useLazyQuery(query, options) {
6310
6471
  }
6311
6472
  return eagerMethods;
6312
6473
  }, []);
6313
- result.error = result.error || void 0;
6314
6474
  Object.assign(result, eagerMethods);
6315
6475
  var execute = React.useCallback(function (executeOptions) {
6316
- setExecution({ called: true, options: executeOptions });
6317
- var promise = result.refetch(executeOptions === null || executeOptions === void 0 ? void 0 : executeOptions.variables).then(function (result1) {
6318
- var result2 = tslib.__assign(tslib.__assign({}, result), { data: result1.data, error: result1.error, called: true, loading: false });
6319
- Object.assign(result2, eagerMethods);
6320
- return result2;
6321
- });
6476
+ execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
6477
+ fetchPolicy: initialFetchPolicy,
6478
+ };
6479
+ var promise = internalState
6480
+ .asyncUpdate()
6481
+ .then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
6322
6482
  promise.catch(function () { });
6323
6483
  return promise;
6324
6484
  }, []);
@@ -6360,7 +6520,7 @@ function useMutation(mutation, options) {
6360
6520
  var mutationId = ++ref.current.mutationId;
6361
6521
  var clientOptions = mergeOptions(baseOptions, executeOptions);
6362
6522
  return client.mutate(clientOptions).then(function (response) {
6363
- var _a, _b;
6523
+ var _a, _b, _c;
6364
6524
  var data = response.data, errors = response.errors;
6365
6525
  var error = errors && errors.length > 0
6366
6526
  ? new ApolloError({ graphQLErrors: errors })
@@ -6378,11 +6538,11 @@ function useMutation(mutation, options) {
6378
6538
  setResult(ref.current.result = result_1);
6379
6539
  }
6380
6540
  }
6381
- (_a = baseOptions.onCompleted) === null || _a === void 0 ? void 0 : _a.call(baseOptions, response.data);
6382
- (_b = executeOptions.onCompleted) === null || _b === void 0 ? void 0 : _b.call(executeOptions, response.data);
6541
+ (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onCompleted) === null || _b === void 0 ? void 0 : _b.call(_a, response.data);
6542
+ (_c = executeOptions.onCompleted) === null || _c === void 0 ? void 0 : _c.call(executeOptions, response.data);
6383
6543
  return response;
6384
6544
  }).catch(function (error) {
6385
- var _a, _b;
6545
+ var _a, _b, _c, _d;
6386
6546
  if (mutationId === ref.current.mutationId &&
6387
6547
  ref.current.isMounted) {
6388
6548
  var result_2 = {
@@ -6396,9 +6556,9 @@ function useMutation(mutation, options) {
6396
6556
  setResult(ref.current.result = result_2);
6397
6557
  }
6398
6558
  }
6399
- if (baseOptions.onError || clientOptions.onError) {
6400
- (_a = baseOptions.onError) === null || _a === void 0 ? void 0 : _a.call(baseOptions, error);
6401
- (_b = executeOptions.onError) === null || _b === void 0 ? void 0 : _b.call(executeOptions, error);
6559
+ if (((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) || clientOptions.onError) {
6560
+ (_c = (_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.onError) === null || _c === void 0 ? void 0 : _c.call(_b, error);
6561
+ (_d = executeOptions.onError) === null || _d === void 0 ? void 0 : _d.call(executeOptions, error);
6402
6562
  return { data: void 0, errors: error };
6403
6563
  }
6404
6564
  throw error;
@@ -6407,9 +6567,12 @@ function useMutation(mutation, options) {
6407
6567
  var reset = React.useCallback(function () {
6408
6568
  setResult({ called: false, loading: false, client: client });
6409
6569
  }, []);
6410
- React.useEffect(function () { return function () {
6411
- ref.current.isMounted = false;
6412
- }; }, []);
6570
+ React.useEffect(function () {
6571
+ ref.current.isMounted = true;
6572
+ return function () {
6573
+ ref.current.isMounted = false;
6574
+ };
6575
+ }, []);
6413
6576
  return [execute, tslib.__assign({ reset: reset }, result)];
6414
6577
  }
6415
6578
 
@@ -6433,6 +6596,12 @@ function useSubscription(subscription, options) {
6433
6596
  context: options === null || options === void 0 ? void 0 : options.context,
6434
6597
  });
6435
6598
  }), observable = _b[0], setObservable = _b[1];
6599
+ var canResetObservableRef = React.useRef(false);
6600
+ React.useEffect(function () {
6601
+ return function () {
6602
+ canResetObservableRef.current = true;
6603
+ };
6604
+ }, []);
6436
6605
  var ref = React.useRef({ client: client, subscription: subscription, options: options });
6437
6606
  React.useEffect(function () {
6438
6607
  var _a, _b, _c, _d;
@@ -6441,7 +6610,7 @@ function useSubscription(subscription, options) {
6441
6610
  shouldResubscribe = !!shouldResubscribe(options);
6442
6611
  }
6443
6612
  if (options === null || options === void 0 ? void 0 : options.skip) {
6444
- if (!(options === null || options === void 0 ? void 0 : options.skip) !== !((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.skip)) {
6613
+ if (!(options === null || options === void 0 ? void 0 : options.skip) !== !((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.skip) || canResetObservableRef.current) {
6445
6614
  setResult({
6446
6615
  loading: false,
6447
6616
  data: void 0,
@@ -6449,13 +6618,16 @@ function useSubscription(subscription, options) {
6449
6618
  variables: options === null || options === void 0 ? void 0 : options.variables,
6450
6619
  });
6451
6620
  setObservable(null);
6621
+ canResetObservableRef.current = false;
6452
6622
  }
6453
6623
  }
6454
- else if (shouldResubscribe !== false && (client !== ref.current.client ||
6455
- subscription !== ref.current.subscription ||
6456
- (options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
6457
- !(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))) {
6624
+ else if ((shouldResubscribe !== false &&
6625
+ (client !== ref.current.client ||
6626
+ subscription !== ref.current.subscription ||
6627
+ (options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
6628
+ !(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
6629
+ !equality.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) ||
6630
+ canResetObservableRef.current) {
6459
6631
  setResult({
6460
6632
  loading: true,
6461
6633
  data: void 0,
@@ -6468,9 +6640,10 @@ function useSubscription(subscription, options) {
6468
6640
  fetchPolicy: options === null || options === void 0 ? void 0 : options.fetchPolicy,
6469
6641
  context: options === null || options === void 0 ? void 0 : options.context,
6470
6642
  }));
6643
+ canResetObservableRef.current = false;
6471
6644
  }
6472
6645
  Object.assign(ref.current, { client: client, subscription: subscription, options: options });
6473
- }, [client, subscription, options]);
6646
+ }, [client, subscription, options, canResetObservableRef.current]);
6474
6647
  React.useEffect(function () {
6475
6648
  if (!observable) {
6476
6649
  return;
@@ -6542,7 +6715,6 @@ exports.HttpLink = HttpLink;
6542
6715
  exports.InMemoryCache = InMemoryCache;
6543
6716
  exports.MissingFieldError = MissingFieldError;
6544
6717
  exports.ObservableQuery = ObservableQuery;
6545
- exports.applyNextFetchPolicy = applyNextFetchPolicy;
6546
6718
  exports.checkFetcher = checkFetcher;
6547
6719
  exports.concat = concat;
6548
6720
  exports.createHttpLink = createHttpLink;