@apollo/client 3.8.0-alpha.11 → 3.8.0-alpha.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/apollo-client.cjs +452 -281
  2. package/apollo-client.cjs.map +1 -1
  3. package/apollo-client.min.cjs +1 -1
  4. package/core/ApolloClient.d.ts.map +1 -1
  5. package/core/ApolloClient.js.map +1 -1
  6. package/core/ObservableQuery.d.ts +2 -1
  7. package/core/ObservableQuery.d.ts.map +1 -1
  8. package/core/ObservableQuery.js +30 -19
  9. package/core/ObservableQuery.js.map +1 -1
  10. package/core/QueryManager.d.ts +2 -0
  11. package/core/QueryManager.d.ts.map +1 -1
  12. package/core/QueryManager.js +60 -48
  13. package/core/QueryManager.js.map +1 -1
  14. package/core/core.cjs +175 -82
  15. package/core/core.cjs.map +1 -1
  16. package/core/core.cjs.native.js +175 -82
  17. package/core/equalByQuery.d.ts +4 -0
  18. package/core/equalByQuery.d.ts.map +1 -0
  19. package/{react/hooks/compareResults.js → core/equalByQuery.js} +14 -10
  20. package/core/equalByQuery.js.map +1 -0
  21. package/core/index.d.ts +1 -1
  22. package/core/index.d.ts.map +1 -1
  23. package/core/index.js +1 -1
  24. package/core/index.js.map +1 -1
  25. package/errors/errors.cjs +17 -17
  26. package/errors/errors.cjs.map +1 -1
  27. package/errors/errors.cjs.native.js +17 -17
  28. package/errors/index.d.ts +24 -8
  29. package/errors/index.d.ts.map +1 -1
  30. package/errors/index.js +17 -19
  31. package/errors/index.js.map +1 -1
  32. package/invariantErrorCodes.js +1 -1
  33. package/link/batch-http/batch-http.cjs +23 -2
  34. package/link/batch-http/batch-http.cjs.map +1 -1
  35. package/link/batch-http/batch-http.cjs.native.js +23 -2
  36. package/link/batch-http/batchHttpLink.d.ts.map +1 -1
  37. package/link/batch-http/batchHttpLink.js +7 -2
  38. package/link/batch-http/batchHttpLink.js.map +1 -1
  39. package/link/core/types.d.ts +4 -0
  40. package/link/core/types.d.ts.map +1 -1
  41. package/link/core/types.js.map +1 -1
  42. package/link/http/createHttpLink.d.ts.map +1 -1
  43. package/link/http/createHttpLink.js +21 -20
  44. package/link/http/createHttpLink.js.map +1 -1
  45. package/link/http/http.cjs +59 -30
  46. package/link/http/http.cjs.map +1 -1
  47. package/link/http/http.cjs.native.js +59 -30
  48. package/link/http/parseAndCheckHttpResponse.d.ts.map +1 -1
  49. package/link/http/parseAndCheckHttpResponse.js +34 -14
  50. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  51. package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
  52. package/link/http/selectHttpOptionsAndBody.js +2 -1
  53. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  54. package/link/subscriptions/index.d.ts.map +1 -1
  55. package/link/subscriptions/index.js +10 -5
  56. package/link/subscriptions/index.js.map +1 -1
  57. package/link/subscriptions/subscriptions.cjs +9 -4
  58. package/link/subscriptions/subscriptions.cjs.map +1 -1
  59. package/link/subscriptions/subscriptions.cjs.native.js +9 -4
  60. package/link/utils/filterOperationVariables.d.ts +5 -0
  61. package/link/utils/filterOperationVariables.d.ts.map +1 -0
  62. package/link/utils/filterOperationVariables.js +18 -0
  63. package/link/utils/filterOperationVariables.js.map +1 -0
  64. package/link/utils/index.d.ts +1 -0
  65. package/link/utils/index.d.ts.map +1 -1
  66. package/link/utils/index.js +1 -0
  67. package/link/utils/index.js.map +1 -1
  68. package/link/utils/utils.cjs +18 -0
  69. package/link/utils/utils.cjs.map +1 -1
  70. package/link/utils/utils.cjs.native.js +18 -0
  71. package/package.json +17 -17
  72. package/react/cache/QuerySubscription.js +1 -1
  73. package/react/cache/QuerySubscription.js.map +1 -1
  74. package/react/cache/SuspenseCache.d.ts +3 -2
  75. package/react/cache/SuspenseCache.d.ts.map +1 -1
  76. package/react/cache/SuspenseCache.js +6 -7
  77. package/react/cache/SuspenseCache.js.map +1 -1
  78. package/react/hooks/hooks.cjs +61 -84
  79. package/react/hooks/hooks.cjs.map +1 -1
  80. package/react/hooks/hooks.cjs.native.js +61 -84
  81. package/react/hooks/internal/__use.d.ts +3 -1
  82. package/react/hooks/internal/__use.d.ts.map +1 -1
  83. package/react/hooks/internal/__use.js +16 -12
  84. package/react/hooks/internal/__use.js.map +1 -1
  85. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  86. package/react/hooks/useLazyQuery.js +13 -22
  87. package/react/hooks/useLazyQuery.js.map +1 -1
  88. package/react/hooks/useQuery.d.ts +3 -3
  89. package/react/hooks/useQuery.d.ts.map +1 -1
  90. package/react/hooks/useQuery.js +26 -25
  91. package/react/hooks/useQuery.js.map +1 -1
  92. package/react/hooks/useSuspenseQuery.d.ts.map +1 -1
  93. package/react/hooks/useSuspenseQuery.js +6 -2
  94. package/react/hooks/useSuspenseQuery.js.map +1 -1
  95. package/react/index.d.ts +1 -1
  96. package/react/index.d.ts.map +1 -1
  97. package/react/index.js +1 -1
  98. package/react/index.js.map +1 -1
  99. package/react/react.cjs +7 -22
  100. package/react/react.cjs.map +1 -1
  101. package/react/react.cjs.native.js +7 -22
  102. package/react/types/types.d.ts +1 -0
  103. package/react/types/types.d.ts.map +1 -1
  104. package/react/types/types.js.map +1 -1
  105. package/testing/core/mocking/mockSubscriptionLink.d.ts +1 -1
  106. package/testing/react/MockedProvider.d.ts +1 -1
  107. package/testing/react/MockedProvider.d.ts.map +1 -1
  108. package/testing/react/MockedProvider.js +7 -6
  109. package/testing/react/MockedProvider.js.map +1 -1
  110. package/testing/testing.cjs +8 -124
  111. package/testing/testing.cjs.map +1 -1
  112. package/testing/testing.cjs.native.js +8 -124
  113. package/utilities/common/incrementalResult.d.ts +2 -1
  114. package/utilities/common/incrementalResult.d.ts.map +1 -1
  115. package/utilities/common/incrementalResult.js +4 -0
  116. package/utilities/common/incrementalResult.js.map +1 -1
  117. package/utilities/common/mergeOptions.d.ts +1 -1
  118. package/utilities/common/mergeOptions.d.ts.map +1 -1
  119. package/utilities/common/mergeOptions.js.map +1 -1
  120. package/utilities/common/objects.d.ts +1 -0
  121. package/utilities/common/objects.d.ts.map +1 -1
  122. package/utilities/common/objects.js +6 -0
  123. package/utilities/common/objects.js.map +1 -1
  124. package/utilities/common/omitDeep.d.ts +3 -0
  125. package/utilities/common/omitDeep.d.ts.map +1 -0
  126. package/utilities/common/omitDeep.js +42 -0
  127. package/utilities/common/omitDeep.js.map +1 -0
  128. package/utilities/common/stripTypename.d.ts +2 -0
  129. package/utilities/common/stripTypename.d.ts.map +1 -0
  130. package/utilities/common/stripTypename.js +5 -0
  131. package/utilities/common/stripTypename.js.map +1 -0
  132. package/utilities/graphql/storeUtils.d.ts.map +1 -1
  133. package/utilities/graphql/storeUtils.js +1 -0
  134. package/utilities/graphql/storeUtils.js.map +1 -1
  135. package/utilities/graphql/transform.d.ts.map +1 -1
  136. package/utilities/graphql/transform.js +26 -16
  137. package/utilities/graphql/transform.js.map +1 -1
  138. package/utilities/index.d.ts +4 -0
  139. package/utilities/index.d.ts.map +1 -1
  140. package/utilities/index.js +3 -0
  141. package/utilities/index.js.map +1 -1
  142. package/utilities/types/DeepOmit.d.ts +9 -0
  143. package/utilities/types/DeepOmit.d.ts.map +1 -0
  144. package/utilities/types/DeepOmit.js +2 -0
  145. package/utilities/types/DeepOmit.js.map +1 -0
  146. package/utilities/utilities.cjs +111 -15
  147. package/utilities/utilities.cjs.map +1 -1
  148. package/utilities/utilities.cjs.native.js +111 -15
  149. package/version.js +1 -1
  150. package/react/hooks/compareResults.d.ts +0 -3
  151. package/react/hooks/compareResults.d.ts.map +0 -1
  152. package/react/hooks/compareResults.js.map +0 -1
