@apollo/client 3.5.10 → 3.6.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +5 -5
  3. package/apollo-client.cjs +563 -375
  4. package/apollo-client.cjs.map +1 -1
  5. package/apollo-client.min.cjs +1 -1
  6. package/cache/cache.cjs +10 -11
  7. package/cache/cache.cjs.map +1 -1
  8. package/cache/cache.cjs.native.js +2288 -0
  9. package/cache/inmemory/policies.js +1 -1
  10. package/cache/inmemory/policies.js.map +1 -1
  11. package/cache/inmemory/readFromStore.d.ts.map +1 -1
  12. package/cache/inmemory/readFromStore.js +10 -11
  13. package/cache/inmemory/readFromStore.js.map +1 -1
  14. package/core/ApolloClient.d.ts +2 -3
  15. package/core/ApolloClient.d.ts.map +1 -1
  16. package/core/ApolloClient.js +4 -8
  17. package/core/ApolloClient.js.map +1 -1
  18. package/core/ObservableQuery.d.ts +10 -4
  19. package/core/ObservableQuery.d.ts.map +1 -1
  20. package/core/ObservableQuery.js +101 -46
  21. package/core/ObservableQuery.js.map +1 -1
  22. package/core/QueryInfo.d.ts.map +1 -1
  23. package/core/QueryInfo.js +4 -2
  24. package/core/QueryInfo.js.map +1 -1
  25. package/core/QueryManager.d.ts +5 -2
  26. package/core/QueryManager.d.ts.map +1 -1
  27. package/core/QueryManager.js +36 -27
  28. package/core/QueryManager.js.map +1 -1
  29. package/core/core.cjs +148 -90
  30. package/core/core.cjs.map +1 -1
  31. package/core/core.cjs.native.js +2146 -0
  32. package/core/index.d.ts +1 -1
  33. package/core/index.d.ts.map +1 -1
  34. package/core/index.js +1 -1
  35. package/core/index.js.map +1 -1
  36. package/core/watchQueryOptions.d.ts +9 -1
  37. package/core/watchQueryOptions.d.ts.map +1 -1
  38. package/core/watchQueryOptions.js.map +1 -1
  39. package/errors/errors.cjs.native.js +48 -0
  40. package/invariantErrorCodes.js +1 -1
  41. package/link/batch/batch.cjs +46 -37
  42. package/link/batch/batch.cjs.map +1 -1
  43. package/link/batch/batch.cjs.native.js +160 -0
  44. package/link/batch/batching.d.ts +2 -6
  45. package/link/batch/batching.d.ts.map +1 -1
  46. package/link/batch/batching.js +46 -37
  47. package/link/batch/batching.js.map +1 -1
  48. package/link/batch-http/batch-http.cjs.native.js +127 -0
  49. package/link/context/context.cjs.native.js +38 -0
  50. package/link/core/core.cjs.native.js +121 -0
  51. package/link/error/error.cjs.native.js +90 -0
  52. package/link/http/http.cjs.native.js +320 -0
  53. package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
  54. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  55. package/link/persisted-queries/index.d.ts +2 -1
  56. package/link/persisted-queries/index.d.ts.map +1 -1
  57. package/link/persisted-queries/index.js +26 -13
  58. package/link/persisted-queries/index.js.map +1 -1
  59. package/link/persisted-queries/persisted-queries.cjs +25 -12
  60. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  61. package/link/persisted-queries/persisted-queries.cjs.native.js +174 -0
  62. package/link/retry/retry.cjs.native.js +170 -0
  63. package/link/schema/schema.cjs.native.js +56 -0
  64. package/link/subscriptions/subscriptions.cjs.native.js +45 -0
  65. package/link/utils/utils.cjs.native.js +115 -0
  66. package/link/ws/ws.cjs.native.js +28 -0
  67. package/main.cjs.native.js +16 -0
  68. package/package.json +30 -27
  69. package/react/components/components.cjs.native.js +79 -0
  70. package/react/context/ApolloConsumer.js +2 -2
  71. package/react/context/ApolloProvider.js +2 -2
  72. package/react/context/context.cjs +4 -4
  73. package/react/context/context.cjs.map +1 -1
  74. package/react/context/context.cjs.native.js +67 -0
  75. package/react/hoc/hoc.cjs.native.js +325 -0
  76. package/react/hooks/hooks.cjs +376 -253
  77. package/react/hooks/hooks.cjs.map +1 -1
  78. package/react/hooks/hooks.cjs.native.js +623 -0
  79. package/react/hooks/index.d.ts +1 -1
  80. package/react/hooks/index.d.ts.map +1 -1
  81. package/react/hooks/index.js +1 -1
  82. package/react/hooks/index.js.map +1 -1
  83. package/react/hooks/useLazyQuery.d.ts +2 -2
  84. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  85. package/react/hooks/useLazyQuery.js +26 -21
  86. package/react/hooks/useLazyQuery.js.map +1 -1
  87. package/react/hooks/useMutation.d.ts.map +1 -1
  88. package/react/hooks/useMutation.js +13 -10
  89. package/react/hooks/useMutation.js.map +1 -1
  90. package/react/hooks/useQuery.d.ts +37 -2
  91. package/react/hooks/useQuery.d.ts.map +1 -1
  92. package/react/hooks/useQuery.js +256 -206
  93. package/react/hooks/useQuery.js.map +1 -1
  94. package/react/hooks/useSubscription.d.ts.map +1 -1
  95. package/react/hooks/useSubscription.js +17 -7
  96. package/react/hooks/useSubscription.js.map +1 -1
  97. package/react/hooks/useSyncExternalStore.d.ts +4 -0
  98. package/react/hooks/useSyncExternalStore.d.ts.map +1 -0
  99. package/react/hooks/useSyncExternalStore.js +48 -0
  100. package/react/hooks/useSyncExternalStore.js.map +1 -0
  101. package/react/parser/index.d.ts.map +1 -1
  102. package/react/parser/index.js +24 -10
  103. package/react/parser/index.js.map +1 -1
  104. package/react/parser/parser.cjs +24 -10
  105. package/react/parser/parser.cjs.map +1 -1
  106. package/react/parser/parser.cjs.native.js +103 -0
  107. package/react/react.cjs.native.js +22 -0
  108. package/react/ssr/RenderPromises.d.ts +3 -2
  109. package/react/ssr/RenderPromises.d.ts.map +1 -1
  110. package/react/ssr/RenderPromises.js +25 -3
  111. package/react/ssr/RenderPromises.js.map +1 -1
  112. package/react/ssr/ssr.cjs +25 -3
  113. package/react/ssr/ssr.cjs.map +1 -1
  114. package/react/ssr/ssr.cjs.native.js +150 -0
  115. package/react/types/types.d.ts +10 -11
  116. package/react/types/types.d.ts.map +1 -1
  117. package/react/types/types.js.map +1 -1
  118. package/testing/core/core.cjs.native.js +288 -0
  119. package/testing/core/mocking/mockFetch.js +1 -1
  120. package/testing/core/mocking/mockFetch.js.map +1 -1
  121. package/testing/core/mocking/mockQueryManager.js +1 -1
  122. package/testing/core/mocking/mockWatchQuery.js +1 -1
  123. package/testing/core/wrap.js +1 -1
  124. package/testing/testing.cjs.native.js +58 -0
  125. package/utilities/common/canUse.d.ts +2 -0
  126. package/utilities/common/canUse.d.ts.map +1 -1
  127. package/utilities/common/canUse.js +6 -2
  128. package/utilities/common/canUse.js.map +1 -1
  129. package/utilities/common/mergeDeep.d.ts.map +1 -1
  130. package/utilities/common/mergeDeep.js +8 -11
  131. package/utilities/common/mergeDeep.js.map +1 -1
  132. package/utilities/common/mergeOptions.d.ts +5 -0
  133. package/utilities/common/mergeOptions.d.ts.map +1 -0
  134. package/utilities/common/mergeOptions.js +8 -0
  135. package/utilities/common/mergeOptions.js.map +1 -0
  136. package/utilities/globals/global.js +1 -2
  137. package/utilities/globals/globals.cjs.native.js +56 -0
  138. package/utilities/graphql/transform.d.ts +2 -2
  139. package/utilities/graphql/transform.d.ts.map +1 -1
  140. package/utilities/graphql/transform.js +1 -1
  141. package/utilities/graphql/transform.js.map +1 -1
  142. package/utilities/index.d.ts +1 -0
  143. package/utilities/index.d.ts.map +1 -1
  144. package/utilities/index.js +1 -0
  145. package/utilities/index.js.map +1 -1
  146. package/utilities/observables/Concast.d.ts +1 -0
  147. package/utilities/observables/Concast.d.ts.map +1 -1
  148. package/utilities/observables/Concast.js +5 -2
  149. package/utilities/observables/Concast.js.map +1 -1
  150. package/utilities/policies/pagination.d.ts.map +1 -1
  151. package/utilities/policies/pagination.js +9 -7
  152. package/utilities/policies/pagination.js.map +1 -1
  153. package/utilities/utilities.cjs +37 -23
  154. package/utilities/utilities.cjs.map +1 -1
  155. package/utilities/utilities.cjs.native.js +1281 -0
  156. 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.9';
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
  }
