@apollo/client 3.6.2 → 3.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/apollo-client.cjs +164 -105
  2. package/apollo-client.cjs.map +1 -1
  3. package/apollo-client.min.cjs +1 -1
  4. package/cache/cache.cjs +9 -10
  5. package/cache/cache.cjs.map +1 -1
  6. package/cache/cache.cjs.native.js +2288 -0
  7. package/cache/inmemory/readFromStore.d.ts.map +1 -1
  8. package/cache/inmemory/readFromStore.js +10 -11
  9. package/cache/inmemory/readFromStore.js.map +1 -1
  10. package/core/ApolloClient.d.ts.map +1 -1
  11. package/core/ApolloClient.js.map +1 -1
  12. package/core/ObservableQuery.d.ts.map +1 -1
  13. package/core/ObservableQuery.js +5 -3
  14. package/core/ObservableQuery.js.map +1 -1
  15. package/core/core.cjs +5 -3
  16. package/core/core.cjs.map +1 -1
  17. package/core/core.cjs.native.js +2141 -0
  18. package/errors/errors.cjs.native.js +48 -0
  19. package/invariantErrorCodes.js +1 -1
  20. package/link/batch/batch.cjs.native.js +161 -0
  21. package/link/batch-http/batch-http.cjs.native.js +127 -0
  22. package/link/context/context.cjs.native.js +38 -0
  23. package/link/core/core.cjs.native.js +121 -0
  24. package/link/error/error.cjs.native.js +90 -0
  25. package/link/http/http.cjs.native.js +320 -0
  26. package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
  27. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  28. package/link/persisted-queries/persisted-queries.cjs.native.js +174 -0
  29. package/link/retry/retry.cjs.native.js +170 -0
  30. package/link/schema/schema.cjs.native.js +56 -0
  31. package/link/subscriptions/subscriptions.cjs.native.js +45 -0
  32. package/link/utils/utils.cjs.native.js +115 -0
  33. package/link/ws/ws.cjs.native.js +28 -0
  34. package/main.cjs.native.js +16 -0
  35. package/package.json +16 -17
  36. package/react/components/components.cjs.native.js +79 -0
  37. package/react/context/context.cjs.native.js +67 -0
  38. package/react/hoc/hoc.cjs.native.js +325 -0
  39. package/react/hooks/hooks.cjs +168 -99
  40. package/react/hooks/hooks.cjs.map +1 -1
  41. package/react/hooks/hooks.cjs.native.js +612 -0
  42. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  43. package/react/hooks/useLazyQuery.js +12 -23
  44. package/react/hooks/useLazyQuery.js.map +1 -1
  45. package/react/hooks/useMutation.js +7 -7
  46. package/react/hooks/useMutation.js.map +1 -1
  47. package/react/hooks/useQuery.d.ts +6 -2
  48. package/react/hooks/useQuery.d.ts.map +1 -1
  49. package/react/hooks/useQuery.js +52 -40
  50. package/react/hooks/useQuery.js.map +1 -1
  51. package/react/hooks/useSubscription.d.ts.map +1 -1
  52. package/react/hooks/useSubscription.js +17 -7
  53. package/react/hooks/useSubscription.js.map +1 -1
  54. package/react/hooks/useSyncExternalStore.d.ts +4 -0
  55. package/react/hooks/useSyncExternalStore.d.ts.map +1 -0
  56. package/react/hooks/useSyncExternalStore.js +48 -0
  57. package/react/hooks/useSyncExternalStore.js.map +1 -0
  58. package/react/parser/parser.cjs.native.js +103 -0
  59. package/react/react.cjs.native.js +22 -0
  60. package/react/ssr/ssr.cjs.native.js +150 -0
  61. package/testing/core/core.cjs.native.js +288 -0
  62. package/testing/testing.cjs.native.js +58 -0
  63. package/utilities/common/canUse.d.ts +2 -0
  64. package/utilities/common/canUse.d.ts.map +1 -1
  65. package/utilities/common/canUse.js +6 -2
  66. package/utilities/common/canUse.js.map +1 -1
  67. package/utilities/common/mergeDeep.d.ts.map +1 -1
  68. package/utilities/common/mergeDeep.js +8 -11
  69. package/utilities/common/mergeDeep.js.map +1 -1
  70. package/utilities/common/mergeOptions.d.ts +1 -1
  71. package/utilities/common/mergeOptions.d.ts.map +1 -1
  72. package/utilities/common/mergeOptions.js +1 -1
  73. package/utilities/common/mergeOptions.js.map +1 -1
  74. package/utilities/globals/globals.cjs.native.js +56 -0
  75. package/utilities/observables/Concast.d.ts.map +1 -1
  76. package/utilities/observables/Concast.js +5 -2
  77. package/utilities/observables/Concast.js.map +1 -1
  78. package/utilities/policies/pagination.d.ts.map +1 -1
  79. package/utilities/policies/pagination.js +9 -7
  80. package/utilities/policies/pagination.js.map +1 -1
  81. package/utilities/utilities.cjs +30 -23
  82. package/utilities/utilities.cjs.map +1 -1
  83. package/utilities/utilities.cjs.native.js +1281 -0
  84. package/version.js +1 -1
