@apollo/client 3.5.10 → 3.6.4

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 (144) hide show
  1. package/LICENSE +1 -1
  2. package/apollo-client.cjs +509 -341
  3. package/apollo-client.cjs.map +1 -1
  4. package/apollo-client.min.cjs +1 -1
  5. package/cache/cache.cjs.native.js +2289 -0
  6. package/core/ApolloClient.d.ts +2 -3
  7. package/core/ApolloClient.d.ts.map +1 -1
  8. package/core/ApolloClient.js +4 -8
  9. package/core/ApolloClient.js.map +1 -1
  10. package/core/ObservableQuery.d.ts +10 -4
  11. package/core/ObservableQuery.d.ts.map +1 -1
  12. package/core/ObservableQuery.js +97 -45
  13. package/core/ObservableQuery.js.map +1 -1
  14. package/core/QueryInfo.d.ts.map +1 -1
  15. package/core/QueryInfo.js +4 -2
  16. package/core/QueryInfo.js.map +1 -1
  17. package/core/QueryManager.d.ts +5 -2
  18. package/core/QueryManager.d.ts.map +1 -1
  19. package/core/QueryManager.js +29 -23
  20. package/core/QueryManager.js.map +1 -1
  21. package/core/core.cjs +138 -85
  22. package/core/core.cjs.map +1 -1
  23. package/core/core.cjs.native.js +2141 -0
  24. package/core/index.d.ts +1 -1
  25. package/core/index.d.ts.map +1 -1
  26. package/core/index.js +1 -1
  27. package/core/index.js.map +1 -1
  28. package/core/watchQueryOptions.d.ts +9 -1
  29. package/core/watchQueryOptions.d.ts.map +1 -1
  30. package/core/watchQueryOptions.js.map +1 -1
  31. package/errors/errors.cjs.native.js +48 -0
  32. package/invariantErrorCodes.js +1 -1
  33. package/link/batch/batch.cjs +47 -37
  34. package/link/batch/batch.cjs.map +1 -1
  35. package/link/batch/batch.cjs.native.js +161 -0
  36. package/link/batch/batching.d.ts +2 -6
  37. package/link/batch/batching.d.ts.map +1 -1
  38. package/link/batch/batching.js +47 -37
  39. package/link/batch/batching.js.map +1 -1
  40. package/link/batch-http/batch-http.cjs.native.js +127 -0
  41. package/link/context/context.cjs.native.js +38 -0
  42. package/link/core/core.cjs.native.js +121 -0
  43. package/link/error/error.cjs.native.js +90 -0
  44. package/link/http/http.cjs.native.js +320 -0
  45. package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
  46. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  47. package/link/persisted-queries/index.d.ts +2 -1
  48. package/link/persisted-queries/index.d.ts.map +1 -1
  49. package/link/persisted-queries/index.js +26 -13
  50. package/link/persisted-queries/index.js.map +1 -1
  51. package/link/persisted-queries/persisted-queries.cjs +25 -12
  52. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  53. package/link/persisted-queries/persisted-queries.cjs.native.js +174 -0
  54. package/link/retry/retry.cjs.native.js +170 -0
  55. package/link/schema/schema.cjs.native.js +56 -0
  56. package/link/subscriptions/subscriptions.cjs.native.js +45 -0
  57. package/link/utils/utils.cjs.native.js +115 -0
  58. package/link/ws/ws.cjs.native.js +28 -0
  59. package/main.cjs.native.js +16 -0
  60. package/package.json +28 -26
  61. package/react/components/components.cjs.native.js +79 -0
  62. package/react/context/ApolloConsumer.js +2 -2
  63. package/react/context/ApolloProvider.js +2 -2
  64. package/react/context/context.cjs +4 -4
  65. package/react/context/context.cjs.map +1 -1
  66. package/react/context/context.cjs.native.js +67 -0
  67. package/react/hoc/hoc.cjs.native.js +325 -0
  68. package/react/hooks/hooks.cjs +351 -247
  69. package/react/hooks/hooks.cjs.map +1 -1
  70. package/react/hooks/hooks.cjs.native.js +604 -0
  71. package/react/hooks/index.d.ts +1 -1
  72. package/react/hooks/index.d.ts.map +1 -1
  73. package/react/hooks/index.js +1 -1
  74. package/react/hooks/index.js.map +1 -1
  75. package/react/hooks/useLazyQuery.d.ts +2 -2
  76. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  77. package/react/hooks/useLazyQuery.js +22 -21
  78. package/react/hooks/useLazyQuery.js.map +1 -1
  79. package/react/hooks/useMutation.d.ts.map +1 -1
  80. package/react/hooks/useMutation.js +6 -3
  81. package/react/hooks/useMutation.js.map +1 -1
  82. package/react/hooks/useQuery.d.ts +36 -2
  83. package/react/hooks/useQuery.d.ts.map +1 -1
  84. package/react/hooks/useQuery.js +238 -204
  85. package/react/hooks/useQuery.js.map +1 -1
  86. package/react/hooks/useSubscription.d.ts.map +1 -1
  87. package/react/hooks/useSubscription.js +17 -7
  88. package/react/hooks/useSubscription.js.map +1 -1
  89. package/react/hooks/useSyncExternalStore.d.ts +4 -0
  90. package/react/hooks/useSyncExternalStore.d.ts.map +1 -0
  91. package/react/hooks/useSyncExternalStore.js +48 -0
  92. package/react/hooks/useSyncExternalStore.js.map +1 -0
  93. package/react/parser/index.d.ts.map +1 -1
  94. package/react/parser/index.js +24 -10
  95. package/react/parser/index.js.map +1 -1
  96. package/react/parser/parser.cjs +24 -10
  97. package/react/parser/parser.cjs.map +1 -1
  98. package/react/parser/parser.cjs.native.js +103 -0
  99. package/react/react.cjs.native.js +22 -0
  100. package/react/ssr/RenderPromises.d.ts +3 -2
  101. package/react/ssr/RenderPromises.d.ts.map +1 -1
  102. package/react/ssr/RenderPromises.js +25 -3
  103. package/react/ssr/RenderPromises.js.map +1 -1
  104. package/react/ssr/ssr.cjs +25 -3
  105. package/react/ssr/ssr.cjs.map +1 -1
  106. package/react/ssr/ssr.cjs.native.js +150 -0
  107. package/react/types/types.d.ts +10 -11
  108. package/react/types/types.d.ts.map +1 -1
  109. package/react/types/types.js.map +1 -1
  110. package/testing/core/core.cjs.native.js +288 -0
  111. package/testing/core/mocking/mockFetch.js +1 -1
  112. package/testing/core/mocking/mockFetch.js.map +1 -1
  113. package/testing/core/mocking/mockQueryManager.js +1 -1
  114. package/testing/core/mocking/mockWatchQuery.js +1 -1
  115. package/testing/core/wrap.js +1 -1
  116. package/testing/testing.cjs.native.js +58 -0
  117. package/utilities/common/canUse.d.ts +2 -0
  118. package/utilities/common/canUse.d.ts.map +1 -1
  119. package/utilities/common/canUse.js +6 -2
  120. package/utilities/common/canUse.js.map +1 -1
  121. package/utilities/common/mergeOptions.d.ts +5 -0
  122. package/utilities/common/mergeOptions.d.ts.map +1 -0
  123. package/utilities/common/mergeOptions.js +8 -0
  124. package/utilities/common/mergeOptions.js.map +1 -0
  125. package/utilities/globals/global.js +1 -2
  126. package/utilities/globals/globals.cjs.native.js +56 -0
  127. package/utilities/graphql/transform.d.ts +2 -2
  128. package/utilities/graphql/transform.d.ts.map +1 -1
  129. package/utilities/graphql/transform.js +1 -1
  130. package/utilities/graphql/transform.js.map +1 -1
  131. package/utilities/index.d.ts +1 -0
  132. package/utilities/index.d.ts.map +1 -1
  133. package/utilities/index.js +1 -0
  134. package/utilities/index.js.map +1 -1
  135. package/utilities/observables/Concast.d.ts.map +1 -1
  136. package/utilities/observables/Concast.js +5 -2
  137. package/utilities/observables/Concast.js.map +1 -1
  138. package/utilities/policies/pagination.d.ts.map +1 -1
  139. package/utilities/policies/pagination.js +9 -7
  140. package/utilities/policies/pagination.js.map +1 -1
  141. package/utilities/utilities.cjs +29 -12
  142. package/utilities/utilities.cjs.map +1 -1
  143. package/utilities/utilities.cjs.native.js +1284 -0
  144. 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));