@@ -11,6 +11,9 @@ var equality = require('@wry/equality');
11
11
  var core = require('../../core');
12
12
  var errors = require('../../errors');
13
13
  var parser = require('../parser');
14
+ var cache = require('../../cache');
15
+
16
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
14
17
 
15
18
  function _interopNamespace(e) {
16
19
  if (e && e.__esModule) return e;
@@ -25,6 +28,7 @@ function _interopNamespace(e) {
25
28
  }
26
29
 
27
30
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
31
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
28
32
 
29
33
  function useApolloClient(override) {
30
34
  var context$1 = React.useContext(context.getApolloContext());
@@ -37,8 +41,8 @@ function useApolloClient(override) {
37
41
 
38
42
  var didWarnUncachedGetSnapshot = false;
39
43
  var uSESKey = "useSyncExternalStore";
40
- var realHook = React__namespace[uSESKey];
41
- var useSyncExternalStore = realHook || (function (subscribe, getSnapshot, getServerSnapshot) {
44
+ var realHook$1 = React__namespace[uSESKey];
45
+ var useSyncExternalStore = realHook$1 || (function (subscribe, getSnapshot, getServerSnapshot) {
42
46
  var value = getSnapshot();
43
47
  if (globals.__DEV__ &&
44
48
  !didWarnUncachedGetSnapshot &&
@@ -103,8 +107,6 @@ var InternalState = (function () {
103
107
  function InternalState(client, query, previous) {
104
108
  this.client = client;
105
109
  this.query = query;
106
- this.asyncResolveFns = new Set();
107
- this.optionsToIgnoreOnce = new (utilities.canUseWeakSet ? WeakSet : Set)();
108
110
  this.ssrDisabledResult = utilities.maybeDeepFreeze({
109
111
  loading: true,
110
112
  data: void 0,
@@ -128,20 +130,30 @@ var InternalState = (function () {
128
130
  InternalState.prototype.forceUpdate = function () {
129
131
  globals.__DEV__ && globals.invariant.warn("Calling default no-op implementation of InternalState#forceUpdate");
130
132
  };
131
- InternalState.prototype.asyncUpdate = function (signal) {
133
+ InternalState.prototype.executeQuery = function (options) {
132
134
  var _this = this;
133
- return new Promise(function (resolve, reject) {
134
- var watchQueryOptions = _this.watchQueryOptions;
135
- var handleAborted = function () {
136
- _this.asyncResolveFns.delete(resolve);
137
- _this.optionsToIgnoreOnce.delete(watchQueryOptions);
138
- signal.removeEventListener('abort', handleAborted);
139
- reject(signal.reason);
140
- };
141
- _this.asyncResolveFns.add(resolve);
142
- _this.optionsToIgnoreOnce.add(watchQueryOptions);
143
- signal.addEventListener('abort', handleAborted);
144
- _this.forceUpdate();
135
+ var _a;
136
+ if (options.query) {
137
+ Object.assign(this, { query: options.query });
138
+ }
139
+ this.watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
140
+ var concast = this.observable.reobserveAsConcast(this.getObsQueryOptions());
141
+ this.previousData = ((_a = this.result) === null || _a === void 0 ? void 0 : _a.data) || this.previousData;
142
+ this.result = void 0;
143
+ this.forceUpdate();
144
+ return new Promise(function (resolve) {
145
+ var result;
146
+ concast.subscribe({
147
+ next: function (value) {
148
+ result = value;
149
+ },
150
+ error: function () {
151
+ resolve(_this.toQueryResult(_this.observable.getCurrentResult()));
152
+ },
153
+ complete: function () {
154
+ resolve(_this.toQueryResult(result));
155
+ }
156
+ });
145
157
  });
146
158
  };
147
159
  InternalState.prototype.useQuery = function (options) {
@@ -197,22 +209,15 @@ var InternalState = (function () {
197
209
  this.client.disableNetworkFetches,
198
210
  ]), function () { return _this.getCurrentResult(); }, function () { return _this.getCurrentResult(); });
199
211
  this.unsafeHandlePartialRefetch(result);
200
- var queryResult = this.toQueryResult(result);
201
- if (!queryResult.loading && this.asyncResolveFns.size) {
202
- this.asyncResolveFns.forEach(function (resolve) { return resolve(queryResult); });
203
- this.asyncResolveFns.clear();
204
- }
205
- return queryResult;
212
+ return this.toQueryResult(result);
206
213
  };
207
214
  InternalState.prototype.useOptions = function (options) {
208
215
  var _a;
209
216
  var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
210
217
  var currentWatchQueryOptions = this.watchQueryOptions;
211
- if (this.optionsToIgnoreOnce.has(currentWatchQueryOptions) ||
212
- !equality.equal(watchQueryOptions, currentWatchQueryOptions)) {
218
+ if (!equality.equal(watchQueryOptions, currentWatchQueryOptions)) {
213
219
  this.watchQueryOptions = watchQueryOptions;
214
220
  if (currentWatchQueryOptions && this.observable) {
215
- this.optionsToIgnoreOnce.delete(currentWatchQueryOptions);
216
221
  this.observable.reobserve(this.getObsQueryOptions());
217
222
  this.previousData = ((_a = this.result) === null || _a === void 0 ? void 0 : _a.data) || this.previousData;
218
223
  this.result = void 0;
@@ -379,11 +384,15 @@ var EAGER_METHODS = [
379
384
  'subscribeToMore',
380
385
  ];
381
386
  function useLazyQuery(query, options) {
382
- var _a, _b;
383
- var abortControllersRef = React.useRef(new Set());
387
+ var _a;
384
388
  var execOptionsRef = React.useRef();
385
- var merged = execOptionsRef.current ? utilities.mergeOptions(options, execOptionsRef.current) : options;
386
- var internalState = useInternalState(useApolloClient(options && options.client), (_b = (_a = execOptionsRef.current) === null || _a === void 0 ? void 0 : _a.query) !== null && _b !== void 0 ? _b : query);
389
+ var optionsRef = React.useRef();
390
+ var queryRef = React.useRef();
391
+ var merged = utilities.mergeOptions(options, execOptionsRef.current || {});
392
+ var document = (_a = merged === null || merged === void 0 ? void 0 : merged.query) !== null && _a !== void 0 ? _a : query;
393
+ optionsRef.current = merged;
394
+ queryRef.current = document;
395
+ var internalState = useInternalState(useApolloClient(options && options.client), document);
387
396
  var useQueryResult = internalState.useQuery(tslib.__assign(tslib.__assign({}, merged), { skip: !execOptionsRef.current }));
388
397
  var initialFetchPolicy = useQueryResult.observable.options.initialFetchPolicy ||
389
398
  internalState.getDefaultFetchPolicy();
@@ -409,28 +418,15 @@ function useLazyQuery(query, options) {
409
418
  return eagerMethods;
410
419
  }, []);
411
420
  Object.assign(result, eagerMethods);
412
- React.useEffect(function () {
413
- return function () {
414
- abortControllersRef.current.forEach(function (controller) {
415
- controller.abort();
416
- });
417
- };
418
- }, []);
419
421
  var execute = React.useCallback(function (executeOptions) {
420
- var controller = new AbortController();
421
- abortControllersRef.current.add(controller);
422
422
  execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
423
423
  fetchPolicy: initialFetchPolicy,
424
424
  };
425
+ var options = utilities.mergeOptions(optionsRef.current, tslib.__assign({ query: queryRef.current }, execOptionsRef.current));
425
426
  var promise = internalState
426
- .asyncUpdate(controller.signal)
427
- .then(function (queryResult) {
428
- abortControllersRef.current.delete(controller);
429
- return Object.assign(queryResult, eagerMethods);
430
- });
431
- promise.catch(function () {
432
- abortControllersRef.current.delete(controller);
433
- });
427
+ .executeQuery(tslib.__assign(tslib.__assign({}, options), { skip: false }))
428
+ .then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
429
+ promise.catch(function () { });
434
430
  return promise;
435
431
  }, []);
436
432
  return [execute, result];
@@ -732,42 +728,20 @@ function useStrictModeSafeCleanupEffect(cleanup) {
732
728
  }, []);
733
729
  }
734
730
 
735
- function isStatefulPromise(promise) {
736
- return 'status' in promise;
737
- }
738
- function wrapPromiseWithState(promise) {
739
- if (isStatefulPromise(promise)) {
740
- return promise;
741
- }
742
- var pendingPromise = promise;
743
- pendingPromise.status = 'pending';
744
- pendingPromise.then(function (value) {
745
- if (pendingPromise.status === 'pending') {
746
- var fulfilledPromise = pendingPromise;
747
- fulfilledPromise.status = 'fulfilled';
748
- fulfilledPromise.value = value;
749
- }
750
- }, function (reason) {
751
- if (pendingPromise.status === 'pending') {
752
- var rejectedPromise = pendingPromise;
753
- rejectedPromise.status = 'rejected';
754
- rejectedPromise.reason = reason;
731
+ var useKey = 'use';
732
+ var realHook = React__default[useKey];
733
+ var __use = realHook ||
734
+ function __use(promise) {
735
+ var statefulPromise = utilities.wrapPromiseWithState(promise);
736
+ switch (statefulPromise.status) {
737
+ case 'pending':
738
+ throw statefulPromise;
739
+ case 'rejected':
740
+ throw statefulPromise.reason;
741
+ case 'fulfilled':
742
+ return statefulPromise.value;
755
743
  }
756
- });
757
- return promise;
758
- }
759
-
760
- function __use(promise) {
761
- var statefulPromise = wrapPromiseWithState(promise);
762
- switch (statefulPromise.status) {
763
- case 'pending':
764
- throw statefulPromise;
765
- case 'rejected':
766
- throw statefulPromise.reason;
767
- case 'fulfilled':
768
- return statefulPromise.value;
769
- }
770
- }
744
+ };
771
745
 
772
746
  function useSuspenseCache(override) {
773
747
  var context$1 = React.useContext(context.getApolloContext());
@@ -785,9 +759,12 @@ function useSuspenseQuery_experimental(query, options) {
785
759
  var suspenseCache = useSuspenseCache(options.suspenseCache);
786
760
  var watchQueryOptions = useWatchQueryOptions({ query: query, options: options });
787
761
  var _a = watchQueryOptions.returnPartialData, returnPartialData = _a === void 0 ? false : _a, variables = watchQueryOptions.variables;
788
- var _b = options.suspensePolicy, suspensePolicy = _b === void 0 ? 'always' : _b;
762
+ var _b = options.suspensePolicy, suspensePolicy = _b === void 0 ? 'always' : _b, _c = options.queryKey, queryKey = _c === void 0 ? [] : _c;
789
763
  var shouldSuspend = suspensePolicy === 'always' || !didPreviouslySuspend.current;
790
- var subscription = suspenseCache.getSubscription(client, query, variables, function () { return client.watchQuery(watchQueryOptions); });
764
+ var cacheKey = [client, query, cache.canonicalStringify(variables)].concat(queryKey);
765
+ var subscription = suspenseCache.getSubscription(cacheKey, function () {
766
+ return client.watchQuery(watchQueryOptions);
767
+ });
791
768
  var dispose = useTrackedSubscriptions(subscription);
792
769
  useStrictModeSafeCleanupEffect(dispose);
793
770
  var result = useSyncExternalStore(subscription.listen, function () { return subscription.result; }, function () { return subscription.result; });
@@ -1,2 +1,4 @@
1
- export declare function __use<TValue>(promise: Promise<TValue>): TValue;
1
+ type Use = <T>(promise: Promise<T>) => T;
2
+ export declare const __use: Use;
3
+ export {};
2
4
  //# sourceMappingURL=__use.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"__use.d.ts","sourceRoot":"","sources":["../../../../src/react/hooks/internal/__use.ts"],"names":[],"mappings":"AAOA,wBAAgB,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,UAWrD"}
1
+ {"version":3,"file":"__use.d.ts","sourceRoot":"","sources":["../../../../src/react/hooks/internal/__use.ts"],"names":[],"mappings":"AAGA,KAAK,GAAG,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AASzC,eAAO,MAAM,KAAK,KAaf,CAAC"}
@@ -1,13 +1,17 @@
1
- import { wrapPromiseWithState } from "../../../utilities/promises/decoration.js";
2
- export function __use(promise) {
3
- var statefulPromise = wrapPromiseWithState(promise);
4
- switch (statefulPromise.status) {
5
- case 'pending':
6
- throw statefulPromise;
7
- case 'rejected':
8
- throw statefulPromise.reason;
9
- case 'fulfilled':
10
- return statefulPromise.value;
11
- }
12
- }
1
+ import { wrapPromiseWithState } from "../../../utilities/index.js";
2
+ import React from 'react';
3
+ var useKey = 'use';
4
+ var realHook = React[useKey];
5
+ export var __use = realHook ||
6
+ function __use(promise) {
7
+ var statefulPromise = wrapPromiseWithState(promise);
8
+ switch (statefulPromise.status) {
9
+ case 'pending':
10
+ throw statefulPromise;
11
+ case 'rejected':
12
+ throw statefulPromise.reason;
13
+ case 'fulfilled':
14
+ return statefulPromise.value;
15
+ }
16
+ };
13
17
  //# sourceMappingURL=__use.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"__use.js","sourceRoot":"","sources":["../../../../src/react/hooks/internal/__use.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAO9E,MAAM,UAAU,KAAK,CAAS,OAAwB;IACpD,IAAM,eAAe,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAEtD,QAAQ,eAAe,CAAC,MAAM,EAAE;QAC9B,KAAK,SAAS;YACZ,MAAM,eAAe,CAAC;QACxB,KAAK,UAAU;YACb,MAAM,eAAe,CAAC,MAAM,CAAC;QAC/B,KAAK,WAAW;YACd,OAAO,eAAe,CAAC,KAAK,CAAC;KAChC;AACH,CAAC","sourcesContent":["import { wrapPromiseWithState } from '../../../utilities/promises/decoration';\n\n// TODO: Replace the use of this with React's use once its available. For now,\n// this mimics its functionality for promises by adding\n// properties to the promise instance and reading them synchronously. This is\n// named with two underscores to allow this hook to evade typical rules of\n// hooks (i.e. it can be used conditionally)\nexport function __use<TValue>(promise: Promise<TValue>) {\n const statefulPromise = wrapPromiseWithState(promise);\n\n switch (statefulPromise.status) {\n case 'pending':\n throw statefulPromise;\n case 'rejected':\n throw statefulPromise.reason;\n case 'fulfilled':\n return statefulPromise.value;\n }\n}\n"]}
1
+ {"version":3,"file":"__use.js","sourceRoot":"","sources":["../../../../src/react/hooks/internal/__use.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,MAAM,OAAO,CAAC;AAM1B,IAAM,MAAM,GAAG,KAA2B,CAAC;AAC3C,IAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAoB,CAAC;AAIlD,MAAM,CAAC,IAAM,KAAK,GAChB,QAAQ;IACR,SAAS,KAAK,CAAS,OAAwB;QAC7C,IAAM,eAAe,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAEtD,QAAQ,eAAe,CAAC,MAAM,EAAE;YAC9B,KAAK,SAAS;gBACZ,MAAM,eAAe,CAAC;YACxB,KAAK,UAAU;gBACb,MAAM,eAAe,CAAC,MAAM,CAAC;YAC/B,KAAK,WAAW;gBACd,OAAO,eAAe,CAAC,KAAK,CAAC;SAChC;IACH,CAAC,CAAC","sourcesContent":["import { wrapPromiseWithState } from '../../../utilities';\nimport React from 'react';\n\ntype Use = <T>(promise: Promise<T>) => T;\n// Prevent webpack from complaining about our feature detection of the\n// use property of the React namespace, which is expected not\n// to exist when using current stable versions, and that's fine.\nconst useKey = 'use' as keyof typeof React;\nconst realHook = React[useKey] as Use | undefined;\n\n// This is named with two underscores to allow this hook to evade typical rules of\n// hooks (i.e. it can be used conditionally)\nexport const __use =\n realHook ||\n function __use<TValue>(promise: Promise<TValue>) {\n const statefulPromise = wrapPromiseWithState(promise);\n\n switch (statefulPromise.status) {\n case 'pending':\n throw statefulPromise;\n case 'rejected':\n throw statefulPromise.reason;\n case 'fulfilled':\n return statefulPromise.value;\n }\n };\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"useLazyQuery.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useLazyQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAGtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,EAEL,oBAAoB,EACpB,oBAAoB,EACpB,OAAO,EAER,MAAM,gBAAgB,CAAC;AAexB,wBAAgB,YAAY,CAAC,KAAK,GAAG,GAAG,EAAE,UAAU,SAAS,kBAAkB,GAAG,kBAAkB,EAClG,KAAK,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,EAC1D,OAAO,CAAC,EAAE,oBAAoB,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,GAClE,oBAAoB,CAAC,KAAK,EAAE,UAAU,CAAC,CAkFzC"}
1
+ {"version":3,"file":"useLazyQuery.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useLazyQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAGtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,EAEL,oBAAoB,EACpB,oBAAoB,EACpB,OAAO,EAER,MAAM,gBAAgB,CAAC;AAexB,wBAAgB,YAAY,CAAC,KAAK,GAAG,GAAG,EAAE,UAAU,SAAS,kBAAkB,GAAG,kBAAkB,EAClG,KAAK,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,EAC1D,OAAO,CAAC,EAAE,oBAAoB,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,GAClE,oBAAoB,CAAC,KAAK,EAAE,UAAU,CAAC,CA8EzC"}
@@ -1,5 +1,5 @@
1
1
  import { __assign } from "tslib";
2
- import { useCallback, useEffect, useMemo, useRef } from 'react';
2
+ import { useCallback, useMemo, useRef } from 'react';
3
3
  import { mergeOptions } from "../../utilities/index.js";
4
4
  import { useInternalState } from "./useQuery.js";
5
5
  import { useApolloClient } from "./useApolloClient.js";
@@ -12,11 +12,15 @@ var EAGER_METHODS = [
12
12
  'subscribeToMore',
13
13
  ];
14
14
  export function useLazyQuery(query, options) {
15
- var _a, _b;
16
- var abortControllersRef = useRef(new Set());
15
+ var _a;
17
16
  var execOptionsRef = useRef();
18
- var merged = execOptionsRef.current ? mergeOptions(options, execOptionsRef.current) : options;
19
- var internalState = useInternalState(useApolloClient(options && options.client), (_b = (_a = execOptionsRef.current) === null || _a === void 0 ? void 0 : _a.query) !== null && _b !== void 0 ? _b : query);
17
+ var optionsRef = useRef();
18
+ var queryRef = useRef();
19
+ var merged = mergeOptions(options, execOptionsRef.current || {});
20
+ var document = (_a = merged === null || merged === void 0 ? void 0 : merged.query) !== null && _a !== void 0 ? _a : query;
21
+ optionsRef.current = merged;
22
+ queryRef.current = document;
23
+ var internalState = useInternalState(useApolloClient(options && options.client), document);
20
24
  var useQueryResult = internalState.useQuery(__assign(__assign({}, merged), { skip: !execOptionsRef.current }));
21
25
  var initialFetchPolicy = useQueryResult.observable.options.initialFetchPolicy ||
22
26
  internalState.getDefaultFetchPolicy();
@@ -42,28 +46,15 @@ export function useLazyQuery(query, options) {
42
46
  return eagerMethods;
43
47
  }, []);
44
48
  Object.assign(result, eagerMethods);
45
- useEffect(function () {
46
- return function () {
47
- abortControllersRef.current.forEach(function (controller) {
48
- controller.abort();
49
- });
50
- };
51
- }, []);
52
49
  var execute = useCallback(function (executeOptions) {
53
- var controller = new AbortController();
54
- abortControllersRef.current.add(controller);
55
50
  execOptionsRef.current = executeOptions ? __assign(__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
56
51
  fetchPolicy: initialFetchPolicy,
57
52
  };
53
+ var options = mergeOptions(optionsRef.current, __assign({ query: queryRef.current }, execOptionsRef.current));
58
54
  var promise = internalState
59
- .asyncUpdate(controller.signal)
60
- .then(function (queryResult) {
61
- abortControllersRef.current.delete(controller);
62
- return Object.assign(queryResult, eagerMethods);
63
- });
64
- promise.catch(function () {
65
- abortControllersRef.current.delete(controller);
66
- });
55
+ .executeQuery(__assign(__assign({}, options), { skip: false }))
56
+ .then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
57
+ promise.catch(function () { });
67
58
  return promise;
68
59
  }, []);
69
60
  return [execute, result];
@@ -1 +1 @@
1
- {"version":3,"file":"useLazyQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useLazyQuery.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAGhE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAQ/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAIpD,IAAM,aAAa,GAAG;IACpB,SAAS;IACT,WAAW;IACX,WAAW;IACX,aAAa;IACb,cAAc;IACd,iBAAiB;CACT,CAAC;AAEX,MAAM,UAAU,YAAY,CAC1B,KAA0D,EAC1D,OAAmE;;IAEnE,IAAM,mBAAmB,GAAG,MAAM,CAAC,IAAI,GAAG,EAAmB,CAAC,CAAC;IAE/D,IAAM,cAAc,GAAG,MAAM,EAAwD,CAAC;IACtF,IAAM,MAAM,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,OAAO,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAEhG,IAAM,aAAa,GAAG,gBAAgB,CACpC,eAAe,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,EAC1C,MAAA,MAAA,cAAc,C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AE,CAAC,CAAA;IAEN,IAAM,OAAO,GAAG,WAAW,CAEzB,UAAA,cAAc;QACd,IAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;QACzC,mBAAmB,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAE5C,cAAc,CAAC,OAAO,GAAG,cAAc,CAAC,CAAC,uBACpC,cAAc,KACjB,WAAW,EAAE,cAAc,CAAC,WAAW,IAAI,kBAAkB,IAC7D,CAAC,CAAC;YACF,WAAW,EAAE,kBAAkB;SAChC,CAAC;QAEF,IAAM,OAAO,GAAG,aAAa;aAC1B,WAAW,CAAC,UAAU,CAAC,MAAM,CAAC;aAC9B,IAAI,CAAC,UAAA,WAAW;YACf,mBAAmB,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;YAE/C,OAAO,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;QAEL,OAAO,CAAC,KAAK,CAAC;YACZ,mBAAmB,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACjD,CAAC,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC;IACjB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import { DocumentNode } from 'graphql';\nimport { TypedDocumentNode } from '@graphql-typed-document-node/core';\nimport { useCallback, useEffect, useMemo, useRef } from 'react';\n\nimport { OperationVariables } from '../../core';\nimport { mergeOptions } from '../../utilities';\nimport {\n LazyQueryHookExecOptions,\n LazyQueryHookOptions,\n LazyQueryResultTuple,\n NoInfer,\n QueryResult,\n} from '../types/types';\nimport { useInternalState } from './useQuery';\nimport { useApolloClient } from './useApolloClient';\n\n// The following methods, when called will execute the query, regardless of\n// whether the useLazyQuery execute function was called before.\nconst EAGER_METHODS = [\n 'refetch',\n 'reobserve',\n 'fetchMore',\n 'updateQuery',\n 'startPolling',\n 'subscribeToMore',\n] as const;\n\nexport function useLazyQuery<TData = any, TVariables extends OperationVariables = OperationVariables>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: LazyQueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>\n): LazyQueryResultTuple<TData, TVariables> {\n const abortControllersRef = useRef(new Set<AbortController>());\n\n const execOptionsRef = useRef<Partial<LazyQueryHookExecOptions<TData, TVariables>>>();\n const merged = execOptionsRef.current ? mergeOptions(options, execOptionsRef.current) : options;\n\n const internalState = useInternalState<TData, TVariables>(\n useApolloClient(options && options.client),\n execOptionsRef.current?.query ?? query\n );\n\n const useQueryResult = internalState.useQuery({\n ...merged,\n skip: !execOptionsRef.current,\n });\n\n const initialFetchPolicy =\n useQueryResult.observable.options.initialFetchPolicy ||\n internalState.getDefaultFetchPolicy();\n\n const result: QueryResult<TData, TVariables> =\n Object.assign(useQueryResult, {\n called: !!execOptionsRef.current,\n });\n\n // We use useMemo here to make sure the eager methods have a stable identity.\n const eagerMethods = useMemo(() => {\n const eagerMethods: Record<string, any> = {};\n for (const key of EAGER_METHODS) {\n const method = result[key];\n eagerMethods[key] = function () {\n if (!execOptionsRef.current) {\n execOptionsRef.current = Object.create(null);\n // Only the first time populating execOptionsRef.current matters here.\n internalState.forceUpdate();\n }\n return method.apply(this, arguments);\n };\n }\n\n return eagerMethods;\n }, []);\n\n Object.assign(result, eagerMethods);\n\n useEffect(() => {\n return () => {\n abortControllersRef.current.forEach((controller) => {\n controller.abort();\n });\n }\n }, [])\n\n const execute = useCallback<\n LazyQueryResultTuple<TData, TVariables>[0]\n >(executeOptions => {\n const controller = new AbortController();\n abortControllersRef.current.add(controller);\n\n execOptionsRef.current = executeOptions ? {\n ...executeOptions,\n fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy,\n } : {\n fetchPolicy: initialFetchPolicy,\n };\n\n const promise = internalState\n .asyncUpdate(controller.signal) // Like internalState.forceUpdate, but returns a Promise.\n .then(queryResult => {\n abortControllersRef.current.delete(controller);\n\n return Object.assign(queryResult, eagerMethods);\n });\n\n promise.catch(() => {\n abortControllersRef.current.delete(controller);\n });\n\n return promise;\n }, []);\n\n return [execute, result];\n}\n"]}
1
+ {"version":3,"file":"useLazyQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useLazyQuery.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAGrD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAQ/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAIpD,IAAM,aAAa,GAAG;IACpB,SAAS;IACT,WAAW;IACX,WAAW;IACX,aAAa;IACb,cAAc;IACd,iBAAiB;CACT,CAAC;AAEX,MAAM,UAAU,YAAY,CAC1B,KAA0D,EAC1D,OAAmE;;IAEnE,IAAM,cAAc,GAAG,MAAM,EAAwD,CAAC;IACtF,IAAM,UAAU,GAAG,MAAM,EAA2C,CAAC;IACrE,IAAM,QAAQ,GAAG,MAAM,EAAuD,CAAC;IAC/E,IAAM,MAAM,GAAG,YAAY,CAAC,OAAO,EAAE,cAAc,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;IACnE,IAAM,QAAQ,GAAG,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,mCAAI,KAAK,CAAC;IAIxC,UAAU,CAAC,OAAO,GAAG,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC;IAE5B,IAAM,aAAa,GAAG,gBAAgB,CACpC,eAAe,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,EAC1C,QAAQ,CACT,CAAC;IAEF,IAAM,cAAc,GAAG,aAAa,CAAC,QAAQ,uBACxC,MAAM,KACT,IAAI,EAAE,CAAC,cAAc,CAAC,OAAO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AAO,EACzB,CAAA;QAEF,IAAM,OAAO,GAAG,aAAa;aAC1B,YAAY,uBAAM,OAAO,KAAE,IAAI,EAAE,KAAK,IAAG;aACzC,IAAI,CAAC,UAAC,WAAW,IAAK,OAAA,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,YAAY,CAAC,EAAxC,CAAwC,CAAC,CAAC;QAInE,OAAO,CAAC,KAAK,CAAC,cAAO,CAAC,CAAC,CAAC;QAExB,OAAO,OAAO,CAAC;IACjB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import { DocumentNode } from 'graphql';\nimport { TypedDocumentNode } from '@graphql-typed-document-node/core';\nimport { useCallback, useMemo, useRef } from 'react';\n\nimport { OperationVariables } from '../../core';\nimport { mergeOptions } from '../../utilities';\nimport {\n LazyQueryHookExecOptions,\n LazyQueryHookOptions,\n LazyQueryResultTuple,\n NoInfer,\n QueryResult,\n} from '../types/types';\nimport { useInternalState } from './useQuery';\nimport { useApolloClient } from './useApolloClient';\n\n// The following methods, when called will execute the query, regardless of\n// whether the useLazyQuery execute function was called before.\nconst EAGER_METHODS = [\n 'refetch',\n 'reobserve',\n 'fetchMore',\n 'updateQuery',\n 'startPolling',\n 'subscribeToMore',\n] as const;\n\nexport function useLazyQuery<TData = any, TVariables extends OperationVariables = OperationVariables>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: LazyQueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>\n): LazyQueryResultTuple<TData, TVariables> {\n const execOptionsRef = useRef<Partial<LazyQueryHookExecOptions<TData, TVariables>>>();\n const optionsRef = useRef<LazyQueryHookOptions<TData, TVariables>>();\n const queryRef = useRef<DocumentNode | TypedDocumentNode<TData, TVariables>>();\n const merged = mergeOptions(options, execOptionsRef.current || {});\n const document = merged?.query ?? query;\n\n // Use refs to track options and the used query to ensure the `execute` \n // function remains referentially stable between renders.\n optionsRef.current = merged;\n queryRef.current = document;\n\n const internalState = useInternalState<TData, TVariables>(\n useApolloClient(options && options.client),\n document\n );\n\n const useQueryResult = internalState.useQuery({\n ...merged,\n skip: !execOptionsRef.current,\n });\n\n const initialFetchPolicy =\n useQueryResult.observable.options.initialFetchPolicy ||\n internalState.getDefaultFetchPolicy();\n\n const result: QueryResult<TData, TVariables> =\n Object.assign(useQueryResult, {\n called: !!execOptionsRef.current,\n });\n\n // We use useMemo here to make sure the eager methods have a stable identity.\n const eagerMethods = useMemo(() => {\n const eagerMethods: Record<string, any> = {};\n for (const key of EAGER_METHODS) {\n const method = result[key];\n eagerMethods[key] = function () {\n if (!execOptionsRef.current) {\n execOptionsRef.current = Object.create(null);\n // Only the first time populating execOptionsRef.current matters here.\n internalState.forceUpdate();\n }\n return method.apply(this, arguments);\n };\n }\n\n return eagerMethods;\n }, []);\n\n Object.assign(result, eagerMethods);\n\n const execute = useCallback<\n LazyQueryResultTuple<TData, TVariables>[0]\n >(executeOptions => {\n execOptionsRef.current = executeOptions ? {\n ...executeOptions,\n fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy,\n } : {\n fetchPolicy: initialFetchPolicy,\n };\n\n const options = mergeOptions(optionsRef.current, {\n query: queryRef.current,\n ...execOptionsRef.current,\n })\n\n const promise = internalState\n .executeQuery({ ...options, skip: false })\n .then((queryResult) => Object.assign(queryResult, eagerMethods));\n\n // Because the return value of `useLazyQuery` is usually floated, we need\n // to catch the promise to prevent unhandled rejections.\n promise.catch(() => {});\n\n return promise;\n }, []);\n\n return [execute, result];\n}\n"]}
@@ -9,9 +9,9 @@ declare class InternalState<TData, TVariables extends OperationVariables> {
9
9
  readonly query: DocumentNode | TypedDocumentNode<TData, TVariables>;
10
10
  constructor(client: ReturnType<typeof useApolloClient>, query: DocumentNode | TypedDocumentNode<TData, TVariables>, previous?: InternalState<TData, TVariables>);
11
11
  forceUpdate(): void;
12
- asyncUpdate(signal: AbortSignal): Promise<QueryResult<TData, TVariables>>;
13
- private asyncResolveFns;
14
- private optionsToIgnoreOnce;
12
+ executeQuery(options: QueryHookOptions<TData, TVariables> & {
13
+ query?: DocumentNode;
14
+ }): Promise<QueryResult<TData, TVariables>>;
15
15
  useQuery(options: QueryHookOptions<TData, TVariables>): QueryResult<TData, TVariables>;
16
16
  private renderPromises;
17
17
  private queryHookOptions;
@@ -1 +1 @@
1
- {"version":3,"file":"useQuery.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useQuery.ts"],"names":[],"mappings":"AAYA,OAAO,EAAgB,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAGrF,OAAO,EACL,YAAY,EACZ,iBAAiB,EAGjB,YAAY,EACZ,iBAAiB,EAElB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,gBAAgB,EAChB,WAAW,EAEX,OAAO,EACR,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AASpD,wBAAgB,QAAQ,CACtB,KAAK,GAAG,GAAG,EACX,UAAU,SAAS,kBAAkB,GAAG,kBAAkB,EAE1D,KAAK,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,EAC1D,OAAO,GAAE,gBAAgB,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAuB,GACnF,WAAW,CAAC,KAAK,EAAE,UAAU,CAAC,CAKhC;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,SAAS,kBAAkB,EAC3E,MAAM,EAAE,YAAY,CAAC,GAAG,CAAC,EACzB,KAAK,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,GACzD,aAAa,CAAC,KAAK,EAAE,UAAU,CAAC,CAuBlC;AAED,cAAM,aAAa,CAAC,KAAK,EAAE,UAAU,SAAS,kBAAkB;aAE5C,MAAM,EAAE,UAAU,CAAC,OAAO,eAAe,CAAC;aAC1C,KAAK,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,CAAC,OAAO,EAAE,gBAAgB,CAAC,KAAK,EAAE,UAAU,CAAC,GAAG;QAC1D,KAAK,CAAC,EAAE,YAAY,CAAC;KACtB;IA4CD,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAC,KAAK,EAAE,UAAU,CAAC;IA6GrD,OAAO,CAAC,cAAc,CAAuC;IAC7D,OAAO,CAAC,gBAAgB,CAAsC;IAC9D,OAAO,CAAC,iBAAiB,CAAuC;IAEhE,OAAO,CAAC,UAAU;IA0ElB,OAAO,CAAC,kBAAkB;IAgC1B,OAAO,CAAC,iBAAiB,CAKtB;IAEH,OAAO,CAAC,iBAAiB,CAKtB;IAGH,OAAO,CAAC,uBAAuB;IAsD/B,qBAAqB,IAAI,qBAAqB;IAW9C,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,OAAO;IAEf,OAAO,CAAC,UAAU,CAAqC;IACvD,OAAO,CAAC,cAAc,CAGpB;IAEF,OAAO,CAAC,kBAAkB;IAuC1B,OAAO,CAAC,MAAM,CAAuC;IACrD,OAAO,CAAC,YAAY,CAAoB;IAExC,OAAO,CAAC,SAAS;IAYjB,OAAO,CAAC,sBAAsB;IAwB9B,OAAO,CAAC,aAAa;IAMrB,OAAO,CAAC,gBAAgB;IAexB,OAAO,CAAC,kBAAkB,CAGtB;IAEJ,aAAa,CACX,MAAM,EAAE,iBAAiB,CAAC,KAAK,CAAC,GAC/B,WAAW,CAAC,KAAK,EAAE,UAAU,CAAC;IA2BjC,OAAO,CAAC,0BAA0B;CAoBnC"}
@@ -9,7 +9,7 @@ import { ApolloError } from "../../errors/index.js";
9
9
  import { NetworkStatus, } from "../../core/index.js";
10
10
  import { DocumentType, verifyDocumentType } from "../parser/index.js";
11
11
  import { useApolloClient } from "./useApolloClient.js";
12
- import { canUseWeakMap, canUseWeakSet, compact, isNonEmptyArray, maybeDeepFreeze } from "../../utilities/index.js";
12
+ import { canUseWeakMap, compact, isNonEmptyArray, maybeDeepFreeze } from "../../utilities/index.js";
13
13
  var hasOwnProperty = Object.prototype.hasOwnProperty;
14
14
  export function useQuery(query, options) {
15
15
  if (options === void 0) { options = Object.create(null); }
@@ -33,8 +33,6 @@ var InternalState = (function () {
33
33
  function InternalState(client, query, previous) {
34
34
  this.client = client;
35
35
  this.query = query;
36
- this.asyncResolveFns = new Set();
37
- this.optionsToIgnoreOnce = new (canUseWeakSet ? WeakSet : Set)();
38
36
  this.ssrDisabledResult = maybeDeepFreeze({
39
37
  loading: true,
40
38
  data: void 0,
@@ -58,20 +56,30 @@ var InternalState = (function () {
58
56
  InternalState.prototype.forceUpdate = function () {
59
57
  __DEV__ && invariant.warn("Calling default no-op implementation of InternalState#forceUpdate");
60
58
  };
61
- InternalState.prototype.asyncUpdate = function (signal) {
59
+ InternalState.prototype.executeQuery = function (options) {
62
60
  var _this = this;
63
- return new Promise(function (resolve, reject) {
64
- var watchQueryOptions = _this.watchQueryOptions;
65
- var handleAborted = function () {
66
- _this.asyncResolveFns.delete(resolve);
67
- _this.optionsToIgnoreOnce.delete(watchQueryOptions);
68
- signal.removeEventListener('abort', handleAborted);
69
- reject(signal.reason);
70
- };
71
- _this.asyncResolveFns.add(resolve);
72
- _this.optionsToIgnoreOnce.add(watchQueryOptions);
73
- signal.addEventListener('abort', handleAborted);
74
- _this.forceUpdate();
61
+ var _a;
62
+ if (options.query) {
63
+ Object.assign(this, { query: options.query });
64
+ }
65
+ this.watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
66
+ var concast = this.observable.reobserveAsConcast(this.getObsQueryOptions());
67
+ this.previousData = ((_a = this.result) === null || _a === void 0 ? void 0 : _a.data) || this.previousData;
68
+ this.result = void 0;
69
+ this.forceUpdate();
70
+ return new Promise(function (resolve) {
71
+ var result;
72
+ concast.subscribe({
73
+ next: function (value) {
74
+ result = value;
75
+ },
76
+ error: function () {
77
+ resolve(_this.toQueryResult(_this.observable.getCurrentResult()));
78
+ },
79
+ complete: function () {
80
+ resolve(_this.toQueryResult(result));
81
+ }
82
+ });
75
83
  });
76
84
  };
77
85
  InternalState.prototype.useQuery = function (options) {
@@ -127,22 +135,15 @@ var InternalState = (function () {
127
135
  this.client.disableNetworkFetches,
128
136
  ]), function () { return _this.getCurrentResult(); }, function () { return _this.getCurrentResult(); });
129
137
  this.unsafeHandlePartialRefetch(result);
130
- var queryResult = this.toQueryResult(result);
131
- if (!queryResult.loading && this.asyncResolveFns.size) {
132
- this.asyncResolveFns.forEach(function (resolve) { return resolve(queryResult); });
133
- this.asyncResolveFns.clear();
134
- }
135
- return queryResult;
138
+ return this.toQueryResult(result);
136
139
  };
137
140
  InternalState.prototype.useOptions = function (options) {
138
141
  var _a;
139
142
  var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
140
143
  var currentWatchQueryOptions = this.watchQueryOptions;
141
- if (this.optionsToIgnoreOnce.has(currentWatchQueryOptions) ||
142
- !equal(watchQueryOptions, currentWatchQueryOptions)) {
144
+ if (!equal(watchQueryOptions, currentWatchQueryOptions)) {
143
145
  this.watchQueryOptions = watchQueryOptions;
144
146
  if (currentWatchQueryOptions && this.observable) {
145
- this.optionsToIgnoreOnce.delete(currentWatchQueryOptions);
146
147
  this.observable.reobserve(this.getObsQueryOptions());
147
148
  this.previousData = ((_a = this.result) === null || _a === void 0 ? void 0 : _a.data) || this.previousData;
148
149
  this.result = void 0;