@apollo/client 3.6.1 → 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 (89) hide show
  1. package/LICENSE +1 -1
  2. package/apollo-client.cjs +133 -78
  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.map +1 -1
  7. package/core/ApolloClient.js.map +1 -1
  8. package/core/ObservableQuery.d.ts.map +1 -1
  9. package/core/ObservableQuery.js +3 -1
  10. package/core/ObservableQuery.js.map +1 -1
  11. package/core/core.cjs +4 -2
  12. package/core/core.cjs.map +1 -1
  13. package/core/core.cjs.native.js +2141 -0
  14. package/errors/errors.cjs.native.js +48 -0
  15. package/invariantErrorCodes.js +1 -1
  16. package/link/batch/batch.cjs.native.js +161 -0
  17. package/link/batch-http/batch-http.cjs.native.js +127 -0
  18. package/link/context/context.cjs.native.js +38 -0
  19. package/link/core/core.cjs.native.js +121 -0
  20. package/link/error/error.cjs.native.js +90 -0
  21. package/link/http/http.cjs.native.js +320 -0
  22. package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
  23. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  24. package/link/persisted-queries/index.d.ts +2 -1
  25. package/link/persisted-queries/index.d.ts.map +1 -1
  26. package/link/persisted-queries/index.js +26 -13
  27. package/link/persisted-queries/index.js.map +1 -1
  28. package/link/persisted-queries/persisted-queries.cjs +25 -12
  29. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  30. package/link/persisted-queries/persisted-queries.cjs.native.js +174 -0
  31. package/link/retry/retry.cjs.native.js +170 -0
  32. package/link/schema/schema.cjs.native.js +56 -0
  33. package/link/subscriptions/subscriptions.cjs.native.js +45 -0
  34. package/link/utils/utils.cjs.native.js +115 -0
  35. package/link/ws/ws.cjs.native.js +28 -0
  36. package/main.cjs.native.js +16 -0
  37. package/package.json +17 -18
  38. package/react/components/components.cjs.native.js +79 -0
  39. package/react/context/ApolloConsumer.js +2 -2
  40. package/react/context/ApolloProvider.js +2 -2
  41. package/react/context/context.cjs +4 -4
  42. package/react/context/context.cjs.map +1 -1
  43. package/react/context/context.cjs.native.js +67 -0
  44. package/react/hoc/hoc.cjs.native.js +325 -0
  45. package/react/hooks/hooks.cjs +151 -90
  46. package/react/hooks/hooks.cjs.map +1 -1
  47. package/react/hooks/hooks.cjs.native.js +604 -0
  48. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  49. package/react/hooks/useLazyQuery.js +7 -22
  50. package/react/hooks/useLazyQuery.js.map +1 -1
  51. package/react/hooks/useQuery.d.ts +5 -1
  52. package/react/hooks/useQuery.d.ts.map +1 -1
  53. package/react/hooks/useQuery.js +46 -39
  54. package/react/hooks/useQuery.js.map +1 -1
  55. package/react/hooks/useSubscription.d.ts.map +1 -1
  56. package/react/hooks/useSubscription.js +17 -7
  57. package/react/hooks/useSubscription.js.map +1 -1
  58. package/react/hooks/useSyncExternalStore.d.ts +4 -0
  59. package/react/hooks/useSyncExternalStore.d.ts.map +1 -0
  60. package/react/hooks/useSyncExternalStore.js +48 -0
  61. package/react/hooks/useSyncExternalStore.js.map +1 -0
  62. package/react/parser/parser.cjs.native.js +103 -0
  63. package/react/react.cjs.native.js +22 -0
  64. package/react/ssr/ssr.cjs.native.js +150 -0
  65. package/testing/core/core.cjs.native.js +288 -0
  66. package/testing/core/mocking/mockQueryManager.js +1 -1
  67. package/testing/core/mocking/mockWatchQuery.js +1 -1
  68. package/testing/core/wrap.js +1 -1
  69. package/testing/testing.cjs.native.js +58 -0
  70. package/utilities/common/canUse.d.ts +2 -0
  71. package/utilities/common/canUse.d.ts.map +1 -1
  72. package/utilities/common/canUse.js +6 -2
  73. package/utilities/common/canUse.js.map +1 -1
  74. package/utilities/common/mergeOptions.d.ts +1 -1
  75. package/utilities/common/mergeOptions.d.ts.map +1 -1
  76. package/utilities/common/mergeOptions.js +1 -1
  77. package/utilities/common/mergeOptions.js.map +1 -1
  78. package/utilities/globals/global.js +1 -2
  79. package/utilities/globals/globals.cjs.native.js +56 -0
  80. package/utilities/observables/Concast.d.ts.map +1 -1
  81. package/utilities/observables/Concast.js +5 -2
  82. package/utilities/observables/Concast.js.map +1 -1
  83. package/utilities/policies/pagination.d.ts.map +1 -1
  84. package/utilities/policies/pagination.js +9 -7
  85. package/utilities/policies/pagination.js.map +1 -1
  86. package/utilities/utilities.cjs +22 -12
  87. package/utilities/utilities.cjs.map +1 -1
  88. package/utilities/utilities.cjs.native.js +1284 -0
  89. package/version.js +1 -1
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2021 Apollo Graph, Inc. (Formerly Meteor Development Group, Inc.)
3
+ Copyright (c) 2022 Apollo Graph, Inc. (Formerly Meteor Development Group, Inc.)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/apollo-client.cjs CHANGED
@@ -13,7 +13,6 @@ var context = require('@wry/context');
13
13
  var trie = require('@wry/trie');