@@ -898,11 +898,14 @@ function asyncMap(observable, mapFn, catchFn) {
898
898
  });
899
899
  }
900
900
 
901
- var canUseWeakMap = typeof WeakMap === 'function' && !(typeof navigator === 'object' &&
902
- navigator.product === 'ReactNative');
901
+ var canUseWeakMap = typeof WeakMap === 'function' &&
902
+ maybe(function () { return navigator.product; }) !== 'ReactNative';
903
903
  var canUseWeakSet = typeof WeakSet === 'function';
904
904
  var canUseSymbol = typeof Symbol === 'function' &&
905
905
  typeof Symbol.for === 'function';
906
+ var canUseDOM = typeof maybe(function () { return window.document.createElement; }) === "function";
907
+ var usingJSDOM = maybe(function () { return navigator.userAgent.indexOf("jsdom") >= 0; }) || false;
908
+ var canUseLayoutEffect = canUseDOM && !usingJSDOM;
906
909
 
907
910
  function fixObservableSubclass(subclass) {
908
911
  function set(key) {
@@ -950,9 +953,12 @@ var Concast = (function (_super) {
950
953
  }
951
954
  },
952
955
  complete: function () {
953
- if (_this.sub !== null) {
956
+ var sub = _this.sub;
957
+ if (sub !== null) {
954
958
  var value = _this.sources.shift();
955
959
  if (!value) {
960
+ if (sub)
961
+ setTimeout(function () { return sub.unsubscribe(); });
956
962
  _this.sub = null;
957
963
  if (_this.latest &&
958
964
  _this.latest[0] === "next") {
@@ -1020,7 +1026,7 @@ var Concast = (function (_super) {
1020
1026
  if (this.observers.delete(observer) &&
1021
1027
  --this.addCount < 1 &&
1022
1028
  !quietly) {
1023
- this.handlers.error(new Error("Observable cancelled prematurely"));
1029
+ this.handlers.complete();
1024
1030
  }
1025
1031
  };
1026
1032
  Concast.prototype.cleanup = function (callback) {
@@ -1087,6 +1093,12 @@ function stringifyForDisplay(value) {
1087
1093
  }).split(JSON.stringify(undefId)).join("<undefined>");
1088
1094
  }
1089
1095
 
1096
+ function mergeOptions(defaults, options) {
1097
+ return compact(defaults, options, options.variables && {
1098
+ variables: tslib.__assign(tslib.__assign({}, (defaults && defaults.variables)), options.variables),
1099
+ });
1100
+ }
1101
+
1090
1102
  function fromError(errorValue) {
1091
1103
  return new zenObservableTs.Observable(function (observer) {
1092
1104
  observer.error(errorValue);
@@ -1291,9 +1303,9 @@ var concat = ApolloLink.concat;
1291
1303
 
1292
1304
  var execute = ApolloLink.execute;
1293
1305
 
1294
- var version = '3.5.10';
1306
+ var version = '3.6.4';
1295
1307
 
1296
- var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
1308
+ var hasOwnProperty$3 = Object.prototype.hasOwnProperty;
1297
1309
  function parseAndCheckHttpResponse(operations) {
1298
1310
  return function (response) { return response
1299
1311
  .text()
@@ -1315,8 +1327,8 @@ function parseAndCheckHttpResponse(operations) {
1315
1327
  throwServerError(response, result, "Response not successful: Received status code ".concat(response.status));
1316
1328
  }
1317
1329
  if (!Array.isArray(result) &&
1318
- !hasOwnProperty$2.call(result, 'data') &&
1319
- !hasOwnProperty$2.call(result, 'errors')) {
1330
+ !hasOwnProperty$3.call(result, 'data') &&
1331
+ !hasOwnProperty$3.call(result, 'errors')) {
1320
1332
  throwServerError(response, result, "Server response was missing for query '".concat(Array.isArray(operations)
1321
1333
  ? operations.map(function (op) { return op.operationName; })
1322
1334
  : operations.operationName, "'."));
@@ -3905,8 +3917,7 @@ function isNetworkRequestInFlight(networkStatus) {
3905
3917
  return networkStatus ? networkStatus < 7 : false;
3906
3918
  }
3907
3919
 
3908
- var assign = Object.assign, hasOwnProperty$1 = Object.hasOwnProperty;
3909
- var warnedAboutUpdateQuery = false;
3920
+ var assign = Object.assign, hasOwnProperty$2 = Object.hasOwnProperty;
3910
3921
  var ObservableQuery = (function (_super) {
3911
3922
  tslib.__extends(ObservableQuery, _super);
3912
3923
  function ObservableQuery(_a) {
@@ -3939,16 +3950,24 @@ var ObservableQuery = (function (_super) {
3939
3950
  }) || this;
3940
3951
  _this.observers = new Set();
3941
3952
  _this.subscriptions = new Set();
3953
+ _this.queryInfo = queryInfo;
3954
+ _this.queryManager = queryManager;
3942
3955
  _this.isTornDown = false;
3943
- _this.options = options;
3956
+ var _b = queryManager.defaultOptions.watchQuery, _c = _b === void 0 ? {} : _b, _d = _c.fetchPolicy, defaultFetchPolicy = _d === void 0 ? "cache-first" : _d;
3957
+ var _e = options.fetchPolicy, fetchPolicy = _e === void 0 ? defaultFetchPolicy : _e, _f = options.initialFetchPolicy, initialFetchPolicy = _f === void 0 ? (fetchPolicy === "standby" ? defaultFetchPolicy : fetchPolicy) : _f;
3958
+ _this.options = tslib.__assign(tslib.__assign({}, options), { initialFetchPolicy: initialFetchPolicy, fetchPolicy: fetchPolicy });
3944
3959
  _this.queryId = queryInfo.queryId || queryManager.generateQueryId();
3945
- var opDef = getOperationDefinition(options.query);
3960
+ var opDef = getOperationDefinition(_this.query);
3946
3961
  _this.queryName = opDef && opDef.name && opDef.name.value;
3947
- _this.initialFetchPolicy = options.fetchPolicy || "cache-first";
3948
- _this.queryManager = queryManager;
3949
- _this.queryInfo = queryInfo;
3950
3962
  return _this;
3951
3963
  }
3964
+ Object.defineProperty(ObservableQuery.prototype, "query", {
3965
+ get: function () {
3966
+ return this.queryManager.transform(this.options.query).document;
3967
+ },
3968
+ enumerable: false,
3969
+ configurable: true
3970
+ });
3952
3971
  Object.defineProperty(ObservableQuery.prototype, "variables", {
3953
3972
  get: function () {
3954
3973
  return this.options.variables;
@@ -4061,8 +4080,8 @@ var ObservableQuery = (function (_super) {
4061
4080
  else {
4062
4081
  reobserveOptions.fetchPolicy = 'network-only';
4063
4082
  }
4064
- if (__DEV__ && variables && hasOwnProperty$1.call(variables, "variables")) {
4065
- var queryDef = getQueryDefinition(this.options.query);
4083
+ if (__DEV__ && variables && hasOwnProperty$2.call(variables, "variables")) {
4084
+ var queryDef = getQueryDefinition(this.query);
4066
4085
  var vars = queryDef.variableDefinitions;
4067
4086
  if (!vars || !vars.some(function (v) { return v.variable.name.value === "variables"; })) {
4068
4087
  __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 +4095,51 @@ var ObservableQuery = (function (_super) {
4076
4095
  };
4077
4096
  ObservableQuery.prototype.fetchMore = function (fetchMoreOptions) {
4078
4097
  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" });
4098
+ 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
4099
  var qid = this.queryManager.generateQueryId();
4100
+ var queryInfo = this.queryInfo;
4101
+ var originalNetworkStatus = queryInfo.networkStatus;
4102
+ queryInfo.networkStatus = exports.NetworkStatus.fetchMore;
4081
4103
  if (combinedOptions.notifyOnNetworkStatusChange) {
4082
- this.queryInfo.networkStatus = exports.NetworkStatus.fetchMore;
4083
4104
  this.observe();
4084
4105
  }
4106
+ var updatedQuerySet = new Set();
4085
4107
  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
- }
4108
+ _this.queryManager.removeQuery(qid);
4109
+ if (queryInfo.networkStatus === exports.NetworkStatus.fetchMore) {
4110
+ queryInfo.networkStatus = originalNetworkStatus;
4111
+ }
4112
+ _this.queryManager.cache.batch({
4113
+ update: function (cache) {
4114
+ var updateQuery = fetchMoreOptions.updateQuery;
4115
+ if (updateQuery) {
4116
+ cache.updateQuery({
4117
+ query: _this.query,
4118
+ variables: _this.variables,
4119
+ returnPartialData: true,
4120
+ optimistic: false,
4121
+ }, function (previous) { return updateQuery(previous, {
4122
+ fetchMoreResult: fetchMoreResult.data,
4123
+ variables: combinedOptions.variables,
4124
+ }); });
4125
+ }
4126
+ else {
4127
+ cache.writeQuery({
4128
+ query: combinedOptions.query,
4129
+ variables: combinedOptions.variables,
4130
+ data: fetchMoreResult.data,
4131
+ });
4132
+ }
4133
+ },
4134
+ onWatchUpdated: function (watch) {
4135
+ updatedQuerySet.add(watch.query);
4136
+ },
4137
+ });
4106
4138
  return fetchMoreResult;
4107
4139
  }).finally(function () {
4108
- _this.queryManager.stopQuery(qid);
4109
- _this.reobserve();
4140
+ if (!updatedQuerySet.has(_this.query)) {
4141
+ reobserveCacheFirst(_this);
4142
+ }
4110
4143
  });
4111
4144
  };
4112
4145
  ObservableQuery.prototype.subscribeToMore = function (options) {
@@ -4159,7 +4192,7 @@ var ObservableQuery = (function (_super) {
4159
4192
  return Promise.resolve();
4160
4193
  }
4161
4194
  return this.reobserve({
4162
- fetchPolicy: this.initialFetchPolicy,
4195
+ fetchPolicy: this.options.initialFetchPolicy,
4163
4196
  variables: variables,
4164
4197
  }, exports.NetworkStatus.setVariables);
4165
4198
  };
@@ -4191,6 +4224,26 @@ var ObservableQuery = (function (_super) {
4191
4224
  this.options.pollInterval = 0;
4192
4225
  this.updatePolling();
4193
4226
  };
4227
+ ObservableQuery.prototype.applyNextFetchPolicy = function (reason, options) {
4228
+ if (options.nextFetchPolicy) {
4229
+ var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a, _b = options.initialFetchPolicy, initialFetchPolicy = _b === void 0 ? fetchPolicy : _b;
4230
+ if (typeof options.nextFetchPolicy === "function") {
4231
+ options.fetchPolicy = options.nextFetchPolicy(fetchPolicy, {
4232
+ reason: reason,
4233
+ options: options,
4234
+ observable: this,
4235
+ initialFetchPolicy: initialFetchPolicy,
4236
+ });
4237
+ }
4238
+ else if (reason === "variables-changed") {
4239
+ options.fetchPolicy = initialFetchPolicy;
4240
+ }
4241
+ else {
4242
+ options.fetchPolicy = options.nextFetchPolicy;
4243
+ }
4244
+ }
4245
+ return options.fetchPolicy;
4246
+ };
4194
4247
  ObservableQuery.prototype.fetch = function (options, newNetworkStatus) {
4195
4248
  this.queryManager.setObservableQuery(this);
4196
4249
  return this.queryManager.fetchQueryObservable(this.queryId, options, newNetworkStatus);
@@ -4253,16 +4306,18 @@ var ObservableQuery = (function (_super) {
4253
4306
  newNetworkStatus === exports.NetworkStatus.fetchMore ||
4254
4307
  newNetworkStatus === exports.NetworkStatus.poll;
4255
4308
  var oldVariables = this.options.variables;
4309
+ var oldFetchPolicy = this.options.fetchPolicy;
4310
+ var mergedOptions = mergeOptions(this.options, newOptions || {});
4256
4311
  var options = useDisposableConcast
4257
- ? compact(this.options, newOptions)
4258
- : assign(this.options, compact(newOptions));
4312
+ ? mergedOptions
4313
+ : assign(this.options, mergedOptions);
4259
4314
  if (!useDisposableConcast) {
4260
4315
  this.updatePolling();
4261
4316
  if (newOptions &&
4262
4317
  newOptions.variables &&
4263
- !newOptions.fetchPolicy &&
4264
- !equality.equal(newOptions.variables, oldVariables)) {
4265
- options.fetchPolicy = this.initialFetchPolicy;
4318
+ !equality.equal(newOptions.variables, oldVariables) &&
4319
+ (!newOptions.fetchPolicy || newOptions.fetchPolicy === oldFetchPolicy)) {
4320
+ this.applyNextFetchPolicy("variables-changed", options);
4266
4321
  if (newNetworkStatus === void 0) {
4267
4322
  newNetworkStatus = exports.NetworkStatus.setVariables;
4268
4323
  }
@@ -4326,6 +4381,23 @@ var ObservableQuery = (function (_super) {
4326
4381
  return ObservableQuery;
4327
4382
  }(zenObservableTs.Observable));
4328
4383
  fixObservableSubclass(ObservableQuery);
4384
+ function reobserveCacheFirst(obsQuery) {
4385
+ var _a = obsQuery.options, fetchPolicy = _a.fetchPolicy, nextFetchPolicy = _a.nextFetchPolicy;
4386
+ if (fetchPolicy === "cache-and-network" ||
4387
+ fetchPolicy === "network-only") {
4388
+ return obsQuery.reobserve({
4389
+ fetchPolicy: "cache-first",
4390
+ nextFetchPolicy: function () {
4391
+ this.nextFetchPolicy = nextFetchPolicy;
4392
+ if (typeof nextFetchPolicy === "function") {
4393
+ return nextFetchPolicy.apply(this, arguments);
4394
+ }
4395
+ return fetchPolicy;
4396
+ },
4397
+ });
4398
+ }
4399
+ return obsQuery.reobserve();
4400
+ }
4329
4401
  function defaultSubscriptionObserverErrorCallback(error) {
4330
4402
  __DEV__ && tsInvariant.invariant.error('Unhandled error', error.message, error.stack);
4331
4403
  }
@@ -4334,14 +4406,6 @@ function logMissingFieldErrors(missing) {
4334
4406
  __DEV__ && tsInvariant.invariant.debug("Missing cache result fields: ".concat(JSON.stringify(missing)), missing);
4335
4407
  }
4336
4408
  }
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
4409
 
4346
4410
  var LocalState = (function () {
4347
4411
  function LocalState(_a) {
@@ -4724,11 +4788,12 @@ var QueryInfo = (function () {
4724
4788
  if (oq) {
4725
4789
  oq["queryInfo"] = this;
4726
4790
  this.listeners.add(this.oqListener = function () {
4727
- if (_this.getDiff().fromOptimisticTransaction) {
4791
+ var diff = _this.getDiff();
4792
+ if (diff.fromOptimisticTransaction) {
4728
4793
  oq["observe"]();
4729
4794
  }
4730
4795
  else {
4731
- oq.reobserve();
4796
+ reobserveCacheFirst(oq);
4732
4797
  }
4733
4798
  });
4734
4799
  }
@@ -4870,10 +4935,10 @@ function shouldWriteResult(result, errorPolicy) {
4870
4935
  return writeWithErrors;
4871
4936
  }
4872
4937
 
4873
- var hasOwnProperty = Object.prototype.hasOwnProperty;
4938
+ var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
4874
4939
  var QueryManager = (function () {
4875
4940
  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;
4941
+ 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
4942
  this.clientAwareness = {};
4878
4943
  this.queries = new Map();
4879
4944
  this.fetchCancelFns = new Map();
@@ -4884,6 +4949,7 @@ var QueryManager = (function () {
4884
4949
  this.inFlightLinkObservables = new Map();
4885
4950
  this.cache = cache;
4886
4951
  this.link = link;
4952
+ this.defaultOptions = defaultOptions || Object.create(null);
4887
4953
  this.queryDeduplication = queryDeduplication;
4888
4954
  this.clientAwareness = clientAwareness;
4889
4955
  this.localState = localState || new LocalState({ cache: cache });
@@ -4905,11 +4971,12 @@ var QueryManager = (function () {
4905
4971
  this.fetchCancelFns.clear();
4906
4972
  };
4907
4973
  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;
4974
+ var _b, _c;
4975
+ 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
4976
  return tslib.__awaiter(this, void 0, void 0, function () {
4910
4977
  var mutationId, mutationStoreValue, self;
4911
- return tslib.__generator(this, function (_f) {
4912
- switch (_f.label) {
4978
+ return tslib.__generator(this, function (_h) {
4979
+ switch (_h.label) {
4913
4980
  case 0:
4914
4981
  __DEV__ ? tsInvariant.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : tsInvariant.invariant(mutation, 12);
4915
4982
  __DEV__ ? tsInvariant.invariant(fetchPolicy === 'network-only' ||
@@ -4921,8 +4988,8 @@ var QueryManager = (function () {
4921
4988
  if (!this.transform(mutation).hasClientExports) return [3, 2];
4922
4989
  return [4, this.localState.addExportedVariables(mutation, variables, context)];
4923
4990
  case 1:
4924
- variables = (_f.sent());
4925
- _f.label = 2;
4991
+ variables = (_h.sent());
4992
+ _h.label = 2;
4926
4993
  case 2:
4927
4994
  mutationStoreValue = this.mutationStore &&
4928
4995
  (this.mutationStore[mutationId] = {
@@ -5023,7 +5090,7 @@ var QueryManager = (function () {
5023
5090
  this.queries.forEach(function (_a, queryId) {
5024
5091
  var observableQuery = _a.observableQuery;
5025
5092
  var queryName = observableQuery && observableQuery.queryName;
5026
- if (!queryName || !hasOwnProperty.call(updateQueries_1, queryName)) {
5093
+ if (!queryName || !hasOwnProperty$1.call(updateQueries_1, queryName)) {
5027
5094
  return;
5028
5095
  }
5029
5096
  var updater = updateQueries_1[queryName];
@@ -5189,9 +5256,9 @@ var QueryManager = (function () {
5189
5256
  });
5190
5257
  this.queries.set(observable.queryId, queryInfo);
5191
5258
  queryInfo.init({
5192
- document: options.query,
5259
+ document: observable.query,
5193
5260
  observableQuery: observable,
5194
- variables: options.variables,
5261
+ variables: observable.variables,
5195
5262
  });
5196
5263
  return observable;
5197
5264
  };
@@ -5375,8 +5442,10 @@ var QueryManager = (function () {
5375
5442
  };
5376
5443
  QueryManager.prototype.removeQuery = function (queryId) {
5377
5444
  this.fetchCancelFns.delete(queryId);
5378
- this.getQuery(queryId).stop();
5379
- this.queries.delete(queryId);
5445
+ if (this.queries.has(queryId)) {
5446
+ this.getQuery(queryId).stop();
5447
+ this.queries.delete(queryId);
5448
+ }
5380
5449
  };
5381
5450
  QueryManager.prototype.broadcastQueries = function () {
5382
5451
  if (this.onBroadcast)
@@ -5460,10 +5529,11 @@ var QueryManager = (function () {
5460
5529
  var aqr = {
5461
5530
  data: result.data,
5462
5531
  loading: false,
5463
- networkStatus: queryInfo.networkStatus || exports.NetworkStatus.ready,
5532
+ networkStatus: exports.NetworkStatus.ready,
5464
5533
  };
5465
5534
  if (hasErrors && options.errorPolicy !== "ignore") {
5466
5535
  aqr.errors = result.errors;
5536
+ aqr.networkStatus = exports.NetworkStatus.error;
5467
5537
  }
5468
5538
  return aqr;
5469
5539
  }, function (networkError) {
@@ -5482,7 +5552,8 @@ var QueryManager = (function () {
5482
5552
  var query = this.transform(options.query).document;
5483
5553
  var variables = this.getVariables(query, options.variables);
5484
5554
  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;
5555
+ var defaults = this.defaultOptions.watchQuery;
5556
+ 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
5557
  var normalized = Object.assign({}, options, {
5487
5558
  query: query,
5488
5559
  variables: variables,
@@ -5504,7 +5575,9 @@ var QueryManager = (function () {
5504
5575
  : fromVariables(normalized.variables));
5505
5576
  concast.cleanup(function () {
5506
5577
  _this.fetchCancelFns.delete(queryId);
5507
- applyNextFetchPolicy(options);
5578
+ if (queryInfo.observableQuery) {
5579
+ queryInfo.observableQuery["applyNextFetchPolicy"]("after-fetch", options);
5580
+ }
5508
5581
  });
5509
5582
  return concast;
5510
5583
  };
@@ -5581,7 +5654,7 @@ var QueryManager = (function () {
5581
5654
  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
5655
  var oldNetworkStatus = queryInfo.networkStatus;
5583
5656
  queryInfo.init({
5584
- document: query,
5657
+ document: this.transform(query).document,
5585
5658
  variables: variables,
5586
5659
  networkStatus: networkStatus,
5587
5660
  });
@@ -5610,14 +5683,12 @@ var QueryManager = (function () {
5610
5683
  (networkStatus === exports.NetworkStatus.refetch &&
5611
5684
  refetchWritePolicy !== "merge") ? 1
5612
5685
  : 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
- };
5686
+ var resultsFromLink = function () { return _this.getResultsFromLink(queryInfo, cacheWriteBehavior, {
5687
+ variables: variables,
5688
+ context: context,
5689
+ fetchPolicy: fetchPolicy,
5690
+ errorPolicy: errorPolicy,
5691
+ }); };
5621
5692
  var shouldNotify = notifyOnNetworkStatusChange &&
5622
5693
  typeof oldNetworkStatus === "number" &&
5623
5694
  oldNetworkStatus !== networkStatus &&
@@ -5692,15 +5763,9 @@ var QueryManager = (function () {
5692
5763
  }());
5693
5764
 
5694
5765
  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
5766
  var ApolloClient = (function () {
5701
5767
  function ApolloClient(options) {
5702
5768
  var _this = this;
5703
- this.defaultOptions = {};
5704
5769
  this.resetStoreCallbacks = [];
5705
5770
  this.clearStoreCallbacks = [];
5706
5771
  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 +5786,7 @@ var ApolloClient = (function () {
5721
5786
  this.cache = cache;
5722
5787
  this.disableNetworkFetches = ssrMode || ssrForceFetchDelay > 0;
5723
5788
  this.queryDeduplication = queryDeduplication;
5724
- this.defaultOptions = defaultOptions || {};
5789
+ this.defaultOptions = defaultOptions || Object.create(null);
5725
5790
  this.typeDefs = typeDefs;
5726
5791
  if (ssrForceFetchDelay) {
5727
5792
  setTimeout(function () { return (_this.disableNetworkFetches = false); }, ssrForceFetchDelay);
@@ -5768,6 +5833,7 @@ var ApolloClient = (function () {
5768
5833
  this.queryManager = new QueryManager({
5769
5834
  cache: this.cache,
5770
5835
  link: this.link,
5836
+ defaultOptions: this.defaultOptions,
5771
5837
  queryDeduplication: queryDeduplication,
5772
5838
  ssrMode: ssrMode,
5773
5839
  clientAwareness: {
@@ -5945,17 +6011,17 @@ function getApolloContext() {
5945
6011
 
5946
6012
  var ApolloConsumer = function (props) {
5947
6013
  var ApolloContext = getApolloContext();
5948
- return React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
6014
+ return (React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
5949
6015
  __DEV__ ? tsInvariant.invariant(context && context.client, 'Could not find "client" in the context of ApolloConsumer. ' +
5950
6016
  'Wrap the root component in an <ApolloProvider>.') : tsInvariant.invariant(context && context.client, 25);
5951
6017
  return props.children(context.client);
5952
- });
6018
+ }));
5953
6019
  };
5954
6020
 
5955
6021
  var ApolloProvider = function (_a) {
5956
6022
  var client = _a.client, children = _a.children;
5957
6023
  var ApolloContext = getApolloContext();
5958
- return React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
6024
+ return (React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
5959
6025
  if (context === void 0) { context = {}; }
5960
6026
  if (client && context.client !== client) {
5961
6027
  context = Object.assign({}, context, { client: client });
@@ -5963,7 +6029,7 @@ var ApolloProvider = function (_a) {
5963
6029
  __DEV__ ? tsInvariant.invariant(context.client, 'ApolloProvider was not passed a client instance. Make ' +
5964
6030
  'sure you pass in your client via the "client" prop.') : tsInvariant.invariant(context.client, 26);
5965
6031
  return (React__namespace.createElement(ApolloContext.Provider, { value: context }, children));
5966
- });
6032
+ }));
5967
6033
  };
5968
6034
 
5969
6035
  function useApolloClient(override) {
@@ -5975,6 +6041,51 @@ function useApolloClient(override) {
5975
6041
  return client;
5976
6042
  }
5977
6043
 
6044
+ var didWarnUncachedGetSnapshot = false;
6045
+ var uSESKey = "useSyncExternalStore";
6046
+ var realHook = React__namespace[uSESKey];
6047
+ var useSyncExternalStore = realHook || (function (subscribe, getSnapshot, getServerSnapshot) {
6048
+ var value = getSnapshot();
6049
+ if (__DEV__ &&
6050
+ !didWarnUncachedGetSnapshot &&
6051
+ value !== getSnapshot()) {
6052
+ didWarnUncachedGetSnapshot = true;
6053
+ __DEV__ && tsInvariant.invariant.error('The result of getSnapshot should be cached to avoid an infinite loop');
6054
+ }
6055
+ var _a = React__namespace.useState({ inst: { value: value, getSnapshot: getSnapshot } }), inst = _a[0].inst, forceUpdate = _a[1];
6056
+ if (canUseLayoutEffect) {
6057
+ React__namespace.useLayoutEffect(function () {
6058
+ Object.assign(inst, { value: value, getSnapshot: getSnapshot });
6059
+ if (checkIfSnapshotChanged(inst)) {
6060
+ forceUpdate({ inst: inst });
6061
+ }
6062
+ }, [subscribe, value, getSnapshot]);
6063
+ }
6064
+ else {
6065
+ Object.assign(inst, { value: value, getSnapshot: getSnapshot });
6066
+ }
6067
+ React__namespace.useEffect(function () {
6068
+ if (checkIfSnapshotChanged(inst)) {
6069
+ forceUpdate({ inst: inst });
6070
+ }
6071
+ return subscribe(function handleStoreChange() {
6072
+ if (checkIfSnapshotChanged(inst)) {
6073
+ forceUpdate({ inst: inst });
6074
+ }
6075
+ });
6076
+ }, [subscribe]);
6077
+ return value;
6078
+ });
6079
+ function checkIfSnapshotChanged(_a) {
6080
+ var value = _a.value, getSnapshot = _a.getSnapshot;
6081
+ try {
6082
+ return value !== getSnapshot();
6083
+ }
6084
+ catch (_b) {
6085
+ return true;
6086
+ }
6087
+ }
6088
+
5978
6089
  exports.DocumentType = void 0;
5979
6090
  (function (DocumentType) {
5980
6091
  DocumentType[DocumentType["Query"] = 0] = "Query";
@@ -6005,16 +6116,30 @@ function parser(document) {
6005
6116
  __DEV__ ? tsInvariant.invariant(!!document && !!document.kind, "Argument of ".concat(document, " passed to parser was not a valid GraphQL ") +
6006
6117
  "DocumentNode. You may need to use 'graphql-tag' or another method " +
6007
6118
  "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
- });
6119
+ var fragments = [];
6120
+ var queries = [];
6121
+ var mutations = [];
6122
+ var subscriptions = [];
6123
+ for (var _i = 0, _a = document.definitions; _i < _a.length; _i++) {
6124
+ var x = _a[_i];
6125
+ if (x.kind === 'FragmentDefinition') {
6126
+ fragments.push(x);
6127
+ continue;
6128
+ }
6129
+ if (x.kind === 'OperationDefinition') {
6130
+ switch (x.operation) {
6131
+ case 'query':
6132
+ queries.push(x);
6133
+ break;
6134
+ case 'mutation':
6135
+ mutations.push(x);
6136
+ break;
6137
+ case 'subscription':
6138
+ subscriptions.push(x);
6139
+ break;
6140
+ }
6141
+ }
6142
+ }
6018
6143
  __DEV__ ? tsInvariant.invariant(!fragments.length ||
6019
6144
  (queries.length || mutations.length || subscriptions.length), "Passing only a fragment to 'graphql' is not yet supported. " +
6020
6145
  "You must include a query, subscription or mutation as well") : tsInvariant.invariant(!fragments.length ||
@@ -6054,254 +6179,286 @@ function verifyDocumentType(document, type) {
6054
6179
  "".concat(requiredOperationName, ", but a ").concat(usedOperationName, " was used instead.")) : tsInvariant.invariant(operation.type === type, 34);
6055
6180
  }
6056
6181
 
6182
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
6057
6183
  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
- },
6184
+ if (options === void 0) { options = Object.create(null); }
6185
+ return useInternalState(useApolloClient(options.client), query).useQuery(options);
6186
+ }
6187
+ function useInternalState(client, query) {
6188
+ var stateRef = React.useRef();
6189
+ if (!stateRef.current ||
6190
+ client !== stateRef.current.client ||
6191
+ query !== stateRef.current.query) {
6192
+ stateRef.current = new InternalState(client, query);
6193
+ }
6194
+ var state = stateRef.current;
6195
+ var _a = React.useState(0); _a[0]; var setTick = _a[1];
6196
+ state.forceUpdate = function () {
6197
+ setTick(function (tick) { return tick + 1; });
6198
+ };
6199
+ return state;
6200
+ }
6201
+ var InternalState = (function () {
6202
+ function InternalState(client, query) {
6203
+ this.client = client;
6204
+ this.query = query;
6205
+ this.asyncResolveFns = new Set();
6206
+ this.optionsToIgnoreOnce = new (canUseWeakSet ? WeakSet : Set)();
6207
+ this.ssrDisabledResult = maybeDeepFreeze({
6208
+ loading: true,
6209
+ data: void 0,
6210
+ error: void 0,
6211
+ networkStatus: exports.NetworkStatus.loading,
6212
+ });
6213
+ this.skipStandbyResult = maybeDeepFreeze({
6214
+ loading: false,
6215
+ data: void 0,
6216
+ error: void 0,
6217
+ networkStatus: exports.NetworkStatus.ready,
6218
+ });
6219
+ this.toQueryResultCache = new (canUseWeakMap ? WeakMap : Map)();
6220
+ verifyDocumentType(query, exports.DocumentType.Query);
6221
+ }
6222
+ InternalState.prototype.forceUpdate = function () {
6223
+ __DEV__ && tsInvariant.invariant.warn("Calling default no-op implementation of InternalState#forceUpdate");
6224
+ };
6225
+ InternalState.prototype.asyncUpdate = function () {
6226
+ var _this = this;
6227
+ return new Promise(function (resolve) {
6228
+ _this.asyncResolveFns.add(resolve);
6229
+ _this.optionsToIgnoreOnce.add(_this.watchQueryOptions);
6230
+ _this.forceUpdate();
6231
+ });
6232
+ };
6233
+ InternalState.prototype.useQuery = function (options) {
6234
+ var _this = this;
6235
+ this.renderPromises = React.useContext(getApolloContext()).renderPromises;
6236
+ this.useOptions(options);
6237
+ var obsQuery = this.useObservableQuery();
6238
+ var result = useSyncExternalStore(React.useCallback(function () {
6239
+ if (_this.renderPromises) {
6240
+ return function () { };
6241
+ }
6242
+ var onNext = function () {
6243
+ var previousResult = _this.result;
6244
+ var result = obsQuery.getCurrentResult();
6245
+ if (previousResult &&
6246
+ previousResult.loading === result.loading &&
6247
+ previousResult.networkStatus === result.networkStatus &&
6248
+ equality.equal(previousResult.data, result.data)) {
6249
+ return;
6250
+ }
6251
+ _this.setResult(result);
6252
+ };
6253
+ var onError = function (error) {
6254
+ var last = obsQuery["last"];
6255
+ subscription.unsubscribe();
6256
+ try {
6257
+ obsQuery.resetLastResults();
6258
+ subscription = obsQuery.subscribe(onNext, onError);
6259
+ }
6260
+ finally {
6261
+ obsQuery["last"] = last;
6262
+ }
6263
+ if (!hasOwnProperty.call(error, 'graphQLErrors')) {
6264
+ throw error;
6265
+ }
6266
+ var previousResult = _this.result;
6267
+ if (!previousResult ||
6268
+ (previousResult && previousResult.loading) ||
6269
+ !equality.equal(error, previousResult.error)) {
6270
+ _this.setResult({
6271
+ data: (previousResult && previousResult.data),
6272
+ error: error,
6273
+ loading: false,
6274
+ networkStatus: exports.NetworkStatus.error,
6096
6275
  });
6097
- }); },
6098
- }, function () { return null; });
6276
+ }
6277
+ };
6278
+ var subscription = obsQuery.subscribe(onNext, onError);
6279
+ return function () { return subscription.unsubscribe(); };
6280
+ }, [
6281
+ obsQuery,
6282
+ this.renderPromises,
6283
+ this.client.disableNetworkFetches,
6284
+ ]), function () { return _this.getCurrentResult(); }, function () { return _this.getCurrentResult(); });
6285
+ this.unsafeHandlePartialRefetch(result);
6286
+ var queryResult = this.toQueryResult(result);
6287
+ if (!queryResult.loading && this.asyncResolveFns.size) {
6288
+ this.asyncResolveFns.forEach(function (resolve) { return resolve(queryResult); });
6289
+ this.asyncResolveFns.clear();
6290
+ }
6291
+ return queryResult;
6292
+ };
6293
+ InternalState.prototype.useOptions = function (options) {
6294
+ var _a;
6295
+ var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
6296
+ var currentWatchQueryOptions = this.watchQueryOptions;
6297
+ if (this.optionsToIgnoreOnce.has(currentWatchQueryOptions) ||
6298
+ !equality.equal(watchQueryOptions, currentWatchQueryOptions)) {
6299
+ this.watchQueryOptions = watchQueryOptions;
6300
+ if (currentWatchQueryOptions && this.observable) {
6301
+ this.optionsToIgnoreOnce.delete(currentWatchQueryOptions);
6302
+ this.observable.reobserve(watchQueryOptions);
6303
+ this.previousData = ((_a = this.result) === null || _a === void 0 ? void 0 : _a.data) || this.previousData;
6304
+ this.result = void 0;
6305
+ }
6306
+ }
6307
+ this.onCompleted = options.onCompleted || InternalState.prototype.onCompleted;
6308
+ this.onError = options.onError || InternalState.prototype.onError;
6309
+ if ((this.renderPromises || this.client.disableNetworkFetches) &&
6310
+ this.queryHookOptions.ssr === false &&
6311
+ !this.queryHookOptions.skip) {
6312
+ this.result = this.ssrDisabledResult;
6313
+ }
6314
+ else if (this.queryHookOptions.skip ||
6315
+ this.watchQueryOptions.fetchPolicy === 'standby') {
6316
+ this.result = this.skipStandbyResult;
6317
+ }
6318
+ else if (this.result === this.ssrDisabledResult ||
6319
+ this.result === this.skipStandbyResult) {
6320
+ this.result = void 0;
6321
+ }
6322
+ };
6323
+ InternalState.prototype.createWatchQueryOptions = function (_a) {
6324
+ var _b;
6325
+ if (_a === void 0) { _a = {}; }
6326
+ 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"]);
6327
+ var watchQueryOptions = Object.assign(otherOptions, { query: this.query });
6328
+ if (this.renderPromises &&
6329
+ (watchQueryOptions.fetchPolicy === 'network-only' ||
6330
+ watchQueryOptions.fetchPolicy === 'cache-and-network')) {
6331
+ watchQueryOptions.fetchPolicy = 'cache-first';
6332
+ }
6333
+ if (!watchQueryOptions.variables) {
6334
+ watchQueryOptions.variables = {};
6335
+ }
6336
+ if (skip) {
6337
+ var _c = watchQueryOptions.fetchPolicy, fetchPolicy = _c === void 0 ? this.getDefaultFetchPolicy() : _c, _d = watchQueryOptions.initialFetchPolicy, initialFetchPolicy = _d === void 0 ? fetchPolicy : _d;
6338
+ Object.assign(watchQueryOptions, {
6339
+ initialFetchPolicy: initialFetchPolicy,
6340
+ fetchPolicy: 'standby',
6341
+ });
6099
6342
  }
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
- }
6343
+ else if (!watchQueryOptions.fetchPolicy) {
6344
+ watchQueryOptions.fetchPolicy =
6345
+ ((_b = this.observable) === null || _b === void 0 ? void 0 : _b.options.initialFetchPolicy) ||
6346
+ this.getDefaultFetchPolicy();
6112
6347
  }
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 () {
6348
+ return watchQueryOptions;
6349
+ };
6350
+ InternalState.prototype.getDefaultFetchPolicy = function () {
6124
6351
  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
- }
6352
+ return (((_a = this.queryHookOptions.defaultOptions) === null || _a === void 0 ? void 0 : _a.fetchPolicy) ||
6353
+ ((_b = this.client.defaultOptions.watchQuery) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
6354
+ "cache-first");
6355
+ };
6356
+ InternalState.prototype.onCompleted = function (data) { };
6357
+ InternalState.prototype.onError = function (error) { };
6358
+ InternalState.prototype.useObservableQuery = function () {
6359
+ var obsQuery = this.observable =
6360
+ this.renderPromises
6361
+ && this.renderPromises.getSSRObservable(this.watchQueryOptions)
6362
+ || this.observable
6363
+ || this.client.watchQuery(mergeOptions(this.queryHookOptions.defaultOptions, this.watchQueryOptions));
6364
+ this.obsQueryFields = React.useMemo(function () { return ({
6365
+ refetch: obsQuery.refetch.bind(obsQuery),
6366
+ reobserve: obsQuery.reobserve.bind(obsQuery),
6367
+ fetchMore: obsQuery.fetchMore.bind(obsQuery),
6368
+ updateQuery: obsQuery.updateQuery.bind(obsQuery),
6369
+ startPolling: obsQuery.startPolling.bind(obsQuery),
6370
+ stopPolling: obsQuery.stopPolling.bind(obsQuery),
6371
+ subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
6372
+ }); }, [obsQuery]);
6373
+ var ssrAllowed = !(this.queryHookOptions.ssr === false ||
6374
+ this.queryHookOptions.skip);
6375
+ if (this.renderPromises && ssrAllowed) {
6376
+ this.renderPromises.registerSSRObservable(obsQuery);
6377
+ if (obsQuery.getCurrentResult().loading) {
6378
+ this.renderPromises.addObservableQueryPromise(obsQuery);
6150
6379
  }
6151
6380
  }
6152
- Object.assign(ref.current, { client: client, query: query });
6153
- }, [obsQuery, client, query, options]);
6154
- React.useEffect(function () {
6155
- if (context.renderPromises) {
6156
- return;
6381
+ return obsQuery;
6382
+ };
6383
+ InternalState.prototype.setResult = function (nextResult) {
6384
+ var previousResult = this.result;
6385
+ if (previousResult && previousResult.data) {
6386
+ this.previousData = previousResult.data;
6157
6387
  }
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;
6388
+ this.result = nextResult;
6389
+ this.forceUpdate();
6390
+ this.handleErrorOrCompleted(nextResult);
6391
+ };
6392
+ InternalState.prototype.handleErrorOrCompleted = function (result) {
6393
+ if (!result.loading) {
6394
+ if (result.error) {
6395
+ this.onError(result.error);
6171
6396
  }
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);
6397
+ else if (result.data) {
6398
+ this.onCompleted(result.data);
6175
6399
  }
6176
6400
  }
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
- }
6401
+ };
6402
+ InternalState.prototype.getCurrentResult = function () {
6403
+ if (!this.result) {
6404
+ this.handleErrorOrCompleted(this.result = this.observable.getCurrentResult());
6202
6405
  }
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) &&
6406
+ return this.result;
6407
+ };
6408
+ InternalState.prototype.toQueryResult = function (result) {
6409
+ var queryResult = this.toQueryResultCache.get(result);
6410
+ if (queryResult)
6411
+ return queryResult;
6412
+ var data = result.data; result.partial; var resultWithoutPartial = tslib.__rest(result, ["data", "partial"]);
6413
+ 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 }));
6414
+ if (!queryResult.error && isNonEmptyArray(result.errors)) {
6415
+ queryResult.error = new ApolloError({ graphQLErrors: result.errors });
6416
+ }
6417
+ return queryResult;
6418
+ };
6419
+ InternalState.prototype.unsafeHandlePartialRefetch = function (result) {
6420
+ if (result.partial &&
6421
+ this.queryHookOptions.partialRefetch &&
6210
6422
  !result.loading &&
6211
6423
  (!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 () { });
6424
+ this.observable.options.fetchPolicy !== 'cache-only') {
6425
+ Object.assign(result, {
6426
+ loading: true,
6427
+ networkStatus: exports.NetworkStatus.refetch,
6428
+ });
6429
+ this.observable.refetch();
6221
6430
  }
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
- }
6431
+ };
6432
+ return InternalState;
6433
+ }());
6278
6434
 
6279
6435
  var EAGER_METHODS = [
6280
6436
  'refetch',
6437
+ 'reobserve',
6281
6438
  'fetchMore',
6282
6439
  'updateQuery',
6283
6440
  'startPolling',
6284
6441
  'subscribeToMore',
6285
6442
  ];
6286
6443
  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
- }
6444
+ var internalState = useInternalState(useApolloClient(options && options.client), query);
6445
+ var execOptionsRef = React.useRef();
6446
+ var useQueryResult = internalState.useQuery(tslib.__assign(tslib.__assign(tslib.__assign({}, options), execOptionsRef.current), { skip: !execOptionsRef.current }));
6447
+ var initialFetchPolicy = useQueryResult.observable.options.initialFetchPolicy ||
6448
+ internalState.getDefaultFetchPolicy();
6449
+ var result = Object.assign(useQueryResult, {
6450
+ called: !!execOptionsRef.current,
6451
+ });
6294
6452
  var eagerMethods = React.useMemo(function () {
6295
6453
  var eagerMethods = {};
6296
6454
  var _loop_1 = function (key) {
6297
6455
  var method = result[key];
6298
6456
  eagerMethods[key] = function () {
6299
- var args = [];
6300
- for (var _i = 0; _i < arguments.length; _i++) {
6301
- args[_i] = arguments[_i];
6457
+ if (!execOptionsRef.current) {
6458
+ execOptionsRef.current = Object.create(null);
6459
+ internalState.forceUpdate();
6302
6460
  }
6303
- setExecution(function (execution) { return (tslib.__assign(tslib.__assign({}, execution), { called: true })); });
6304
- return method.apply(void 0, args);
6461
+ return method.apply(this, arguments);
6305
6462
  };
6306
6463
  };
6307
6464
  for (var _i = 0, EAGER_METHODS_1 = EAGER_METHODS; _i < EAGER_METHODS_1.length; _i++) {
@@ -6310,15 +6467,14 @@ function useLazyQuery(query, options) {
6310
6467
  }
6311
6468
  return eagerMethods;
6312
6469
  }, []);
6313
- result.error = result.error || void 0;
6314
6470
  Object.assign(result, eagerMethods);
6315
6471
  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
- });
6472
+ execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
6473
+ fetchPolicy: initialFetchPolicy,
6474
+ };
6475
+ var promise = internalState
6476
+ .asyncUpdate()
6477
+ .then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
6322
6478
  promise.catch(function () { });
6323
6479
  return promise;
6324
6480
  }, []);
@@ -6407,9 +6563,12 @@ function useMutation(mutation, options) {
6407
6563
  var reset = React.useCallback(function () {
6408
6564
  setResult({ called: false, loading: false, client: client });
6409
6565
  }, []);
6410
- React.useEffect(function () { return function () {
6411
- ref.current.isMounted = false;
6412
- }; }, []);
6566
+ React.useEffect(function () {
6567
+ ref.current.isMounted = true;
6568
+ return function () {
6569
+ ref.current.isMounted = false;
6570
+ };
6571
+ }, []);
6413
6572
  return [execute, tslib.__assign({ reset: reset }, result)];
6414
6573
  }
6415
6574
 
@@ -6433,6 +6592,12 @@ function useSubscription(subscription, options) {
6433
6592
  context: options === null || options === void 0 ? void 0 : options.context,
6434
6593
  });
6435
6594
  }), observable = _b[0], setObservable = _b[1];
6595
+ var canResetObservableRef = React.useRef(false);
6596
+ React.useEffect(function () {
6597
+ return function () {
6598
+ canResetObservableRef.current = true;
6599
+ };
6600
+ }, []);
6436
6601
  var ref = React.useRef({ client: client, subscription: subscription, options: options });
6437
6602
  React.useEffect(function () {
6438
6603
  var _a, _b, _c, _d;
@@ -6441,7 +6606,7 @@ function useSubscription(subscription, options) {
6441
6606
  shouldResubscribe = !!shouldResubscribe(options);
6442
6607
  }
6443
6608
  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)) {
6609
+ 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
6610
  setResult({
6446
6611
  loading: false,
6447
6612
  data: void 0,
@@ -6449,13 +6614,16 @@ function useSubscription(subscription, options) {
6449
6614
  variables: options === null || options === void 0 ? void 0 : options.variables,
6450
6615
  });
6451
6616
  setObservable(null);
6617
+ canResetObservableRef.current = false;
6452
6618
  }
6453
6619
  }
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))) {
6620
+ else if ((shouldResubscribe !== false &&
6621
+ (client !== ref.current.client ||
6622
+ subscription !== ref.current.subscription ||
6623
+ (options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
6624
+ !(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
6625
+ !equality.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) ||
6626
+ canResetObservableRef.current) {
6459
6627
  setResult({
6460
6628
  loading: true,
6461
6629
  data: void 0,
@@ -6468,9 +6636,10 @@ function useSubscription(subscription, options) {
6468
6636
  fetchPolicy: options === null || options === void 0 ? void 0 : options.fetchPolicy,
6469
6637
  context: options === null || options === void 0 ? void 0 : options.context,
6470
6638
  }));
6639
+ canResetObservableRef.current = false;
6471
6640
  }
6472
6641
  Object.assign(ref.current, { client: client, subscription: subscription, options: options });
6473
- }, [client, subscription, options]);
6642
+ }, [client, subscription, options, canResetObservableRef.current]);
6474
6643
  React.useEffect(function () {
6475
6644
  if (!observable) {
6476
6645
  return;
@@ -6542,7 +6711,6 @@ exports.HttpLink = HttpLink;
6542
6711
  exports.InMemoryCache = InMemoryCache;
6543
6712
  exports.MissingFieldError = MissingFieldError;
6544
6713
  exports.ObservableQuery = ObservableQuery;
6545
- exports.applyNextFetchPolicy = applyNextFetchPolicy;
6546
6714
  exports.checkFetcher = checkFetcher;
6547
6715
  exports.concat = concat;
6548
6716
  exports.createHttpLink = createHttpLink;