@@ -3,18 +3,31 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var globals = require('../../utilities/globals');
6
- var react = require('react');
6
+ var React = require('react');
7
7
  var context = require('../context');
8
8
  var tslib = require('tslib');
9
- var errors = require('../../errors');
10
- var index_js = require('use-sync-external-store/shim/index.js');
9
+ var utilities = require('../../utilities');
11
10
  var equality = require('@wry/equality');
12
11
  var core = require('../../core');
12
+ var errors = require('../../errors');
13
13
  var parser = require('../parser');
14
- var utilities = require('../../utilities');
14
+
15
+ function _interopNamespace(e) {
16
+ if (e && e.__esModule) return e;
17
+ var n = Object.create(null);
18
+ if (e) {
19
+ for (var k in e) {
20
+ n[k] = e[k];
21
+ }
22
+ }
23
+ n["default"] = e;
24
+ return Object.freeze(n);
25
+ }
26
+
27
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
15
28
 
16
29
  function useApolloClient(override) {
17
- var context$1 = react.useContext(context.getApolloContext());
30
+ var context$1 = React.useContext(context.getApolloContext());
18
31
  var client = override || context$1.client;
19
32
  __DEV__ ? globals.invariant(!!client, 'Could not find "client" in the context or passed in as an option. ' +
20
33
  'Wrap the root component in an <ApolloProvider>, or pass an ApolloClient ' +
@@ -22,29 +35,76 @@ function useApolloClient(override) {
22
35
  return client;
23
36
  }
24
37
 
38
+ var didWarnUncachedGetSnapshot = false;
39
+ var uSESKey = "useSyncExternalStore";
40
+ var realHook = React__namespace[uSESKey];
41
+ var useSyncExternalStore = realHook || (function (subscribe, getSnapshot, getServerSnapshot) {
42
+ var value = getSnapshot();
43
+ if (__DEV__ &&
44
+ !didWarnUncachedGetSnapshot &&
45
+ value !== getSnapshot()) {
46
+ didWarnUncachedGetSnapshot = true;
47
+ __DEV__ && globals.invariant.error('The result of getSnapshot should be cached to avoid an infinite loop');
48
+ }
49
+ var _a = React__namespace.useState({ inst: { value: value, getSnapshot: getSnapshot } }), inst = _a[0].inst, forceUpdate = _a[1];
50
+ if (utilities.canUseLayoutEffect) {
51
+ React__namespace.useLayoutEffect(function () {
52
+ Object.assign(inst, { value: value, getSnapshot: getSnapshot });
53
+ if (checkIfSnapshotChanged(inst)) {
54
+ forceUpdate({ inst: inst });
55
+ }
56
+ }, [subscribe, value, getSnapshot]);
57
+ }
58
+ else {
59
+ Object.assign(inst, { value: value, getSnapshot: getSnapshot });
60
+ }
61
+ React__namespace.useEffect(function () {
62
+ if (checkIfSnapshotChanged(inst)) {
63
+ forceUpdate({ inst: inst });
64
+ }
65
+ return subscribe(function handleStoreChange() {
66
+ if (checkIfSnapshotChanged(inst)) {
67
+ forceUpdate({ inst: inst });
68
+ }
69
+ });
70
+ }, [subscribe]);
71
+ return value;
72
+ });
73
+ function checkIfSnapshotChanged(_a) {
74
+ var value = _a.value, getSnapshot = _a.getSnapshot;
75
+ try {
76
+ return value !== getSnapshot();
77
+ }
78
+ catch (_b) {
79
+ return true;
80
+ }
81
+ }
82
+
25
83
  var hasOwnProperty = Object.prototype.hasOwnProperty;
26
84
  function useQuery(query, options) {
27
85
  if (options === void 0) { options = Object.create(null); }
28
86
  return useInternalState(useApolloClient(options.client), query).useQuery(options);
29
87
  }
30
88
  function useInternalState(client, query) {
31
- var stateRef = react.useRef();
89
+ var stateRef = React.useRef();
32
90
  if (!stateRef.current ||
33
91
  client !== stateRef.current.client ||
34
92
  query !== stateRef.current.query) {
35
- stateRef.current = new InternalState(client, query);
93
+ stateRef.current = new InternalState(client, query, stateRef.current);
36
94
  }
37
95
  var state = stateRef.current;
38
- var _a = react.useState(0); _a[0]; var setTick = _a[1];
96
+ var _a = React.useState(0); _a[0]; var setTick = _a[1];
39
97
  state.forceUpdate = function () {
40
98
  setTick(function (tick) { return tick + 1; });
41
99
  };
42
100
  return state;
43
101
  }
44
102
  var InternalState = (function () {
45
- function InternalState(client, query) {
103
+ function InternalState(client, query, previous) {
46
104
  this.client = client;
47
105
  this.query = query;
106
+ this.asyncResolveFns = new Set();
107
+ this.optionsToIgnoreOnce = new (utilities.canUseWeakSet ? WeakSet : Set)();
48
108
  this.ssrDisabledResult = utilities.maybeDeepFreeze({
49
109
  loading: true,
50
110
  data: void 0,
@@ -59,15 +119,29 @@ var InternalState = (function () {
59
119
  });
60
120
  this.toQueryResultCache = new (utilities.canUseWeakMap ? WeakMap : Map)();
61
121
  parser.verifyDocumentType(query, parser.DocumentType.Query);
122
+ var previousResult = previous && previous.result;
123
+ var previousData = previousResult && previousResult.data;
124
+ if (previousData) {
125
+ this.previousData = previousData;
126
+ }
62
127
  }
63
128
  InternalState.prototype.forceUpdate = function () {
129
+ __DEV__ && globals.invariant.warn("Calling default no-op implementation of InternalState#forceUpdate");
130
+ };
131
+ InternalState.prototype.asyncUpdate = function () {
132
+ var _this = this;
133
+ return new Promise(function (resolve) {
134
+ _this.asyncResolveFns.add(resolve);
135
+ _this.optionsToIgnoreOnce.add(_this.watchQueryOptions);
136
+ _this.forceUpdate();
137
+ });
64
138
  };
65
139
  InternalState.prototype.useQuery = function (options) {
66
140
  var _this = this;
67
- this.renderPromises = react.useContext(context.getApolloContext()).renderPromises;
141
+ this.renderPromises = React.useContext(context.getApolloContext()).renderPromises;
68
142
  this.useOptions(options);
69
143
  var obsQuery = this.useObservableQuery();
70
- var result = index_js.useSyncExternalStore(react.useCallback(function () {
144
+ var result = useSyncExternalStore(React.useCallback(function () {
71
145
  if (_this.renderPromises) {
72
146
  return function () { };
73
147
  }
@@ -115,15 +189,22 @@ var InternalState = (function () {
115
189
  this.client.disableNetworkFetches,
116
190
  ]), function () { return _this.getCurrentResult(); }, function () { return _this.getCurrentResult(); });
117
191
  this.unsafeHandlePartialRefetch(result);
118
- return this.toQueryResult(result);
192
+ var queryResult = this.toQueryResult(result);
193
+ if (!queryResult.loading && this.asyncResolveFns.size) {
194
+ this.asyncResolveFns.forEach(function (resolve) { return resolve(queryResult); });
195
+ this.asyncResolveFns.clear();
196
+ }
197
+ return queryResult;
119
198
  };
120
199
  InternalState.prototype.useOptions = function (options) {
121
200
  var _a;
122
201
  var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
123
202
  var currentWatchQueryOptions = this.watchQueryOptions;
124
- if (!equality.equal(watchQueryOptions, currentWatchQueryOptions)) {
203
+ if (this.optionsToIgnoreOnce.has(currentWatchQueryOptions) ||
204
+ !equality.equal(watchQueryOptions, currentWatchQueryOptions)) {
125
205
  this.watchQueryOptions = watchQueryOptions;
126
206
  if (currentWatchQueryOptions && this.observable) {
207
+ this.optionsToIgnoreOnce.delete(currentWatchQueryOptions);
127
208
  this.observable.reobserve(watchQueryOptions);
128
209
  this.previousData = ((_a = this.result) === null || _a === void 0 ? void 0 : _a.data) || this.previousData;
129
210
  this.result = void 0;
@@ -132,7 +213,8 @@ var InternalState = (function () {
132
213
  this.onCompleted = options.onCompleted || InternalState.prototype.onCompleted;
133
214
  this.onError = options.onError || InternalState.prototype.onError;
134
215
  if ((this.renderPromises || this.client.disableNetworkFetches) &&
135
- this.queryHookOptions.ssr === false) {
216
+ this.queryHookOptions.ssr === false &&
217
+ !this.queryHookOptions.skip) {
136
218
  this.result = this.ssrDisabledResult;
137
219
  }
138
220
  else if (this.queryHookOptions.skip ||
@@ -145,51 +227,38 @@ var InternalState = (function () {
145
227
  }
146
228
  };
147
229
  InternalState.prototype.createWatchQueryOptions = function (_a) {
230
+ var _b;
148
231
  if (_a === void 0) { _a = {}; }
149
- 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"]);
150
- var toMerge = [];
151
- var globalDefaults = this.client.defaultOptions.watchQuery;
152
- if (globalDefaults)
153
- toMerge.push(globalDefaults);
154
- if (defaultOptions)
155
- toMerge.push(defaultOptions);
156
- var latestOptions = this.observable && this.observable.options;
157
- if (latestOptions && toMerge.length) {
158
- var defaults_1 = toMerge.reduce(core.mergeOptions, Object.create(null));
159
- toMerge.length = 1;
160
- toMerge[0] = defaults_1;
161
- Object.keys(defaults_1).forEach(function (defaultOptionName) {
162
- var currentOptionValue = latestOptions[defaultOptionName];
163
- if (hasOwnProperty.call(latestOptions, defaultOptionName) &&
164
- !equality.equal(defaults_1[defaultOptionName], currentOptionValue)) {
165
- defaults_1[defaultOptionName] = defaultOptionName === "variables"
166
- ? tslib.__assign(tslib.__assign({}, defaults_1.variables), currentOptionValue) : currentOptionValue;
167
- }
168
- });
169
- }
170
- toMerge.push(otherOptions);
171
- var merged = toMerge.reduce(core.mergeOptions, Object.create(null));
172
- var watchQueryOptions = Object.assign(merged, { query: this.query });
232
+ 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"]);
233
+ var watchQueryOptions = Object.assign(otherOptions, { query: this.query });
173
234
  if (this.renderPromises &&
174
235
  (watchQueryOptions.fetchPolicy === 'network-only' ||
175
236
  watchQueryOptions.fetchPolicy === 'cache-and-network')) {
176
237
  watchQueryOptions.fetchPolicy = 'cache-first';
177
238
  }
178
- else if (!watchQueryOptions.fetchPolicy) {
179
- watchQueryOptions.fetchPolicy = 'cache-first';
239
+ if (!watchQueryOptions.variables) {
240
+ watchQueryOptions.variables = {};
180
241
  }
181
242
  if (skip) {
182
- var _b = watchQueryOptions.initialFetchPolicy, initialFetchPolicy = _b === void 0 ? watchQueryOptions.fetchPolicy : _b;
243
+ var _c = watchQueryOptions.fetchPolicy, fetchPolicy = _c === void 0 ? this.getDefaultFetchPolicy() : _c, _d = watchQueryOptions.initialFetchPolicy, initialFetchPolicy = _d === void 0 ? fetchPolicy : _d;
183
244
  Object.assign(watchQueryOptions, {
184
245
  initialFetchPolicy: initialFetchPolicy,
185
246
  fetchPolicy: 'standby',
186
247
  });
187
248
  }
188
- if (!watchQueryOptions.variables) {
189
- watchQueryOptions.variables = {};
249
+ else if (!watchQueryOptions.fetchPolicy) {
250
+ watchQueryOptions.fetchPolicy =
251
+ ((_b = this.observable) === null || _b === void 0 ? void 0 : _b.options.initialFetchPolicy) ||
252
+ this.getDefaultFetchPolicy();
190
253
  }
191
254
  return watchQueryOptions;
192
255
  };
256
+ InternalState.prototype.getDefaultFetchPolicy = function () {
257
+ var _a, _b;
258
+ return (((_a = this.queryHookOptions.defaultOptions) === null || _a === void 0 ? void 0 : _a.fetchPolicy) ||
259
+ ((_b = this.client.defaultOptions.watchQuery) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
260
+ "cache-first");
261
+ };
193
262
  InternalState.prototype.onCompleted = function (data) { };
194
263
  InternalState.prototype.onError = function (error) { };
195
264
  InternalState.prototype.useObservableQuery = function () {
@@ -197,8 +266,8 @@ var InternalState = (function () {
197
266
  this.renderPromises
198
267
  && this.renderPromises.getSSRObservable(this.watchQueryOptions)
199
268
  || this.observable
200
- || this.client.watchQuery(tslib.__assign({}, this.watchQueryOptions));
201
- this.obsQueryFields = react.useMemo(function () { return ({
269
+ || this.client.watchQuery(core.mergeOptions(this.queryHookOptions.defaultOptions, this.watchQueryOptions));
270
+ this.obsQueryFields = React.useMemo(function () { return ({
202
271
  refetch: obsQuery.refetch.bind(obsQuery),
203
272
  reobserve: obsQuery.reobserve.bind(obsQuery),
204
273
  fetchMore: obsQuery.fetchMore.bind(obsQuery),
@@ -207,11 +276,11 @@ var InternalState = (function () {
207
276
  stopPolling: obsQuery.stopPolling.bind(obsQuery),
208
277
  subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
209
278
  }); }, [obsQuery]);
210
- if (this.renderPromises) {
279
+ var ssrAllowed = !(this.queryHookOptions.ssr === false ||
280
+ this.queryHookOptions.skip);
281
+ if (this.renderPromises && ssrAllowed) {
211
282
  this.renderPromises.registerSSRObservable(obsQuery);
212
- var ssrAllowed = !(this.queryHookOptions.ssr === false ||
213
- this.queryHookOptions.skip);
214
- if (ssrAllowed && obsQuery.getCurrentResult().loading) {
283
+ if (obsQuery.getCurrentResult().loading) {
215
284
  this.renderPromises.addObservableQueryPromise(obsQuery);
216
285
  }
217
286
  }
@@ -279,17 +348,17 @@ var EAGER_METHODS = [
279
348
  ];
280
349
  function useLazyQuery(query, options) {
281
350
  var internalState = useInternalState(useApolloClient(options && options.client), query);
282
- var execOptionsRef = react.useRef();
283
- var defaultOptions = internalState.client.defaultOptions.watchQuery;
284
- var initialFetchPolicy = (options && options.fetchPolicy) ||
285
- (execOptionsRef.current && execOptionsRef.current.fetchPolicy) ||
286
- (defaultOptions && defaultOptions.fetchPolicy) ||
287
- "cache-first";
288
- var useQueryResult = internalState.useQuery(tslib.__assign(tslib.__assign(tslib.__assign({}, options), execOptionsRef.current), { skip: !execOptionsRef.current }));
351
+ var execOptionsRef = React.useRef();
352
+ var merged = execOptionsRef.current
353
+ ? utilities.mergeOptions(options, execOptionsRef.current)
354
+ : options;
355
+ var useQueryResult = internalState.useQuery(tslib.__assign(tslib.__assign({}, merged), { skip: !execOptionsRef.current }));
356
+ var initialFetchPolicy = useQueryResult.observable.options.initialFetchPolicy ||
357
+ internalState.getDefaultFetchPolicy();
289
358
  var result = Object.assign(useQueryResult, {
290
359
  called: !!execOptionsRef.current,
291
360
  });
292
- var eagerMethods = react.useMemo(function () {
361
+ var eagerMethods = React.useMemo(function () {
293
362
  var eagerMethods = {};
294
363
  var _loop_1 = function (key) {
295
364
  var method = result[key];
@@ -308,23 +377,13 @@ function useLazyQuery(query, options) {
308
377
  return eagerMethods;
309
378
  }, []);
310
379
  Object.assign(result, eagerMethods);
311
- var execute = react.useCallback(function (executeOptions) {
312
- var promise = result.reobserve(execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
380
+ var execute = React.useCallback(function (executeOptions) {
381
+ execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
313
382
  fetchPolicy: initialFetchPolicy,
314
- }).then(function (apolloQueryResult) {
315
- apolloQueryResult = apolloQueryResult || internalState["getCurrentResult"]();
316
- if (apolloQueryResult.error ||
317
- utilities.isNonEmptyArray(apolloQueryResult.errors)) {
318
- var _a = result.observable.options.errorPolicy, errorPolicy = _a === void 0 ? "none" : _a;
319
- if (errorPolicy === "none") {
320
- throw apolloQueryResult.error || new errors.ApolloError({
321
- graphQLErrors: apolloQueryResult.errors,
322
- });
323
- }
324
- }
325
- return internalState.toQueryResult(apolloQueryResult);
326
- }).then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
327
- internalState.forceUpdate();
383
+ };
384
+ var promise = internalState
385
+ .asyncUpdate()
386
+ .then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
328
387
  promise.catch(function () { });
329
388
  return promise;
330
389
  }, []);
@@ -334,12 +393,12 @@ function useLazyQuery(query, options) {
334
393
  function useMutation(mutation, options) {
335
394
  var client = useApolloClient(options === null || options === void 0 ? void 0 : options.client);
336
395
  parser.verifyDocumentType(mutation, parser.DocumentType.Mutation);
337
- var _a = react.useState({
396
+ var _a = React.useState({
338
397
  called: false,
339
398
  loading: false,
340
399
  client: client,
341
400
  }), result = _a[0], setResult = _a[1];
342
- var ref = react.useRef({
401
+ var ref = React.useRef({
343
402
  result: result,
344
403
  mutationId: 0,
345
404
  isMounted: true,
@@ -350,7 +409,7 @@ function useMutation(mutation, options) {
350
409
  {
351
410
  Object.assign(ref.current, { client: client, options: options, mutation: mutation });
352
411
  }
353
- var execute = react.useCallback(function (executeOptions) {
412
+ var execute = React.useCallback(function (executeOptions) {
354
413
  if (executeOptions === void 0) { executeOptions = {}; }
355
414
  var _a = ref.current, client = _a.client, options = _a.options, mutation = _a.mutation;
356
415
  var baseOptions = tslib.__assign(tslib.__assign({}, options), { mutation: mutation });
@@ -366,7 +425,7 @@ function useMutation(mutation, options) {
366
425
  var mutationId = ++ref.current.mutationId;
367
426
  var clientOptions = core.mergeOptions(baseOptions, executeOptions);
368
427
  return client.mutate(clientOptions).then(function (response) {
369
- var _a, _b;
428
+ var _a, _b, _c;
370
429
  var data = response.data, errors$1 = response.errors;
371
430
  var error = errors$1 && errors$1.length > 0
372
431
  ? new errors.ApolloError({ graphQLErrors: errors$1 })
@@ -384,11 +443,11 @@ function useMutation(mutation, options) {
384
443
  setResult(ref.current.result = result_1);
385
444
  }
386
445
  }
387
- (_a = baseOptions.onCompleted) === null || _a === void 0 ? void 0 : _a.call(baseOptions, response.data);
388
- (_b = executeOptions.onCompleted) === null || _b === void 0 ? void 0 : _b.call(executeOptions, response.data);
446
+ (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onCompleted) === null || _b === void 0 ? void 0 : _b.call(_a, response.data);
447
+ (_c = executeOptions.onCompleted) === null || _c === void 0 ? void 0 : _c.call(executeOptions, response.data);
389
448
  return response;
390
449
  }).catch(function (error) {
391
- var _a, _b;
450
+ var _a, _b, _c, _d;
392
451
  if (mutationId === ref.current.mutationId &&
393
452
  ref.current.isMounted) {
394
453
  var result_2 = {
@@ -402,18 +461,18 @@ function useMutation(mutation, options) {
402
461
  setResult(ref.current.result = result_2);
403
462
  }
404
463
  }
405
- if (baseOptions.onError || clientOptions.onError) {
406
- (_a = baseOptions.onError) === null || _a === void 0 ? void 0 : _a.call(baseOptions, error);
407
- (_b = executeOptions.onError) === null || _b === void 0 ? void 0 : _b.call(executeOptions, error);
464
+ if (((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) || clientOptions.onError) {
465
+ (_c = (_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.onError) === null || _c === void 0 ? void 0 : _c.call(_b, error);
466
+ (_d = executeOptions.onError) === null || _d === void 0 ? void 0 : _d.call(executeOptions, error);
408
467
  return { data: void 0, errors: error };
409
468
  }
410
469
  throw error;
411
470
  });
412
471
  }, []);
413
- var reset = react.useCallback(function () {
472
+ var reset = React.useCallback(function () {
414
473
  setResult({ called: false, loading: false, client: client });
415
474
  }, []);
416
- react.useEffect(function () {
475
+ React.useEffect(function () {
417
476
  ref.current.isMounted = true;
418
477
  return function () {
419
478
  ref.current.isMounted = false;
@@ -425,13 +484,13 @@ function useMutation(mutation, options) {
425
484
  function useSubscription(subscription, options) {
426
485
  var client = useApolloClient(options === null || options === void 0 ? void 0 : options.client);
427
486
  parser.verifyDocumentType(subscription, parser.DocumentType.Subscription);
428
- var _a = react.useState({
487
+ var _a = React.useState({
429
488
  loading: !(options === null || options === void 0 ? void 0 : options.skip),
430
489
  error: void 0,
431
490
  data: void 0,
432
491
  variables: options === null || options === void 0 ? void 0 : options.variables,
433
492
  }), result = _a[0], setResult = _a[1];
434
- var _b = react.useState(function () {
493
+ var _b = React.useState(function () {
435
494
  if (options === null || options === void 0 ? void 0 : options.skip) {
436
495
  return null;
437
496
  }
@@ -442,15 +501,21 @@ function useSubscription(subscription, options) {
442
501
  context: options === null || options === void 0 ? void 0 : options.context,
443
502
  });
444
503
  }), observable = _b[0], setObservable = _b[1];
445
- var ref = react.useRef({ client: client, subscription: subscription, options: options });
446
- react.useEffect(function () {
504
+ var canResetObservableRef = React.useRef(false);
505
+ React.useEffect(function () {
506
+ return function () {
507
+ canResetObservableRef.current = true;
508
+ };
509
+ }, []);
510
+ var ref = React.useRef({ client: client, subscription: subscription, options: options });
511
+ React.useEffect(function () {
447
512
  var _a, _b, _c, _d;
448
513
  var shouldResubscribe = options === null || options === void 0 ? void 0 : options.shouldResubscribe;
449
514
  if (typeof shouldResubscribe === 'function') {
450
515
  shouldResubscribe = !!shouldResubscribe(options);
451
516
  }
452
517
  if (options === null || options === void 0 ? void 0 : options.skip) {
453
- if (!(options === null || options === void 0 ? void 0 : options.skip) !== !((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.skip)) {
518
+ if (!(options === null || options === void 0 ? void 0 : options.skip) !== !((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.skip) || canResetObservableRef.current) {
454
519
  setResult({
455
520
  loading: false,
456
521
  data: void 0,
@@ -458,13 +523,16 @@ function useSubscription(subscription, options) {
458
523
  variables: options === null || options === void 0 ? void 0 : options.variables,
459
524
  });
460
525
  setObservable(null);
526
+ canResetObservableRef.current = false;
461
527
  }
462
528
  }
463
- else if (shouldResubscribe !== false && (client !== ref.current.client ||
464
- subscription !== ref.current.subscription ||
465
- (options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
466
- !(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
467
- !equality.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) {
529
+ else if ((shouldResubscribe !== false &&
530
+ (client !== ref.current.client ||
531
+ subscription !== ref.current.subscription ||
532
+ (options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
533
+ !(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
534
+ !equality.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) ||
535
+ canResetObservableRef.current) {
468
536
  setResult({
469
537
  loading: true,
470
538
  data: void 0,
@@ -477,10 +545,11 @@ function useSubscription(subscription, options) {
477
545
  fetchPolicy: options === null || options === void 0 ? void 0 : options.fetchPolicy,
478
546
  context: options === null || options === void 0 ? void 0 : options.context,
479
547
  }));
548
+ canResetObservableRef.current = false;
480
549
  }
481
550
  Object.assign(ref.current, { client: client, subscription: subscription, options: options });
482
- }, [client, subscription, options]);
483
- react.useEffect(function () {
551
+ }, [client, subscription, options, canResetObservableRef.current]);
552
+ React.useEffect(function () {
484
553
  if (!observable) {
485
554
  return;
486
555
  }
@@ -521,8 +590,8 @@ function useSubscription(subscription, options) {
521
590
 
522
591
  function useReactiveVar(rv) {
523
592
  var value = rv();
524
- var setValue = react.useState(value)[1];
525
- react.useEffect(function () {
593
+ var setValue = React.useState(value)[1];
594
+ React.useEffect(function () {
526
595
  var probablySameValue = rv();
527
596
  if (value !== probablySameValue) {
528
597
  setValue(probablySameValue);