14
14
  var graphqlTag = require('graphql-tag');
15
15
  var React = require('react');
16
- var index_js = require('use-sync-external-store/shim/index.js');
17
16
 
18
17
  function _interopNamespace(e) {
19
18
  if (e && e.__esModule) return e;
@@ -899,11 +898,14 @@ function asyncMap(observable, mapFn, catchFn) {
899
898
  });
900
899
  }
901
900
 
902
- var canUseWeakMap = typeof WeakMap === 'function' && !(typeof navigator === 'object' &&
903
- navigator.product === 'ReactNative');
901
+ var canUseWeakMap = typeof WeakMap === 'function' &&
902
+ maybe(function () { return navigator.product; }) !== 'ReactNative';
904
903
  var canUseWeakSet = typeof WeakSet === 'function';
905
904
  var canUseSymbol = typeof Symbol === 'function' &&
906
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;
907
909
 
908
910
  function fixObservableSubclass(subclass) {
909
911
  function set(key) {
@@ -951,9 +953,12 @@ var Concast = (function (_super) {
951
953
  }
952
954
  },
953
955
  complete: function () {
954
- if (_this.sub !== null) {
956
+ var sub = _this.sub;
957
+ if (sub !== null) {
955
958
  var value = _this.sources.shift();
956
959
  if (!value) {
960
+ if (sub)
961
+ setTimeout(function () { return sub.unsubscribe(); });
957
962
  _this.sub = null;
958
963
  if (_this.latest &&
959
964
  _this.latest[0] === "next") {
@@ -1021,7 +1026,7 @@ var Concast = (function (_super) {
1021
1026
  if (this.observers.delete(observer) &&
1022
1027
  --this.addCount < 1 &&
1023
1028
  !quietly) {
1024
- this.handlers.error(new Error("Observable cancelled prematurely"));
1029
+ this.handlers.complete();
1025
1030
  }
1026
1031
  };
1027
1032
  Concast.prototype.cleanup = function (callback) {
@@ -1090,7 +1095,7 @@ function stringifyForDisplay(value) {
1090
1095
 
1091
1096
  function mergeOptions(defaults, options) {
1092
1097
  return compact(defaults, options, options.variables && {
1093
- variables: tslib.__assign(tslib.__assign({}, defaults.variables), options.variables),
1098
+ variables: tslib.__assign(tslib.__assign({}, (defaults && defaults.variables)), options.variables),
1094
1099
  });
1095
1100
  }
1096
1101
 
@@ -1298,7 +1303,7 @@ var concat = ApolloLink.concat;
1298
1303
 
1299
1304
  var execute = ApolloLink.execute;
1300
1305
 
1301
- var version = '3.6.1';
1306
+ var version = '3.6.4';
1302
1307
 
1303
1308
  var hasOwnProperty$3 = Object.prototype.hasOwnProperty;
1304
1309
  function parseAndCheckHttpResponse(operations) {
@@ -3948,7 +3953,9 @@ var ObservableQuery = (function (_super) {
3948
3953
  _this.queryInfo = queryInfo;
3949
3954
  _this.queryManager = queryManager;
3950
3955
  _this.isTornDown = false;
3951
- _this.options = tslib.__assign({ initialFetchPolicy: options.fetchPolicy || "cache-first" }, 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 });
3952
3959
  _this.queryId = queryInfo.queryId || queryManager.generateQueryId();
3953
3960
  var opDef = getOperationDefinition(_this.query);
3954
3961
  _this.queryName = opDef && opDef.name && opDef.name.value;
@@ -6004,17 +6011,17 @@ function getApolloContext() {
6004
6011
 
6005
6012
  var ApolloConsumer = function (props) {
6006
6013
  var ApolloContext = getApolloContext();
6007
- return React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
6014
+ return (React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
6008
6015
  __DEV__ ? tsInvariant.invariant(context && context.client, 'Could not find "client" in the context of ApolloConsumer. ' +
6009
6016
  'Wrap the root component in an <ApolloProvider>.') : tsInvariant.invariant(context && context.client, 25);
6010
6017
  return props.children(context.client);
6011
- });
6018
+ }));
6012
6019
  };
6013
6020
 
6014
6021
  var ApolloProvider = function (_a) {
6015
6022
  var client = _a.client, children = _a.children;
6016
6023
  var ApolloContext = getApolloContext();
6017
- return React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
6024
+ return (React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
6018
6025
  if (context === void 0) { context = {}; }
6019
6026
  if (client && context.client !== client) {
6020
6027
  context = Object.assign({}, context, { client: client });
@@ -6022,7 +6029,7 @@ var ApolloProvider = function (_a) {
6022
6029
  __DEV__ ? tsInvariant.invariant(context.client, 'ApolloProvider was not passed a client instance. Make ' +
6023
6030
  'sure you pass in your client via the "client" prop.') : tsInvariant.invariant(context.client, 26);
6024
6031
  return (React__namespace.createElement(ApolloContext.Provider, { value: context }, children));
6025
- });
6032
+ }));
6026
6033
  };
6027
6034
 
6028
6035
  function useApolloClient(override) {
@@ -6034,6 +6041,51 @@ function useApolloClient(override) {
6034
6041
  return client;
6035
6042
  }
6036
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
+
6037
6089
  exports.DocumentType = void 0;
6038
6090
  (function (DocumentType) {
6039
6091
  DocumentType[DocumentType["Query"] = 0] = "Query";
@@ -6150,6 +6202,8 @@ var InternalState = (function () {
6150
6202
  function InternalState(client, query) {
6151
6203
  this.client = client;
6152
6204
  this.query = query;
6205
+ this.asyncResolveFns = new Set();
6206
+ this.optionsToIgnoreOnce = new (canUseWeakSet ? WeakSet : Set)();
6153
6207
  this.ssrDisabledResult = maybeDeepFreeze({
6154
6208
  loading: true,
6155
6209
  data: void 0,
@@ -6166,13 +6220,22 @@ var InternalState = (function () {
6166
6220
  verifyDocumentType(query, exports.DocumentType.Query);
6167
6221
  }
6168
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
+ });
6169
6232
  };
6170
6233
  InternalState.prototype.useQuery = function (options) {
6171
6234
  var _this = this;
6172
6235
  this.renderPromises = React.useContext(getApolloContext()).renderPromises;
6173
6236
  this.useOptions(options);
6174
6237
  var obsQuery = this.useObservableQuery();
6175
- var result = index_js.useSyncExternalStore(React.useCallback(function () {
6238
+ var result = useSyncExternalStore(React.useCallback(function () {
6176
6239
  if (_this.renderPromises) {
6177
6240
  return function () { };
6178
6241
  }
@@ -6218,17 +6281,24 @@ var InternalState = (function () {
6218
6281
  obsQuery,
6219
6282
  this.renderPromises,
6220
6283
  this.client.disableNetworkFetches,
6221
- ]), function () { return _this.getCurrentResult(); });
6284
+ ]), function () { return _this.getCurrentResult(); }, function () { return _this.getCurrentResult(); });
6222
6285
  this.unsafeHandlePartialRefetch(result);
6223
- return this.toQueryResult(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;
6224
6292
  };
6225
6293
  InternalState.prototype.useOptions = function (options) {
6226
6294
  var _a;
6227
6295
  var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
6228
6296
  var currentWatchQueryOptions = this.watchQueryOptions;
6229
- if (!equality.equal(watchQueryOptions, currentWatchQueryOptions)) {
6297
+ if (this.optionsToIgnoreOnce.has(currentWatchQueryOptions) ||
6298
+ !equality.equal(watchQueryOptions, currentWatchQueryOptions)) {
6230
6299
  this.watchQueryOptions = watchQueryOptions;
6231
6300
  if (currentWatchQueryOptions && this.observable) {
6301
+ this.optionsToIgnoreOnce.delete(currentWatchQueryOptions);
6232
6302
  this.observable.reobserve(watchQueryOptions);
6233
6303
  this.previousData = ((_a = this.result) === null || _a === void 0 ? void 0 : _a.data) || this.previousData;
6234
6304
  this.result = void 0;
@@ -6237,7 +6307,8 @@ var InternalState = (function () {
6237
6307
  this.onCompleted = options.onCompleted || InternalState.prototype.onCompleted;
6238
6308
  this.onError = options.onError || InternalState.prototype.onError;
6239
6309
  if ((this.renderPromises || this.client.disableNetworkFetches) &&
6240
- this.queryHookOptions.ssr === false) {
6310
+ this.queryHookOptions.ssr === false &&
6311
+ !this.queryHookOptions.skip) {
6241
6312
  this.result = this.ssrDisabledResult;
6242
6313
  }
6243
6314
  else if (this.queryHookOptions.skip ||
@@ -6250,51 +6321,38 @@ var InternalState = (function () {
6250
6321
  }
6251
6322
  };
6252
6323
  InternalState.prototype.createWatchQueryOptions = function (_a) {
6324
+ var _b;
6253
6325
  if (_a === void 0) { _a = {}; }
6254
- var skip = _a.skip; _a.ssr; _a.onCompleted; _a.onError; _a.displayName; var defaultOptions = _a.defaultOptions, otherOptions = tslib.__rest(_a, ["skip", "ssr", "onCompleted", "onError", "displayName", "defaultOptions"]);
6255
- var toMerge = [];
6256
- var globalDefaults = this.client.defaultOptions.watchQuery;
6257
- if (globalDefaults)
6258
- toMerge.push(globalDefaults);
6259
- if (defaultOptions)
6260
- toMerge.push(defaultOptions);
6261
- var latestOptions = this.observable && this.observable.options;
6262
- if (latestOptions && toMerge.length) {
6263
- var defaults_1 = toMerge.reduce(mergeOptions, Object.create(null));
6264
- toMerge.length = 1;
6265
- toMerge[0] = defaults_1;
6266
- Object.keys(defaults_1).forEach(function (defaultOptionName) {
6267
- var currentOptionValue = latestOptions[defaultOptionName];
6268
- if (hasOwnProperty.call(latestOptions, defaultOptionName) &&
6269
- !equality.equal(defaults_1[defaultOptionName], currentOptionValue)) {
6270
- defaults_1[defaultOptionName] = defaultOptionName === "variables"
6271
- ? tslib.__assign(tslib.__assign({}, defaults_1.variables), currentOptionValue) : currentOptionValue;
6272
- }
6273
- });
6274
- }
6275
- toMerge.push(otherOptions);
6276
- var merged = toMerge.reduce(mergeOptions, Object.create(null));
6277
- var watchQueryOptions = Object.assign(merged, { query: this.query });
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 });
6278
6328
  if (this.renderPromises &&
6279
6329
  (watchQueryOptions.fetchPolicy === 'network-only' ||
6280
6330
  watchQueryOptions.fetchPolicy === 'cache-and-network')) {
6281
6331
  watchQueryOptions.fetchPolicy = 'cache-first';
6282
6332
  }
6283
- else if (!watchQueryOptions.fetchPolicy) {
6284
- watchQueryOptions.fetchPolicy = 'cache-first';
6333
+ if (!watchQueryOptions.variables) {
6334
+ watchQueryOptions.variables = {};
6285
6335
  }
6286
6336
  if (skip) {
6287
- var _b = watchQueryOptions.initialFetchPolicy, initialFetchPolicy = _b === void 0 ? watchQueryOptions.fetchPolicy : _b;
6337
+ var _c = watchQueryOptions.fetchPolicy, fetchPolicy = _c === void 0 ? this.getDefaultFetchPolicy() : _c, _d = watchQueryOptions.initialFetchPolicy, initialFetchPolicy = _d === void 0 ? fetchPolicy : _d;
6288
6338
  Object.assign(watchQueryOptions, {
6289
6339
  initialFetchPolicy: initialFetchPolicy,
6290
6340
  fetchPolicy: 'standby',
6291
6341
  });
6292
6342
  }
6293
- if (!watchQueryOptions.variables) {
6294
- watchQueryOptions.variables = {};
6343
+ else if (!watchQueryOptions.fetchPolicy) {
6344
+ watchQueryOptions.fetchPolicy =
6345
+ ((_b = this.observable) === null || _b === void 0 ? void 0 : _b.options.initialFetchPolicy) ||
6346
+ this.getDefaultFetchPolicy();
6295
6347
  }
6296
6348
  return watchQueryOptions;
6297
6349
  };
6350
+ InternalState.prototype.getDefaultFetchPolicy = function () {
6351
+ var _a, _b;
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
+ };
6298
6356
  InternalState.prototype.onCompleted = function (data) { };
6299
6357
  InternalState.prototype.onError = function (error) { };
6300
6358
  InternalState.prototype.useObservableQuery = function () {
@@ -6302,7 +6360,7 @@ var InternalState = (function () {
6302
6360
  this.renderPromises
6303
6361
  && this.renderPromises.getSSRObservable(this.watchQueryOptions)
6304
6362
  || this.observable
6305
- || this.client.watchQuery(tslib.__assign({}, this.watchQueryOptions));
6363
+ || this.client.watchQuery(mergeOptions(this.queryHookOptions.defaultOptions, this.watchQueryOptions));
6306
6364
  this.obsQueryFields = React.useMemo(function () { return ({
6307
6365
  refetch: obsQuery.refetch.bind(obsQuery),
6308
6366
  reobserve: obsQuery.reobserve.bind(obsQuery),
@@ -6312,11 +6370,11 @@ var InternalState = (function () {
6312
6370
  stopPolling: obsQuery.stopPolling.bind(obsQuery),
6313
6371
  subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
6314
6372
  }); }, [obsQuery]);
6315
- if (this.renderPromises) {
6373
+ var ssrAllowed = !(this.queryHookOptions.ssr === false ||
6374
+ this.queryHookOptions.skip);
6375
+ if (this.renderPromises && ssrAllowed) {
6316
6376
  this.renderPromises.registerSSRObservable(obsQuery);
6317
- var ssrAllowed = !(this.queryHookOptions.ssr === false ||
6318
- this.queryHookOptions.skip);
6319
- if (ssrAllowed && obsQuery.getCurrentResult().loading) {
6377
+ if (obsQuery.getCurrentResult().loading) {
6320
6378
  this.renderPromises.addObservableQueryPromise(obsQuery);
6321
6379
  }
6322
6380
  }
@@ -6385,12 +6443,9 @@ var EAGER_METHODS = [
6385
6443
  function useLazyQuery(query, options) {
6386
6444
  var internalState = useInternalState(useApolloClient(options && options.client), query);
6387
6445
  var execOptionsRef = React.useRef();
6388
- var defaultOptions = internalState.client.defaultOptions.watchQuery;
6389
- var initialFetchPolicy = (options && options.fetchPolicy) ||
6390
- (execOptionsRef.current && execOptionsRef.current.fetchPolicy) ||
6391
- (defaultOptions && defaultOptions.fetchPolicy) ||
6392
- "cache-first";
6393
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();
6394
6449
  var result = Object.assign(useQueryResult, {
6395
6450
  called: !!execOptionsRef.current,
6396
6451
  });
@@ -6414,22 +6469,12 @@ function useLazyQuery(query, options) {
6414
6469
  }, []);
6415
6470
  Object.assign(result, eagerMethods);
6416
6471
  var execute = React.useCallback(function (executeOptions) {
6417
- var promise = result.reobserve(execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
6472
+ execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
6418
6473
  fetchPolicy: initialFetchPolicy,
6419
- }).then(function (apolloQueryResult) {
6420
- apolloQueryResult = apolloQueryResult || internalState["getCurrentResult"]();
6421
- if (apolloQueryResult.error ||
6422
- isNonEmptyArray(apolloQueryResult.errors)) {
6423
- var _a = result.observable.options.errorPolicy, errorPolicy = _a === void 0 ? "none" : _a;
6424
- if (errorPolicy === "none") {
6425
- throw apolloQueryResult.error || new ApolloError({
6426
- graphQLErrors: apolloQueryResult.errors,
6427
- });
6428
- }
6429
- }
6430
- return internalState.toQueryResult(apolloQueryResult);
6431
- }).then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
6432
- internalState.forceUpdate();
6474
+ };
6475
+ var promise = internalState
6476
+ .asyncUpdate()
6477
+ .then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
6433
6478
  promise.catch(function () { });
6434
6479
  return promise;
6435
6480
  }, []);
@@ -6547,6 +6592,12 @@ function useSubscription(subscription, options) {
6547
6592
  context: options === null || options === void 0 ? void 0 : options.context,
6548
6593
  });
6549
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
+ }, []);
6550
6601
  var ref = React.useRef({ client: client, subscription: subscription, options: options });
6551
6602
  React.useEffect(function () {
6552
6603
  var _a, _b, _c, _d;
@@ -6555,7 +6606,7 @@ function useSubscription(subscription, options) {
6555
6606
  shouldResubscribe = !!shouldResubscribe(options);
6556
6607
  }
6557
6608
  if (options === null || options === void 0 ? void 0 : options.skip) {
6558
- 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) {
6559
6610
  setResult({
6560
6611
  loading: false,
6561
6612
  data: void 0,
@@ -6563,13 +6614,16 @@ function useSubscription(subscription, options) {
6563
6614
  variables: options === null || options === void 0 ? void 0 : options.variables,
6564
6615
  });
6565
6616
  setObservable(null);
6617
+ canResetObservableRef.current = false;
6566
6618
  }
6567
6619
  }
6568
- else if (shouldResubscribe !== false && (client !== ref.current.client ||
6569
- subscription !== ref.current.subscription ||
6570
- (options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
6571
- !(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
6572
- !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) {
6573
6627
  setResult({
6574
6628
  loading: true,
6575
6629
  data: void 0,
@@ -6582,9 +6636,10 @@ function useSubscription(subscription, options) {
6582
6636
  fetchPolicy: options === null || options === void 0 ? void 0 : options.fetchPolicy,
6583
6637
  context: options === null || options === void 0 ? void 0 : options.context,
6584
6638
  }));
6639
+ canResetObservableRef.current = false;
6585
6640
  }
6586
6641
  Object.assign(ref.current, { client: client, subscription: subscription, options: options });
6587
- }, [client, subscription, options]);
6642
+ }, [client, subscription, options, canResetObservableRef.current]);
6588
6643
  React.useEffect(function () {
6589
6644
  if (!observable) {
6590
6645
  return;