@@ -3111,7 +3119,7 @@ function makeFieldFunctionOptions(policies, objectOrReference, fieldSpec, contex
3111
3119
  cache: policies.cache,
3112
3120
  canRead: canRead,
3113
3121
  readField: function () {
3114
- return policies.readField(normalizeReadFieldOptions(arguments, objectOrReference, context), context);
3122
+ return policies.readField(normalizeReadFieldOptions(arguments, objectOrReference, variables), context);
3115
3123
  },
3116
3124
  mergeObjects: makeMergeObjectsFunction(context.store),
3117
3125
  };
@@ -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,27 @@ 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 (fetchPolicy === "standby") ;
4227
+ else if (typeof options.nextFetchPolicy === "function") {
4228
+ options.fetchPolicy = options.nextFetchPolicy(fetchPolicy, {
4229
+ reason: reason,
4230
+ options: options,
4231
+ observable: this,
4232
+ initialFetchPolicy: initialFetchPolicy,
4233
+ });
4234
+ }
4235
+ else if (reason === "variables-changed") {
4236
+ options.fetchPolicy = initialFetchPolicy;
4237
+ }
4238
+ else {
4239
+ options.fetchPolicy = options.nextFetchPolicy;
4240
+ }
4241
+ }
4242
+ return options.fetchPolicy;
4243
+ };
4194
4244
  ObservableQuery.prototype.fetch = function (options, newNetworkStatus) {
4195
4245
  this.queryManager.setObservableQuery(this);
4196
4246
  return this.queryManager.fetchQueryObservable(this.queryId, options, newNetworkStatus);
@@ -4253,16 +4303,19 @@ var ObservableQuery = (function (_super) {
4253
4303
  newNetworkStatus === exports.NetworkStatus.fetchMore ||
4254
4304
  newNetworkStatus === exports.NetworkStatus.poll;
4255
4305
  var oldVariables = this.options.variables;
4306
+ var oldFetchPolicy = this.options.fetchPolicy;
4307
+ var mergedOptions = compact(this.options, newOptions || {});
4256
4308
  var options = useDisposableConcast
4257
- ? compact(this.options, newOptions)
4258
- : assign(this.options, compact(newOptions));
4309
+ ? mergedOptions
4310
+ : assign(this.options, mergedOptions);
4259
4311
  if (!useDisposableConcast) {
4260
4312
  this.updatePolling();
4261
4313
  if (newOptions &&
4262
4314
  newOptions.variables &&
4263
- !newOptions.fetchPolicy &&
4264
- !equality.equal(newOptions.variables, oldVariables)) {
4265
- options.fetchPolicy = this.initialFetchPolicy;
4315
+ !equality.equal(newOptions.variables, oldVariables) &&
4316
+ options.fetchPolicy !== "standby" &&
4317
+ options.fetchPolicy === oldFetchPolicy) {
4318
+ this.applyNextFetchPolicy("variables-changed", options);
4266
4319
  if (newNetworkStatus === void 0) {
4267
4320
  newNetworkStatus = exports.NetworkStatus.setVariables;
4268
4321
  }
@@ -4280,7 +4333,7 @@ var ObservableQuery = (function (_super) {
4280
4333
  };
4281
4334
  if (!useDisposableConcast) {
4282
4335
  if (this.concast && this.observer) {
4283
- this.concast.removeObserver(this.observer, true);
4336
+ this.concast.removeObserver(this.observer);
4284
4337
  }
4285
4338
  this.concast = concast;
4286
4339
  this.observer = observer;
@@ -4326,6 +4379,23 @@ var ObservableQuery = (function (_super) {
4326
4379
  return ObservableQuery;
4327
4380
  }(zenObservableTs.Observable));
4328
4381
  fixObservableSubclass(ObservableQuery);
4382
+ function reobserveCacheFirst(obsQuery) {
4383
+ var _a = obsQuery.options, fetchPolicy = _a.fetchPolicy, nextFetchPolicy = _a.nextFetchPolicy;
4384
+ if (fetchPolicy === "cache-and-network" ||
4385
+ fetchPolicy === "network-only") {
4386
+ return obsQuery.reobserve({
4387
+ fetchPolicy: "cache-first",
4388
+ nextFetchPolicy: function () {
4389
+ this.nextFetchPolicy = nextFetchPolicy;
4390
+ if (typeof nextFetchPolicy === "function") {
4391
+ return nextFetchPolicy.apply(this, arguments);
4392
+ }
4393
+ return fetchPolicy;
4394
+ },
4395
+ });
4396
+ }
4397
+ return obsQuery.reobserve();
4398
+ }
4329
4399
  function defaultSubscriptionObserverErrorCallback(error) {
4330
4400
  __DEV__ && tsInvariant.invariant.error('Unhandled error', error.message, error.stack);
4331
4401
  }
@@ -4334,14 +4404,6 @@ function logMissingFieldErrors(missing) {
4334
4404
  __DEV__ && tsInvariant.invariant.debug("Missing cache result fields: ".concat(JSON.stringify(missing)), missing);
4335
4405
  }
4336
4406
  }
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
4407
 
4346
4408
  var LocalState = (function () {
4347
4409
  function LocalState(_a) {
@@ -4724,11 +4786,12 @@ var QueryInfo = (function () {
4724
4786
  if (oq) {
4725
4787
  oq["queryInfo"] = this;
4726
4788
  this.listeners.add(this.oqListener = function () {
4727
- if (_this.getDiff().fromOptimisticTransaction) {
4789
+ var diff = _this.getDiff();
4790
+ if (diff.fromOptimisticTransaction) {
4728
4791
  oq["observe"]();
4729
4792
  }
4730
4793
  else {
4731
- oq.reobserve();
4794
+ reobserveCacheFirst(oq);
4732
4795
  }
4733
4796
  });
4734
4797
  }
@@ -4870,10 +4933,10 @@ function shouldWriteResult(result, errorPolicy) {
4870
4933
  return writeWithErrors;
4871
4934
  }
4872
4935
 
4873
- var hasOwnProperty = Object.prototype.hasOwnProperty;
4936
+ var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
4874
4937
  var QueryManager = (function () {
4875
4938
  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;
4939
+ 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
4940
  this.clientAwareness = {};
4878
4941
  this.queries = new Map();
4879
4942
  this.fetchCancelFns = new Map();
@@ -4884,6 +4947,7 @@ var QueryManager = (function () {
4884
4947
  this.inFlightLinkObservables = new Map();
4885
4948
  this.cache = cache;
4886
4949
  this.link = link;
4950
+ this.defaultOptions = defaultOptions || Object.create(null);
4887
4951
  this.queryDeduplication = queryDeduplication;
4888
4952
  this.clientAwareness = clientAwareness;
4889
4953
  this.localState = localState || new LocalState({ cache: cache });
@@ -4905,11 +4969,12 @@ var QueryManager = (function () {
4905
4969
  this.fetchCancelFns.clear();
4906
4970
  };
4907
4971
  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;
4972
+ var _b, _c;
4973
+ 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
4974
  return tslib.__awaiter(this, void 0, void 0, function () {
4910
4975
  var mutationId, mutationStoreValue, self;
4911
- return tslib.__generator(this, function (_f) {
4912
- switch (_f.label) {
4976
+ return tslib.__generator(this, function (_h) {
4977
+ switch (_h.label) {
4913
4978
  case 0:
4914
4979
  __DEV__ ? tsInvariant.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : tsInvariant.invariant(mutation, 12);
4915
4980
  __DEV__ ? tsInvariant.invariant(fetchPolicy === 'network-only' ||
@@ -4921,8 +4986,8 @@ var QueryManager = (function () {
4921
4986
  if (!this.transform(mutation).hasClientExports) return [3, 2];
4922
4987
  return [4, this.localState.addExportedVariables(mutation, variables, context)];
4923
4988
  case 1:
4924
- variables = (_f.sent());
4925
- _f.label = 2;
4989
+ variables = (_h.sent());
4990
+ _h.label = 2;
4926
4991
  case 2:
4927
4992
  mutationStoreValue = this.mutationStore &&
4928
4993
  (this.mutationStore[mutationId] = {
@@ -5023,7 +5088,7 @@ var QueryManager = (function () {
5023
5088
  this.queries.forEach(function (_a, queryId) {
5024
5089
  var observableQuery = _a.observableQuery;
5025
5090
  var queryName = observableQuery && observableQuery.queryName;
5026
- if (!queryName || !hasOwnProperty.call(updateQueries_1, queryName)) {
5091
+ if (!queryName || !hasOwnProperty$1.call(updateQueries_1, queryName)) {
5027
5092
  return;
5028
5093
  }
5029
5094
  var updater = updateQueries_1[queryName];
@@ -5189,9 +5254,9 @@ var QueryManager = (function () {
5189
5254
  });
5190
5255
  this.queries.set(observable.queryId, queryInfo);
5191
5256
  queryInfo.init({
5192
- document: options.query,
5257
+ document: observable.query,
5193
5258
  observableQuery: observable,
5194
- variables: options.variables,
5259
+ variables: observable.variables,
5195
5260
  });
5196
5261
  return observable;
5197
5262
  };
@@ -5375,8 +5440,10 @@ var QueryManager = (function () {
5375
5440
  };
5376
5441
  QueryManager.prototype.removeQuery = function (queryId) {
5377
5442
  this.fetchCancelFns.delete(queryId);
5378
- this.getQuery(queryId).stop();
5379
- this.queries.delete(queryId);
5443
+ if (this.queries.has(queryId)) {
5444
+ this.getQuery(queryId).stop();
5445
+ this.queries.delete(queryId);
5446
+ }
5380
5447
  };
5381
5448
  QueryManager.prototype.broadcastQueries = function () {
5382
5449
  if (this.onBroadcast)
@@ -5460,10 +5527,11 @@ var QueryManager = (function () {
5460
5527
  var aqr = {
5461
5528
  data: result.data,
5462
5529
  loading: false,
5463
- networkStatus: queryInfo.networkStatus || exports.NetworkStatus.ready,
5530
+ networkStatus: exports.NetworkStatus.ready,
5464
5531
  };
5465
5532
  if (hasErrors && options.errorPolicy !== "ignore") {
5466
5533
  aqr.errors = result.errors;
5534
+ aqr.networkStatus = exports.NetworkStatus.error;
5467
5535
  }
5468
5536
  return aqr;
5469
5537
  }, function (networkError) {
@@ -5482,7 +5550,8 @@ var QueryManager = (function () {
5482
5550
  var query = this.transform(options.query).document;
5483
5551
  var variables = this.getVariables(query, options.variables);
5484
5552
  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;
5553
+ var defaults = this.defaultOptions.watchQuery;
5554
+ 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
5555
  var normalized = Object.assign({}, options, {
5487
5556
  query: query,
5488
5557
  variables: variables,
@@ -5494,18 +5563,23 @@ var QueryManager = (function () {
5494
5563
  });
5495
5564
  var fromVariables = function (variables) {
5496
5565
  normalized.variables = variables;
5497
- return _this.fetchQueryByPolicy(queryInfo, normalized, networkStatus);
5566
+ var concastSources = _this.fetchQueryByPolicy(queryInfo, normalized, networkStatus);
5567
+ if (normalized.fetchPolicy !== "standby" &&
5568
+ concastSources.length > 0 &&
5569
+ queryInfo.observableQuery) {
5570
+ queryInfo.observableQuery["applyNextFetchPolicy"]("after-fetch", options);
5571
+ }
5572
+ return concastSources;
5498
5573
  };
5574
+ var cleanupCancelFn = function () { return _this.fetchCancelFns.delete(queryId); };
5499
5575
  this.fetchCancelFns.set(queryId, function (reason) {
5576
+ cleanupCancelFn();
5500
5577
  setTimeout(function () { return concast.cancel(reason); });
5501
5578
  });
5502
5579
  var concast = new Concast(this.transform(normalized.query).hasClientExports
5503
5580
  ? this.localState.addExportedVariables(normalized.query, normalized.variables, normalized.context).then(fromVariables)
5504
5581
  : fromVariables(normalized.variables));
5505
- concast.cleanup(function () {
5506
- _this.fetchCancelFns.delete(queryId);
5507
- applyNextFetchPolicy(options);
5508
- });
5582
+ concast.promise.then(cleanupCancelFn, cleanupCancelFn);
5509
5583
  return concast;
5510
5584
  };
5511
5585
  QueryManager.prototype.refetchQueries = function (_a) {
@@ -5581,7 +5655,7 @@ var QueryManager = (function () {
5581
5655
  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
5656
  var oldNetworkStatus = queryInfo.networkStatus;
5583
5657
  queryInfo.init({
5584
- document: query,
5658
+ document: this.transform(query).document,
5585
5659
  variables: variables,
5586
5660
  networkStatus: networkStatus,
5587
5661
  });
@@ -5610,14 +5684,12 @@ var QueryManager = (function () {
5610
5684
  (networkStatus === exports.NetworkStatus.refetch &&
5611
5685
  refetchWritePolicy !== "merge") ? 1
5612
5686
  : 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
- };
5687
+ var resultsFromLink = function () { return _this.getResultsFromLink(queryInfo, cacheWriteBehavior, {
5688
+ variables: variables,
5689
+ context: context,
5690
+ fetchPolicy: fetchPolicy,
5691
+ errorPolicy: errorPolicy,
5692
+ }); };
5621
5693
  var shouldNotify = notifyOnNetworkStatusChange &&
5622
5694
  typeof oldNetworkStatus === "number" &&
5623
5695
  oldNetworkStatus !== networkStatus &&
@@ -5692,15 +5764,9 @@ var QueryManager = (function () {
5692
5764
  }());
5693
5765
 
5694
5766
  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
5767
  var ApolloClient = (function () {
5701
5768
  function ApolloClient(options) {
5702
5769
  var _this = this;
5703
- this.defaultOptions = {};
5704
5770
  this.resetStoreCallbacks = [];
5705
5771
  this.clearStoreCallbacks = [];
5706
5772
  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 +5787,7 @@ var ApolloClient = (function () {
5721
5787
  this.cache = cache;
5722
5788
  this.disableNetworkFetches = ssrMode || ssrForceFetchDelay > 0;
5723
5789
  this.queryDeduplication = queryDeduplication;
5724
- this.defaultOptions = defaultOptions || {};
5790
+ this.defaultOptions = defaultOptions || Object.create(null);
5725
5791
  this.typeDefs = typeDefs;
5726
5792
  if (ssrForceFetchDelay) {
5727
5793
  setTimeout(function () { return (_this.disableNetworkFetches = false); }, ssrForceFetchDelay);
@@ -5768,6 +5834,7 @@ var ApolloClient = (function () {
5768
5834
  this.queryManager = new QueryManager({
5769
5835
  cache: this.cache,
5770
5836
  link: this.link,
5837
+ defaultOptions: this.defaultOptions,
5771
5838
  queryDeduplication: queryDeduplication,
5772
5839
  ssrMode: ssrMode,
5773
5840
  clientAwareness: {
@@ -5945,17 +6012,17 @@ function getApolloContext() {
5945
6012
 
5946
6013
  var ApolloConsumer = function (props) {
5947
6014
  var ApolloContext = getApolloContext();
5948
- return React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
6015
+ return (React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
5949
6016
  __DEV__ ? tsInvariant.invariant(context && context.client, 'Could not find "client" in the context of ApolloConsumer. ' +
5950
6017
  'Wrap the root component in an <ApolloProvider>.') : tsInvariant.invariant(context && context.client, 25);
5951
6018
  return props.children(context.client);
5952
- });
6019
+ }));
5953
6020
  };
5954
6021
 
5955
6022
  var ApolloProvider = function (_a) {
5956
6023
  var client = _a.client, children = _a.children;
5957
6024
  var ApolloContext = getApolloContext();
5958
- return React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
6025
+ return (React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
5959
6026
  if (context === void 0) { context = {}; }
5960
6027
  if (client && context.client !== client) {
5961
6028
  context = Object.assign({}, context, { client: client });
@@ -5963,7 +6030,7 @@ var ApolloProvider = function (_a) {
5963
6030
  __DEV__ ? tsInvariant.invariant(context.client, 'ApolloProvider was not passed a client instance. Make ' +
5964
6031
  'sure you pass in your client via the "client" prop.') : tsInvariant.invariant(context.client, 26);
5965
6032
  return (React__namespace.createElement(ApolloContext.Provider, { value: context }, children));
5966
- });
6033
+ }));
5967
6034
  };
5968
6035
 
5969
6036
  function useApolloClient(override) {
@@ -5975,6 +6042,51 @@ function useApolloClient(override) {
5975
6042
  return client;
5976
6043
  }
5977
6044
 
6045
+ var didWarnUncachedGetSnapshot = false;
6046
+ var uSESKey = "useSyncExternalStore";
6047
+ var realHook = React__namespace[uSESKey];
6048
+ var useSyncExternalStore = realHook || (function (subscribe, getSnapshot, getServerSnapshot) {
6049
+ var value = getSnapshot();
6050
+ if (__DEV__ &&
6051
+ !didWarnUncachedGetSnapshot &&
6052
+ value !== getSnapshot()) {
6053
+ didWarnUncachedGetSnapshot = true;
6054
+ __DEV__ && tsInvariant.invariant.error('The result of getSnapshot should be cached to avoid an infinite loop');
6055
+ }
6056
+ var _a = React__namespace.useState({ inst: { value: value, getSnapshot: getSnapshot } }), inst = _a[0].inst, forceUpdate = _a[1];
6057
+ if (canUseLayoutEffect) {
6058
+ React__namespace.useLayoutEffect(function () {
6059
+ Object.assign(inst, { value: value, getSnapshot: getSnapshot });
6060
+ if (checkIfSnapshotChanged(inst)) {
6061
+ forceUpdate({ inst: inst });
6062
+ }
6063
+ }, [subscribe, value, getSnapshot]);
6064
+ }
6065
+ else {
6066
+ Object.assign(inst, { value: value, getSnapshot: getSnapshot });
6067
+ }
6068
+ React__namespace.useEffect(function () {
6069
+ if (checkIfSnapshotChanged(inst)) {
6070
+ forceUpdate({ inst: inst });
6071
+ }
6072
+ return subscribe(function handleStoreChange() {
6073
+ if (checkIfSnapshotChanged(inst)) {
6074
+ forceUpdate({ inst: inst });
6075
+ }
6076
+ });
6077
+ }, [subscribe]);
6078
+ return value;
6079
+ });
6080
+ function checkIfSnapshotChanged(_a) {
6081
+ var value = _a.value, getSnapshot = _a.getSnapshot;
6082
+ try {
6083
+ return value !== getSnapshot();
6084
+ }
6085
+ catch (_b) {
6086
+ return true;
6087
+ }
6088
+ }
6089
+
5978
6090
  exports.DocumentType = void 0;
5979
6091
  (function (DocumentType) {
5980
6092
  DocumentType[DocumentType["Query"] = 0] = "Query";
@@ -6005,16 +6117,30 @@ function parser(document) {
6005
6117
  __DEV__ ? tsInvariant.invariant(!!document && !!document.kind, "Argument of ".concat(document, " passed to parser was not a valid GraphQL ") +
6006
6118
  "DocumentNode. You may need to use 'graphql-tag' or another method " +
6007
6119
  "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
- });
6120
+ var fragments = [];
6121
+ var queries = [];
6122
+ var mutations = [];
6123
+ var subscriptions = [];
6124
+ for (var _i = 0, _a = document.definitions; _i < _a.length; _i++) {
6125
+ var x = _a[_i];
6126
+ if (x.kind === 'FragmentDefinition') {
6127
+ fragments.push(x);
6128
+ continue;
6129
+ }
6130
+ if (x.kind === 'OperationDefinition') {
6131
+ switch (x.operation) {
6132
+ case 'query':
6133
+ queries.push(x);
6134
+ break;
6135
+ case 'mutation':
6136
+ mutations.push(x);
6137
+ break;
6138
+ case 'subscription':
6139
+ subscriptions.push(x);
6140
+ break;
6141
+ }
6142
+ }
6143
+ }
6018
6144
  __DEV__ ? tsInvariant.invariant(!fragments.length ||
6019
6145
  (queries.length || mutations.length || subscriptions.length), "Passing only a fragment to 'graphql' is not yet supported. " +
6020
6146
  "You must include a query, subscription or mutation as well") : tsInvariant.invariant(!fragments.length ||
@@ -6054,254 +6180,305 @@ function verifyDocumentType(document, type) {
6054
6180
  "".concat(requiredOperationName, ", but a ").concat(usedOperationName, " was used instead.")) : tsInvariant.invariant(operation.type === type, 34);
6055
6181
  }
6056
6182
 
6183
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
6057
6184
  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
- },
6185
+ if (options === void 0) { options = Object.create(null); }
6186
+ return useInternalState(useApolloClient(options.client), query).useQuery(options);
6187
+ }
6188
+ function useInternalState(client, query) {
6189
+ var stateRef = React.useRef();
6190
+ if (!stateRef.current ||
6191
+ client !== stateRef.current.client ||
6192
+ query !== stateRef.current.query) {
6193
+ stateRef.current = new InternalState(client, query, stateRef.current);
6194
+ }
6195
+ var state = stateRef.current;
6196
+ var _a = React.useState(0); _a[0]; var setTick = _a[1];
6197
+ state.forceUpdate = function () {
6198
+ setTick(function (tick) { return tick + 1; });
6199
+ };
6200
+ return state;
6201
+ }
6202
+ var InternalState = (function () {
6203
+ function InternalState(client, query, previous) {
6204
+ this.client = client;
6205
+ this.query = query;
6206
+ this.asyncResolveFns = new Set();
6207
+ this.optionsToIgnoreOnce = new (canUseWeakSet ? WeakSet : Set)();
6208
+ this.ssrDisabledResult = maybeDeepFreeze({
6209
+ loading: true,
6210
+ data: void 0,
6211
+ error: void 0,
6212
+ networkStatus: exports.NetworkStatus.loading,
6213
+ });
6214
+ this.skipStandbyResult = maybeDeepFreeze({
6215
+ loading: false,
6216
+ data: void 0,
6217
+ error: void 0,
6218
+ networkStatus: exports.NetworkStatus.ready,
6219
+ });
6220
+ this.toQueryResultCache = new (canUseWeakMap ? WeakMap : Map)();
6221
+ verifyDocumentType(query, exports.DocumentType.Query);
6222
+ var previousResult = previous && previous.result;
6223
+ var previousData = previousResult && previousResult.data;
6224
+ if (previousData) {
6225
+ this.previousData = previousData;
6226
+ }
6227
+ }
6228
+ InternalState.prototype.forceUpdate = function () {
6229
+ __DEV__ && tsInvariant.invariant.warn("Calling default no-op implementation of InternalState#forceUpdate");
6230
+ };
6231
+ InternalState.prototype.asyncUpdate = function () {
6232
+ var _this = this;
6233
+ return new Promise(function (resolve) {
6234
+ _this.asyncResolveFns.add(resolve);
6235
+ _this.optionsToIgnoreOnce.add(_this.watchQueryOptions);
6236
+ _this.forceUpdate();
6237
+ });
6238
+ };
6239
+ InternalState.prototype.useQuery = function (options) {
6240
+ var _this = this;
6241
+ this.renderPromises = React.useContext(getApolloContext()).renderPromises;
6242
+ this.useOptions(options);
6243
+ var obsQuery = this.useObservableQuery();
6244
+ var result = useSyncExternalStore(React.useCallback(function () {
6245
+ if (_this.renderPromises) {
6246
+ return function () { };
6247
+ }
6248
+ var onNext = function () {
6249
+ var previousResult = _this.result;
6250
+ var result = obsQuery.getCurrentResult();
6251
+ if (previousResult &&
6252
+ previousResult.loading === result.loading &&
6253
+ previousResult.networkStatus === result.networkStatus &&
6254
+ equality.equal(previousResult.data, result.data)) {
6255
+ return;
6256
+ }
6257
+ _this.setResult(result);
6258
+ };
6259
+ var onError = function (error) {
6260
+ var last = obsQuery["last"];
6261
+ subscription.unsubscribe();
6262
+ try {
6263
+ obsQuery.resetLastResults();
6264
+ subscription = obsQuery.subscribe(onNext, onError);
6265
+ }
6266
+ finally {
6267
+ obsQuery["last"] = last;
6268
+ }
6269
+ if (!hasOwnProperty.call(error, 'graphQLErrors')) {
6270
+ throw error;
6271
+ }
6272
+ var previousResult = _this.result;
6273
+ if (!previousResult ||
6274
+ (previousResult && previousResult.loading) ||
6275
+ !equality.equal(error, previousResult.error)) {
6276
+ _this.setResult({
6277
+ data: (previousResult && previousResult.data),
6278
+ error: error,
6279
+ loading: false,
6280
+ networkStatus: exports.NetworkStatus.error,
6096
6281
  });
6097
- }); },
6098
- }, function () { return null; });
6282
+ }
6283
+ };
6284
+ var subscription = obsQuery.subscribe(onNext, onError);
6285
+ return function () { return subscription.unsubscribe(); };
6286
+ }, [
6287
+ obsQuery,
6288
+ this.renderPromises,
6289
+ this.client.disableNetworkFetches,
6290
+ ]), function () { return _this.getCurrentResult(); }, function () { return _this.getCurrentResult(); });
6291
+ this.unsafeHandlePartialRefetch(result);
6292
+ var queryResult = this.toQueryResult(result);
6293
+ if (!queryResult.loading && this.asyncResolveFns.size) {
6294
+ this.asyncResolveFns.forEach(function (resolve) { return resolve(queryResult); });
6295
+ this.asyncResolveFns.clear();
6296
+ }
6297
+ return queryResult;
6298
+ };
6299
+ InternalState.prototype.useOptions = function (options) {
6300
+ var _a;
6301
+ var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
6302
+ var currentWatchQueryOptions = this.watchQueryOptions;
6303
+ if (this.optionsToIgnoreOnce.has(currentWatchQueryOptions) ||
6304
+ !equality.equal(watchQueryOptions, currentWatchQueryOptions)) {
6305
+ this.watchQueryOptions = watchQueryOptions;
6306
+ if (currentWatchQueryOptions && this.observable) {
6307
+ this.optionsToIgnoreOnce.delete(currentWatchQueryOptions);
6308
+ this.observable.reobserve(this.getObsQueryOptions());
6309
+ this.previousData = ((_a = this.result) === null || _a === void 0 ? void 0 : _a.data) || this.previousData;
6310
+ this.result = void 0;
6311
+ }
6312
+ }
6313
+ this.onCompleted = options.onCompleted || InternalState.prototype.onCompleted;
6314
+ this.onError = options.onError || InternalState.prototype.onError;
6315
+ if ((this.renderPromises || this.client.disableNetworkFetches) &&
6316
+ this.queryHookOptions.ssr === false &&
6317
+ !this.queryHookOptions.skip) {
6318
+ this.result = this.ssrDisabledResult;
6319
+ }
6320
+ else if (this.queryHookOptions.skip ||
6321
+ this.watchQueryOptions.fetchPolicy === 'standby') {
6322
+ this.result = this.skipStandbyResult;
6323
+ }
6324
+ else if (this.result === this.ssrDisabledResult ||
6325
+ this.result === this.skipStandbyResult) {
6326
+ this.result = void 0;
6327
+ }
6328
+ };
6329
+ InternalState.prototype.getObsQueryOptions = function () {
6330
+ var toMerge = [];
6331
+ var globalDefaults = this.client.defaultOptions.watchQuery;
6332
+ if (globalDefaults)
6333
+ toMerge.push(globalDefaults);
6334
+ if (this.queryHookOptions.defaultOptions) {
6335
+ toMerge.push(this.queryHookOptions.defaultOptions);
6336
+ }
6337
+ toMerge.push(compact(this.observable && this.observable.options, this.watchQueryOptions));
6338
+ return toMerge.reduce(mergeOptions);
6339
+ };
6340
+ InternalState.prototype.createWatchQueryOptions = function (_a) {
6341
+ var _b;
6342
+ if (_a === void 0) { _a = {}; }
6343
+ 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"]);
6344
+ var watchQueryOptions = Object.assign(otherOptions, { query: this.query });
6345
+ if (this.renderPromises &&
6346
+ (watchQueryOptions.fetchPolicy === 'network-only' ||
6347
+ watchQueryOptions.fetchPolicy === 'cache-and-network')) {
6348
+ watchQueryOptions.fetchPolicy = 'cache-first';
6349
+ }
6350
+ if (!watchQueryOptions.variables) {
6351
+ watchQueryOptions.variables = {};
6352
+ }
6353
+ if (skip) {
6354
+ var _c = watchQueryOptions.fetchPolicy, fetchPolicy = _c === void 0 ? this.getDefaultFetchPolicy() : _c, _d = watchQueryOptions.initialFetchPolicy, initialFetchPolicy = _d === void 0 ? fetchPolicy : _d;
6355
+ Object.assign(watchQueryOptions, {
6356
+ initialFetchPolicy: initialFetchPolicy,
6357
+ fetchPolicy: 'standby',
6358
+ });
6099
6359
  }
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
- }
6360
+ else if (!watchQueryOptions.fetchPolicy) {
6361
+ watchQueryOptions.fetchPolicy =
6362
+ ((_b = this.observable) === null || _b === void 0 ? void 0 : _b.options.initialFetchPolicy) ||
6363
+ this.getDefaultFetchPolicy();
6112
6364
  }
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 () {
6365
+ return watchQueryOptions;
6366
+ };
6367
+ InternalState.prototype.getDefaultFetchPolicy = function () {
6124
6368
  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
- }
6369
+ return (((_a = this.queryHookOptions.defaultOptions) === null || _a === void 0 ? void 0 : _a.fetchPolicy) ||
6370
+ ((_b = this.client.defaultOptions.watchQuery) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
6371
+ "cache-first");
6372
+ };
6373
+ InternalState.prototype.onCompleted = function (data) { };
6374
+ InternalState.prototype.onError = function (error) { };
6375
+ InternalState.prototype.useObservableQuery = function () {
6376
+ var obsQuery = this.observable =
6377
+ this.renderPromises
6378
+ && this.renderPromises.getSSRObservable(this.watchQueryOptions)
6379
+ || this.observable
6380
+ || this.client.watchQuery(this.getObsQueryOptions());
6381
+ this.obsQueryFields = React.useMemo(function () { return ({
6382
+ refetch: obsQuery.refetch.bind(obsQuery),
6383
+ reobserve: obsQuery.reobserve.bind(obsQuery),
6384
+ fetchMore: obsQuery.fetchMore.bind(obsQuery),
6385
+ updateQuery: obsQuery.updateQuery.bind(obsQuery),
6386
+ startPolling: obsQuery.startPolling.bind(obsQuery),
6387
+ stopPolling: obsQuery.stopPolling.bind(obsQuery),
6388
+ subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
6389
+ }); }, [obsQuery]);
6390
+ var ssrAllowed = !(this.queryHookOptions.ssr === false ||
6391
+ this.queryHookOptions.skip);
6392
+ if (this.renderPromises && ssrAllowed) {
6393
+ this.renderPromises.registerSSRObservable(obsQuery);
6394
+ if (obsQuery.getCurrentResult().loading) {
6395
+ this.renderPromises.addObservableQueryPromise(obsQuery);
6150
6396
  }
6151
6397
  }
6152
- Object.assign(ref.current, { client: client, query: query });
6153
- }, [obsQuery, client, query, options]);
6154
- React.useEffect(function () {
6155
- if (context.renderPromises) {
6156
- return;
6398
+ return obsQuery;
6399
+ };
6400
+ InternalState.prototype.setResult = function (nextResult) {
6401
+ var previousResult = this.result;
6402
+ if (previousResult && previousResult.data) {
6403
+ this.previousData = previousResult.data;
6157
6404
  }
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;
6405
+ this.result = nextResult;
6406
+ this.forceUpdate();
6407
+ this.handleErrorOrCompleted(nextResult);
6408
+ };
6409
+ InternalState.prototype.handleErrorOrCompleted = function (result) {
6410
+ if (!result.loading) {
6411
+ if (result.error) {
6412
+ this.onError(result.error);
6171
6413
  }
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);
6414
+ else if (result.data) {
6415
+ this.onCompleted(result.data);
6175
6416
  }
6176
6417
  }
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
- }
6418
+ };
6419
+ InternalState.prototype.getCurrentResult = function () {
6420
+ if (!this.result) {
6421
+ this.handleErrorOrCompleted(this.result = this.observable.getCurrentResult());
6202
6422
  }
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) &&
6423
+ return this.result;
6424
+ };
6425
+ InternalState.prototype.toQueryResult = function (result) {
6426
+ var queryResult = this.toQueryResultCache.get(result);
6427
+ if (queryResult)
6428
+ return queryResult;
6429
+ var data = result.data; result.partial; var resultWithoutPartial = tslib.__rest(result, ["data", "partial"]);
6430
+ 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: !this.queryHookOptions.skip, previousData: this.previousData }));
6431
+ if (!queryResult.error && isNonEmptyArray(result.errors)) {
6432
+ queryResult.error = new ApolloError({ graphQLErrors: result.errors });
6433
+ }
6434
+ return queryResult;
6435
+ };
6436
+ InternalState.prototype.unsafeHandlePartialRefetch = function (result) {
6437
+ if (result.partial &&
6438
+ this.queryHookOptions.partialRefetch &&
6210
6439
  !result.loading &&
6211
6440
  (!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 () { });
6441
+ this.observable.options.fetchPolicy !== 'cache-only') {
6442
+ Object.assign(result, {
6443
+ loading: true,
6444
+ networkStatus: exports.NetworkStatus.refetch,
6445
+ });
6446
+ this.observable.refetch();
6221
6447
  }
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
- }
6448
+ };
6449
+ return InternalState;
6450
+ }());
6278
6451
 
6279
6452
  var EAGER_METHODS = [
6280
6453
  'refetch',
6454
+ 'reobserve',
6281
6455
  'fetchMore',
6282
6456
  'updateQuery',
6283
6457
  'startPolling',
6284
6458
  'subscribeToMore',
6285
6459
  ];
6286
6460
  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
- }
6461
+ var internalState = useInternalState(useApolloClient(options && options.client), query);
6462
+ var execOptionsRef = React.useRef();
6463
+ var merged = execOptionsRef.current
6464
+ ? mergeOptions(options, execOptionsRef.current)
6465
+ : options;
6466
+ var useQueryResult = internalState.useQuery(tslib.__assign(tslib.__assign({}, merged), { skip: !execOptionsRef.current }));
6467
+ var initialFetchPolicy = useQueryResult.observable.options.initialFetchPolicy ||
6468
+ internalState.getDefaultFetchPolicy();
6469
+ var result = Object.assign(useQueryResult, {
6470
+ called: !!execOptionsRef.current,
6471
+ });
6294
6472
  var eagerMethods = React.useMemo(function () {
6295
6473
  var eagerMethods = {};
6296
6474
  var _loop_1 = function (key) {
6297
6475
  var method = result[key];
6298
6476
  eagerMethods[key] = function () {
6299
- var args = [];
6300
- for (var _i = 0; _i < arguments.length; _i++) {
6301
- args[_i] = arguments[_i];
6477
+ if (!execOptionsRef.current) {
6478
+ execOptionsRef.current = Object.create(null);
6479
+ internalState.forceUpdate();
6302
6480
  }
6303
- setExecution(function (execution) { return (tslib.__assign(tslib.__assign({}, execution), { called: true })); });
6304
- return method.apply(void 0, args);
6481
+ return method.apply(this, arguments);
6305
6482
  };
6306
6483
  };
6307
6484
  for (var _i = 0, EAGER_METHODS_1 = EAGER_METHODS; _i < EAGER_METHODS_1.length; _i++) {
@@ -6310,15 +6487,14 @@ function useLazyQuery(query, options) {
6310
6487
  }
6311
6488
  return eagerMethods;
6312
6489
  }, []);
6313
- result.error = result.error || void 0;
6314
6490
  Object.assign(result, eagerMethods);
6315
6491
  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
- });
6492
+ execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
6493
+ fetchPolicy: initialFetchPolicy,
6494
+ };
6495
+ var promise = internalState
6496
+ .asyncUpdate()
6497
+ .then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
6322
6498
  promise.catch(function () { });
6323
6499
  return promise;
6324
6500
  }, []);
@@ -6360,7 +6536,7 @@ function useMutation(mutation, options) {
6360
6536
  var mutationId = ++ref.current.mutationId;
6361
6537
  var clientOptions = mergeOptions(baseOptions, executeOptions);
6362
6538
  return client.mutate(clientOptions).then(function (response) {
6363
- var _a, _b;
6539
+ var _a, _b, _c;
6364
6540
  var data = response.data, errors = response.errors;
6365
6541
  var error = errors && errors.length > 0
6366
6542
  ? new ApolloError({ graphQLErrors: errors })
@@ -6378,11 +6554,11 @@ function useMutation(mutation, options) {
6378
6554
  setResult(ref.current.result = result_1);
6379
6555
  }
6380
6556
  }
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);
6557
+ (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onCompleted) === null || _b === void 0 ? void 0 : _b.call(_a, response.data);
6558
+ (_c = executeOptions.onCompleted) === null || _c === void 0 ? void 0 : _c.call(executeOptions, response.data);
6383
6559
  return response;
6384
6560
  }).catch(function (error) {
6385
- var _a, _b;
6561
+ var _a, _b, _c, _d;
6386
6562
  if (mutationId === ref.current.mutationId &&
6387
6563
  ref.current.isMounted) {
6388
6564
  var result_2 = {
@@ -6396,9 +6572,9 @@ function useMutation(mutation, options) {
6396
6572
  setResult(ref.current.result = result_2);
6397
6573
  }
6398
6574
  }
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);
6575
+ if (((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) || clientOptions.onError) {
6576
+ (_c = (_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.onError) === null || _c === void 0 ? void 0 : _c.call(_b, error);
6577
+ (_d = executeOptions.onError) === null || _d === void 0 ? void 0 : _d.call(executeOptions, error);
6402
6578
  return { data: void 0, errors: error };
6403
6579
  }
6404
6580
  throw error;
@@ -6407,9 +6583,12 @@ function useMutation(mutation, options) {
6407
6583
  var reset = React.useCallback(function () {
6408
6584
  setResult({ called: false, loading: false, client: client });
6409
6585
  }, []);
6410
- React.useEffect(function () { return function () {
6411
- ref.current.isMounted = false;
6412
- }; }, []);
6586
+ React.useEffect(function () {
6587
+ ref.current.isMounted = true;
6588
+ return function () {
6589
+ ref.current.isMounted = false;
6590
+ };
6591
+ }, []);
6413
6592
  return [execute, tslib.__assign({ reset: reset }, result)];
6414
6593
  }
6415
6594
 
@@ -6433,6 +6612,12 @@ function useSubscription(subscription, options) {
6433
6612
  context: options === null || options === void 0 ? void 0 : options.context,
6434
6613
  });
6435
6614
  }), observable = _b[0], setObservable = _b[1];
6615
+ var canResetObservableRef = React.useRef(false);
6616
+ React.useEffect(function () {
6617
+ return function () {
6618
+ canResetObservableRef.current = true;
6619
+ };
6620
+ }, []);
6436
6621
  var ref = React.useRef({ client: client, subscription: subscription, options: options });
6437
6622
  React.useEffect(function () {
6438
6623
  var _a, _b, _c, _d;
@@ -6441,7 +6626,7 @@ function useSubscription(subscription, options) {
6441
6626
  shouldResubscribe = !!shouldResubscribe(options);
6442
6627
  }
6443
6628
  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)) {
6629
+ 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
6630
  setResult({
6446
6631
  loading: false,
6447
6632
  data: void 0,
@@ -6449,13 +6634,16 @@ function useSubscription(subscription, options) {
6449
6634
  variables: options === null || options === void 0 ? void 0 : options.variables,
6450
6635
  });
6451
6636
  setObservable(null);
6637
+ canResetObservableRef.current = false;
6452
6638
  }
6453
6639
  }
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))) {
6640
+ else if ((shouldResubscribe !== false &&
6641
+ (client !== ref.current.client ||
6642
+ subscription !== ref.current.subscription ||
6643
+ (options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
6644
+ !(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
6645
+ !equality.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) ||
6646
+ canResetObservableRef.current) {
6459
6647
  setResult({
6460
6648
  loading: true,
6461
6649
  data: void 0,
@@ -6468,9 +6656,10 @@ function useSubscription(subscription, options) {
6468
6656
  fetchPolicy: options === null || options === void 0 ? void 0 : options.fetchPolicy,
6469
6657
  context: options === null || options === void 0 ? void 0 : options.context,
6470
6658
  }));
6659
+ canResetObservableRef.current = false;
6471
6660
  }
6472
6661
  Object.assign(ref.current, { client: client, subscription: subscription, options: options });
6473
- }, [client, subscription, options]);
6662
+ }, [client, subscription, options, canResetObservableRef.current]);
6474
6663
  React.useEffect(function () {
6475
6664
  if (!observable) {
6476
6665
  return;
@@ -6542,7 +6731,6 @@ exports.HttpLink = HttpLink;
6542
6731
  exports.InMemoryCache = InMemoryCache;
6543
6732
  exports.MissingFieldError = MissingFieldError;
6544
6733
  exports.ObservableQuery = ObservableQuery;
6545
- exports.applyNextFetchPolicy = applyNextFetchPolicy;
6546
6734
  exports.checkFetcher = checkFetcher;
6547
6735
  exports.concat = concat;
6548
6736
  exports.createHttpLink = createHttpLink;