@apollo/client 3.8.0-alpha.4 → 3.8.0-alpha.6

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 (307) hide show
  1. package/README.md +2 -0
  2. package/apollo-client.cjs +190 -86
  3. package/apollo-client.cjs.map +1 -1
  4. package/apollo-client.min.cjs +1 -1
  5. package/cache/cache.cjs +20 -20
  6. package/cache/cache.cjs.map +1 -1
  7. package/cache/cache.cjs.native.js +20 -20
  8. package/cache/core/cache.d.ts +1 -1
  9. package/cache/core/cache.d.ts.map +1 -1
  10. package/cache/core/cache.js.map +1 -1
  11. package/cache/core/types/common.d.ts +7 -7
  12. package/cache/core/types/common.d.ts.map +1 -1
  13. package/cache/inmemory/entityStore.d.ts +1 -1
  14. package/cache/inmemory/entityStore.d.ts.map +1 -1
  15. package/cache/inmemory/entityStore.js +1 -1
  16. package/cache/inmemory/helpers.js.map +1 -1
  17. package/cache/inmemory/inMemoryCache.d.ts +3 -2
  18. package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
  19. package/cache/inmemory/inMemoryCache.js +1 -1
  20. package/cache/inmemory/inMemoryCache.js.map +1 -1
  21. package/cache/inmemory/key-extractor.js +1 -1
  22. package/cache/inmemory/object-canon.d.ts +0 -1
  23. package/cache/inmemory/object-canon.d.ts.map +1 -1
  24. package/cache/inmemory/object-canon.js +1 -1
  25. package/cache/inmemory/object-canon.js.map +1 -1
  26. package/cache/inmemory/policies.d.ts +12 -12
  27. package/cache/inmemory/policies.d.ts.map +1 -1
  28. package/cache/inmemory/policies.js +1 -1
  29. package/cache/inmemory/policies.js.map +1 -1
  30. package/cache/inmemory/reactiveVars.d.ts +1 -1
  31. package/cache/inmemory/reactiveVars.d.ts.map +1 -1
  32. package/cache/inmemory/readFromStore.d.ts +2 -2
  33. package/cache/inmemory/readFromStore.d.ts.map +1 -1
  34. package/cache/inmemory/readFromStore.js +1 -1
  35. package/cache/inmemory/readFromStore.js.map +1 -1
  36. package/cache/inmemory/types.d.ts +4 -4
  37. package/cache/inmemory/types.d.ts.map +1 -1
  38. package/cache/inmemory/writeToStore.d.ts +1 -1
  39. package/cache/inmemory/writeToStore.d.ts.map +1 -1
  40. package/cache/inmemory/writeToStore.js +1 -1
  41. package/cache/inmemory/writeToStore.js.map +1 -1
  42. package/core/ApolloClient.d.ts +5 -5
  43. package/core/ApolloClient.d.ts.map +1 -1
  44. package/core/ApolloClient.js +1 -1
  45. package/core/ApolloClient.js.map +1 -1
  46. package/core/LocalState.d.ts +9 -6
  47. package/core/LocalState.d.ts.map +1 -1
  48. package/core/LocalState.js +65 -15
  49. package/core/LocalState.js.map +1 -1
  50. package/core/ObservableQuery.d.ts +5 -5
  51. package/core/ObservableQuery.d.ts.map +1 -1
  52. package/core/ObservableQuery.js +2 -2
  53. package/core/ObservableQuery.js.map +1 -1
  54. package/core/QueryInfo.d.ts +1 -1
  55. package/core/QueryInfo.d.ts.map +1 -1
  56. package/core/QueryInfo.js +1 -1
  57. package/core/QueryInfo.js.map +1 -1
  58. package/core/QueryManager.d.ts +7 -7
  59. package/core/QueryManager.d.ts.map +1 -1
  60. package/core/QueryManager.js +19 -11
  61. package/core/QueryManager.js.map +1 -1
  62. package/core/core.cjs +113 -62
  63. package/core/core.cjs.map +1 -1
  64. package/core/core.cjs.native.js +113 -62
  65. package/core/index.js +2 -2
  66. package/core/index.js.map +1 -1
  67. package/core/types.d.ts +18 -17
  68. package/core/types.d.ts.map +1 -1
  69. package/core/types.js +1 -0
  70. package/core/types.js.map +1 -1
  71. package/core/watchQueryOptions.d.ts +11 -11
  72. package/core/watchQueryOptions.d.ts.map +1 -1
  73. package/core/watchQueryOptions.js.map +1 -1
  74. package/errors/index.d.ts +2 -2
  75. package/errors/index.d.ts.map +1 -1
  76. package/invariantErrorCodes.js +33 -33
  77. package/link/batch/batch.cjs +5 -3
  78. package/link/batch/batch.cjs.map +1 -1
  79. package/link/batch/batch.cjs.native.js +5 -3
  80. package/link/batch/batching.d.ts +2 -2
  81. package/link/batch/batching.d.ts.map +1 -1
  82. package/link/batch/batching.js +5 -3
  83. package/link/batch/batching.js.map +1 -1
  84. package/link/context/index.d.ts +2 -1
  85. package/link/context/index.d.ts.map +1 -1
  86. package/link/context/index.js.map +1 -1
  87. package/link/core/ApolloLink.js +2 -2
  88. package/link/core/core.cjs +2 -2
  89. package/link/core/core.cjs.map +1 -1
  90. package/link/core/core.cjs.native.js +2 -2
  91. package/link/core/types.d.ts +13 -12
  92. package/link/core/types.d.ts.map +1 -1
  93. package/link/core/types.js.map +1 -1
  94. package/link/http/checkFetcher.js +2 -2
  95. package/link/http/createHttpLink.d.ts +0 -1
  96. package/link/http/createHttpLink.d.ts.map +1 -1
  97. package/link/http/createHttpLink.js +2 -1
  98. package/link/http/createHttpLink.js.map +1 -1
  99. package/link/http/http.cjs +13 -38
  100. package/link/http/http.cjs.map +1 -1
  101. package/link/http/http.cjs.native.js +13 -38
  102. package/link/http/iterators/async.js.map +1 -1
  103. package/link/http/iterators/nodeStream.js.map +1 -1
  104. package/link/http/iterators/promise.js.map +1 -1
  105. package/link/http/iterators/reader.js.map +1 -1
  106. package/link/http/parseAndCheckHttpResponse.d.ts +2 -2
  107. package/link/http/parseAndCheckHttpResponse.d.ts.map +1 -1
  108. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  109. package/link/http/responseIterator.js +1 -1
  110. package/link/http/responseIterator.js.map +1 -1
  111. package/link/http/selectHttpOptionsAndBody.d.ts +2 -2
  112. package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
  113. package/link/http/selectHttpOptionsAndBody.js +3 -1
  114. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  115. package/link/http/serializeFetchParameter.d.ts +1 -1
  116. package/link/http/serializeFetchParameter.d.ts.map +1 -1
  117. package/link/http/serializeFetchParameter.js +2 -2
  118. package/link/persisted-queries/index.d.ts +2 -2
  119. package/link/persisted-queries/index.d.ts.map +1 -1
  120. package/link/persisted-queries/index.js +3 -3
  121. package/link/persisted-queries/persisted-queries.cjs +3 -3
  122. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  123. package/link/persisted-queries/persisted-queries.cjs.native.js +3 -3
  124. package/link/utils/throwServerError.d.ts +1 -1
  125. package/link/utils/throwServerError.d.ts.map +1 -1
  126. package/link/utils/toPromise.js +1 -1
  127. package/link/utils/utils.cjs +2 -2
  128. package/link/utils/utils.cjs.map +1 -1
  129. package/link/utils/utils.cjs.native.js +2 -2
  130. package/link/utils/validateOperation.js +2 -2
  131. package/package.json +15 -15
  132. package/react/cache/SuspenseCache.d.ts +1 -1
  133. package/react/cache/SuspenseCache.d.ts.map +1 -1
  134. package/react/cache/SuspenseCache.js.map +1 -1
  135. package/react/components/Query.d.ts +2 -2
  136. package/react/components/Query.d.ts.map +1 -1
  137. package/react/components/Query.js.map +1 -1
  138. package/react/components/Subscription.d.ts +2 -2
  139. package/react/components/Subscription.d.ts.map +1 -1
  140. package/react/components/Subscription.js.map +1 -1
  141. package/react/components/types.d.ts +2 -2
  142. package/react/components/types.d.ts.map +1 -1
  143. package/react/components/types.js.map +1 -1
  144. package/react/context/ApolloConsumer.js +2 -2
  145. package/react/context/ApolloProvider.js +2 -2
  146. package/react/context/context.cjs +4 -4
  147. package/react/context/context.cjs.map +1 -1
  148. package/react/context/context.cjs.native.js +4 -4
  149. package/react/hoc/graphql.d.ts +2 -1
  150. package/react/hoc/graphql.d.ts.map +1 -1
  151. package/react/hoc/graphql.js.map +1 -1
  152. package/react/hoc/hoc-utils.d.ts +1 -1
  153. package/react/hoc/hoc-utils.d.ts.map +1 -1
  154. package/react/hoc/hoc-utils.js +2 -2
  155. package/react/hoc/hoc.cjs +4 -4
  156. package/react/hoc/hoc.cjs.map +1 -1
  157. package/react/hoc/hoc.cjs.native.js +4 -4
  158. package/react/hoc/mutation-hoc.d.ts +2 -2
  159. package/react/hoc/mutation-hoc.d.ts.map +1 -1
  160. package/react/hoc/mutation-hoc.js.map +1 -1
  161. package/react/hoc/query-hoc.d.ts +1 -1
  162. package/react/hoc/query-hoc.d.ts.map +1 -1
  163. package/react/hoc/query-hoc.js.map +1 -1
  164. package/react/hoc/subscription-hoc.d.ts +1 -1
  165. package/react/hoc/subscription-hoc.d.ts.map +1 -1
  166. package/react/hoc/subscription-hoc.js.map +1 -1
  167. package/react/hoc/types.d.ts +6 -6
  168. package/react/hoc/types.d.ts.map +1 -1
  169. package/react/hoc/types.js.map +1 -1
  170. package/react/hoc/withApollo.js +2 -2
  171. package/react/hooks/hooks.cjs +65 -46
  172. package/react/hooks/hooks.cjs.map +1 -1
  173. package/react/hooks/hooks.cjs.native.js +65 -46
  174. package/react/hooks/internal/useIsomorphicLayoutEffect.js +1 -1
  175. package/react/hooks/internal/useIsomorphicLayoutEffect.js.map +1 -1
  176. package/react/hooks/useApolloClient.js +2 -2
  177. package/react/hooks/useFragment.d.ts +2 -1
  178. package/react/hooks/useFragment.d.ts.map +1 -1
  179. package/react/hooks/useFragment.js +9 -8
  180. package/react/hooks/useFragment.js.map +1 -1
  181. package/react/hooks/useLazyQuery.d.ts +1 -1
  182. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  183. package/react/hooks/useLazyQuery.js +22 -8
  184. package/react/hooks/useLazyQuery.js.map +1 -1
  185. package/react/hooks/useMutation.d.ts.map +1 -1
  186. package/react/hooks/useMutation.js +7 -7
  187. package/react/hooks/useMutation.js.map +1 -1
  188. package/react/hooks/useQuery.d.ts +4 -4
  189. package/react/hooks/useQuery.d.ts.map +1 -1
  190. package/react/hooks/useQuery.js +12 -4
  191. package/react/hooks/useQuery.js.map +1 -1
  192. package/react/hooks/useSubscription.d.ts +1 -2
  193. package/react/hooks/useSubscription.d.ts.map +1 -1
  194. package/react/hooks/useSubscription.js +1 -2
  195. package/react/hooks/useSubscription.js.map +1 -1
  196. package/react/hooks/useSuspenseCache.js +2 -2
  197. package/react/hooks/useSuspenseQuery.d.ts +4 -2
  198. package/react/hooks/useSuspenseQuery.d.ts.map +1 -1
  199. package/react/hooks/useSuspenseQuery.js +6 -4
  200. package/react/hooks/useSuspenseQuery.js.map +1 -1
  201. package/react/hooks/useSyncExternalStore.d.ts +1 -1
  202. package/react/hooks/useSyncExternalStore.d.ts.map +1 -1
  203. package/react/hooks/useSyncExternalStore.js +1 -1
  204. package/react/hooks/useSyncExternalStore.js.map +1 -1
  205. package/react/parser/index.js +6 -6
  206. package/react/parser/parser.cjs +10 -10
  207. package/react/parser/parser.cjs.map +1 -1
  208. package/react/parser/parser.cjs.native.js +10 -10
  209. package/react/ssr/RenderPromises.d.ts +4 -4
  210. package/react/ssr/RenderPromises.d.ts.map +1 -1
  211. package/react/ssr/RenderPromises.js.map +1 -1
  212. package/react/ssr/getDataFromTree.d.ts +1 -1
  213. package/react/ssr/getDataFromTree.d.ts.map +1 -1
  214. package/react/types/types.d.ts +20 -20
  215. package/react/types/types.d.ts.map +1 -1
  216. package/react/types/types.js.map +1 -1
  217. package/testing/core/core.cjs +13 -3
  218. package/testing/core/core.cjs.map +1 -1
  219. package/testing/core/core.cjs.native.js +13 -3
  220. package/testing/core/index.d.ts +1 -1
  221. package/testing/core/index.d.ts.map +1 -1
  222. package/testing/core/index.js.map +1 -1
  223. package/testing/core/mocking/mockFetch.js.map +1 -1
  224. package/testing/core/mocking/mockLink.d.ts +8 -4
  225. package/testing/core/mocking/mockLink.d.ts.map +1 -1
  226. package/testing/core/mocking/mockLink.js +14 -4
  227. package/testing/core/mocking/mockLink.js.map +1 -1
  228. package/testing/core/mocking/mockQueryManager.d.ts +1 -1
  229. package/testing/core/mocking/mockQueryManager.d.ts.map +1 -1
  230. package/testing/core/mocking/mockQueryManager.js +3 -3
  231. package/testing/core/mocking/mockQueryManager.js.map +1 -1
  232. package/testing/core/mocking/mockWatchQuery.d.ts +1 -1
  233. package/testing/core/mocking/mockWatchQuery.d.ts.map +1 -1
  234. package/testing/core/mocking/mockWatchQuery.js +4 -5
  235. package/testing/core/mocking/mockWatchQuery.js.map +1 -1
  236. package/testing/core/observableToPromise.d.ts +2 -2
  237. package/testing/core/observableToPromise.d.ts.map +1 -1
  238. package/testing/core/observableToPromise.js.map +1 -1
  239. package/testing/react/MockedProvider.d.ts +1 -0
  240. package/testing/react/MockedProvider.d.ts.map +1 -1
  241. package/testing/react/MockedProvider.js +2 -2
  242. package/testing/react/MockedProvider.js.map +1 -1
  243. package/testing/testing.cjs +2 -2
  244. package/testing/testing.cjs.map +1 -1
  245. package/testing/testing.cjs.native.js +2 -2
  246. package/utilities/common/cloneDeep.js.map +1 -1
  247. package/utilities/common/errorHandling.d.ts +2 -2
  248. package/utilities/common/errorHandling.d.ts.map +1 -1
  249. package/utilities/common/errorHandling.js.map +1 -1
  250. package/utilities/common/incrementalResult.d.ts +4 -4
  251. package/utilities/common/incrementalResult.d.ts.map +1 -1
  252. package/utilities/common/incrementalResult.js.map +1 -1
  253. package/utilities/common/maybeDeepFreeze.d.ts +0 -1
  254. package/utilities/common/maybeDeepFreeze.d.ts.map +1 -1
  255. package/utilities/common/maybeDeepFreeze.js +1 -1
  256. package/utilities/common/maybeDeepFreeze.js.map +1 -1
  257. package/utilities/common/mergeDeep.d.ts +2 -2
  258. package/utilities/common/mergeDeep.d.ts.map +1 -1
  259. package/utilities/common/mergeOptions.d.ts +3 -3
  260. package/utilities/common/mergeOptions.d.ts.map +1 -1
  261. package/utilities/common/mergeOptions.js.map +1 -1
  262. package/utilities/globals/DEV.d.ts +1 -1
  263. package/utilities/globals/DEV.d.ts.map +1 -1
  264. package/utilities/globals/DEV.js +1 -17
  265. package/utilities/globals/DEV.js.map +1 -1
  266. package/utilities/globals/global.d.ts +5 -2
  267. package/utilities/globals/global.d.ts.map +1 -1
  268. package/utilities/globals/global.js.map +1 -1
  269. package/utilities/globals/globals.cjs +5 -22
  270. package/utilities/globals/globals.cjs.map +1 -1
  271. package/utilities/globals/globals.cjs.native.js +5 -22
  272. package/utilities/globals/index.d.ts +1 -1
  273. package/utilities/globals/index.d.ts.map +1 -1
  274. package/utilities/globals/index.js +1 -4
  275. package/utilities/globals/index.js.map +1 -1
  276. package/utilities/graphql/directives.d.ts +2 -2
  277. package/utilities/graphql/directives.d.ts.map +1 -1
  278. package/utilities/graphql/directives.js +1 -1
  279. package/utilities/graphql/directives.js.map +1 -1
  280. package/utilities/graphql/fragments.d.ts +1 -1
  281. package/utilities/graphql/fragments.d.ts.map +1 -1
  282. package/utilities/graphql/fragments.js +1 -1
  283. package/utilities/graphql/getFromAST.js +1 -1
  284. package/utilities/graphql/storeUtils.d.ts +3 -3
  285. package/utilities/graphql/storeUtils.d.ts.map +1 -1
  286. package/utilities/graphql/storeUtils.js +1 -1
  287. package/utilities/graphql/storeUtils.js.map +1 -1
  288. package/utilities/graphql/transform.d.ts +9 -9
  289. package/utilities/graphql/transform.d.ts.map +1 -1
  290. package/utilities/graphql/transform.js +1 -1
  291. package/utilities/graphql/transform.js.map +1 -1
  292. package/utilities/index.d.ts +2 -0
  293. package/utilities/index.d.ts.map +1 -1
  294. package/utilities/index.js +2 -0
  295. package/utilities/index.js.map +1 -1
  296. package/utilities/observables/Concast.d.ts +5 -5
  297. package/utilities/observables/Concast.d.ts.map +1 -1
  298. package/utilities/observables/asyncMap.js.map +1 -1
  299. package/utilities/policies/pagination.d.ts +7 -7
  300. package/utilities/policies/pagination.d.ts.map +1 -1
  301. package/utilities/policies/pagination.js.map +1 -1
  302. package/utilities/types/IsStrictlyAny.d.ts +3 -3
  303. package/utilities/types/IsStrictlyAny.d.ts.map +1 -1
  304. package/utilities/utilities.cjs +75 -19
  305. package/utilities/utilities.cjs.map +1 -1
  306. package/utilities/utilities.cjs.native.js +75 -19
  307. package/version.js +1 -1
@@ -29,9 +29,9 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
29
29
  function useApolloClient(override) {
30
30
  var context$1 = React.useContext(context.getApolloContext());
31
31
  var client = override || context$1.client;
32
- __DEV__ ? globals.invariant(!!client, 'Could not find "client" in the context or passed in as an option. ' +
32
+ globals.__DEV__ ? globals.invariant(!!client, 'Could not find "client" in the context or passed in as an option. ' +
33
33
  'Wrap the root component in an <ApolloProvider>, or pass an ApolloClient ' +
34
- 'instance in via options.') : globals.invariant(!!client, 31);
34
+ 'instance in via options.') : globals.invariant(!!client, 32);
35
35
  return client;
36
36
  }
37
37
 
@@ -40,11 +40,11 @@ var uSESKey = "useSyncExternalStore";
40
40
  var realHook = React__namespace[uSESKey];
41
41
  var useSyncExternalStore = realHook || (function (subscribe, getSnapshot, getServerSnapshot) {
42
42
  var value = getSnapshot();
43
- if (__DEV__ &&
43
+ if (globals.__DEV__ &&
44
44
  !didWarnUncachedGetSnapshot &&
45
45
  value !== getSnapshot()) {
46
46
  didWarnUncachedGetSnapshot = true;
47
- __DEV__ && globals.invariant.error('The result of getSnapshot should be cached to avoid an infinite loop');
47
+ globals.__DEV__ && globals.invariant.error('The result of getSnapshot should be cached to avoid an infinite loop');
48
48
  }
49
49
  var _a = React__namespace.useState({ inst: { value: value, getSnapshot: getSnapshot } }), inst = _a[0].inst, forceUpdate = _a[1];
50
50
  if (utilities.canUseLayoutEffect) {
@@ -126,13 +126,21 @@ var InternalState = (function () {
126
126
  }
127
127
  }
128
128
  InternalState.prototype.forceUpdate = function () {
129
- __DEV__ && globals.invariant.warn("Calling default no-op implementation of InternalState#forceUpdate");
129
+ globals.__DEV__ && globals.invariant.warn("Calling default no-op implementation of InternalState#forceUpdate");
130
130
  };
131
- InternalState.prototype.asyncUpdate = function () {
131
+ InternalState.prototype.asyncUpdate = function (signal) {
132
132
  var _this = this;
133
- return new Promise(function (resolve) {
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
+ };
134
141
  _this.asyncResolveFns.add(resolve);
135
- _this.optionsToIgnoreOnce.add(_this.watchQueryOptions);
142
+ _this.optionsToIgnoreOnce.add(watchQueryOptions);
143
+ signal.addEventListener('abort', handleAborted);
136
144
  _this.forceUpdate();
137
145
  });
138
146
  };
@@ -320,7 +328,7 @@ var InternalState = (function () {
320
328
  _this.onCompleted(result.data);
321
329
  }
322
330
  }).catch(function (error) {
323
- __DEV__ && globals.invariant.warn(error);
331
+ globals.__DEV__ && globals.invariant.warn(error);
324
332
  });
325
333
  }
326
334
  };
@@ -371,11 +379,11 @@ var EAGER_METHODS = [
371
379
  'subscribeToMore',
372
380
  ];
373
381
  function useLazyQuery(query, options) {
374
- var internalState = useInternalState(useApolloClient(options && options.client), query);
382
+ var _a;
383
+ var abortControllersRef = React.useRef(new Set());
375
384
  var execOptionsRef = React.useRef();
376
- var merged = execOptionsRef.current
377
- ? utilities.mergeOptions(options, execOptionsRef.current)
378
- : options;
385
+ var merged = execOptionsRef.current ? utilities.mergeOptions(options, execOptionsRef.current) : options;
386
+ var internalState = useInternalState(useApolloClient(options && options.client), (_a = merged === null || merged === void 0 ? void 0 : merged.query) !== null && _a !== void 0 ? _a : query);
379
387
  var useQueryResult = internalState.useQuery(tslib.__assign(tslib.__assign({}, merged), { skip: !execOptionsRef.current }));
380
388
  var initialFetchPolicy = useQueryResult.observable.options.initialFetchPolicy ||
381
389
  internalState.getDefaultFetchPolicy();
@@ -401,14 +409,28 @@ function useLazyQuery(query, options) {
401
409
  return eagerMethods;
402
410
  }, []);
403
411
  Object.assign(result, eagerMethods);
412
+ React.useEffect(function () {
413
+ return function () {
414
+ abortControllersRef.current.forEach(function (controller) {
415
+ controller.abort();
416
+ });
417
+ };
418
+ }, []);
404
419
  var execute = React.useCallback(function (executeOptions) {
420
+ var controller = new AbortController();
421
+ abortControllersRef.current.add(controller);
405
422
  execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
406
423
  fetchPolicy: initialFetchPolicy,
407
424
  };
408
425
  var promise = internalState
409
- .asyncUpdate()
410
- .then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
411
- promise.catch(function () { });
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
+ });
412
434
  return promise;
413
435
  }, []);
414
436
  return [execute, result];
@@ -449,7 +471,7 @@ function useMutation(mutation, options) {
449
471
  var mutationId = ++ref.current.mutationId;
450
472
  var clientOptions = core.mergeOptions(baseOptions, executeOptions);
451
473
  return client.mutate(clientOptions).then(function (response) {
452
- var _a, _b, _c;
474
+ var _a;
453
475
  var data = response.data, errors$1 = response.errors;
454
476
  var error = errors$1 && errors$1.length > 0
455
477
  ? new errors.ApolloError({ graphQLErrors: errors$1 })
@@ -467,11 +489,11 @@ function useMutation(mutation, options) {
467
489
  setResult(ref.current.result = result_1);
468
490
  }
469
491
  }
470
- (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onCompleted) === null || _b === void 0 ? void 0 : _b.call(_a, response.data, clientOptions);
471
- (_c = executeOptions.onCompleted) === null || _c === void 0 ? void 0 : _c.call(executeOptions, response.data, clientOptions);
492
+ var onCompleted = executeOptions.onCompleted || ((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onCompleted);
493
+ onCompleted === null || onCompleted === void 0 ? void 0 : onCompleted(response.data, clientOptions);
472
494
  return response;
473
495
  }).catch(function (error) {
474
- var _a, _b, _c, _d;
496
+ var _a;
475
497
  if (mutationId === ref.current.mutationId &&
476
498
  ref.current.isMounted) {
477
499
  var result_2 = {
@@ -485,9 +507,9 @@ function useMutation(mutation, options) {
485
507
  setResult(ref.current.result = result_2);
486
508
  }
487
509
  }
488
- if (((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) || clientOptions.onError) {
489
- (_c = (_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.onError) === null || _c === void 0 ? void 0 : _c.call(_b, error, clientOptions);
490
- (_d = executeOptions.onError) === null || _d === void 0 ? void 0 : _d.call(executeOptions, error, clientOptions);
510
+ var onError = executeOptions.onError || ((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError);
511
+ if (onError) {
512
+ onError(error, clientOptions);
491
513
  return { data: void 0, errors: error };
492
514
  }
493
515
  throw error;
@@ -520,12 +542,12 @@ function useSubscription(subscription, options) {
520
542
  if (!hasIssuedDeprecationWarningRef.current) {
521
543
  hasIssuedDeprecationWarningRef.current = true;
522
544
  if (options === null || options === void 0 ? void 0 : options.onSubscriptionData) {
523
- __DEV__ && globals.invariant.warn(options.onData
545
+ globals.__DEV__ && globals.invariant.warn(options.onData
524
546
  ? "'useSubscription' supports only the 'onSubscriptionData' or 'onData' option, but not both. Only the 'onData' option will be used."
525
547
  : "'onSubscriptionData' is deprecated and will be removed in a future major version. Please use the 'onData' option instead.");
526
548
  }
527
549
  if (options === null || options === void 0 ? void 0 : options.onSubscriptionComplete) {
528
- __DEV__ && globals.invariant.warn(options.onComplete
550
+ globals.__DEV__ && globals.invariant.warn(options.onComplete
529
551
  ? "'useSubscription' supports only the 'onSubscriptionComplete' or 'onComplete' option, but not both. Only the 'onComplete' option will be used."
530
552
  : "'onSubscriptionComplete' is deprecated and will be removed in a future major version. Please use the 'onComplete' option instead.");
531
553
  }
@@ -664,20 +686,21 @@ function useFragment_experimental(options) {
664
686
  var diffOptions = tslib.__assign(tslib.__assign({}, rest), { id: typeof from === "string" ? from : cache.identify(from), query: cache["getFragmentDoc"](fragment, fragmentName), optimistic: optimistic });
665
687
  var resultRef = React.useRef();
666
688
  var latestDiff = cache.diff(diffOptions);
689
+ var getSnapshot = function () {
690
+ var latestDiffToResult = diffToResult(latestDiff);
691
+ return resultRef.current &&
692
+ equality.equal(resultRef.current.data, latestDiffToResult.data)
693
+ ? resultRef.current
694
+ : (resultRef.current = latestDiffToResult);
695
+ };
667
696
  return useSyncExternalStore(function (forceUpdate) {
668
697
  return cache.watch(tslib.__assign(tslib.__assign({}, diffOptions), { immediate: true, callback: function (diff) {
669
698
  if (!equality.equal(diff, latestDiff)) {
670
- resultRef.current = diffToResult(latestDiff = diff);
699
+ resultRef.current = diffToResult((latestDiff = diff));
671
700
  forceUpdate();
672
701
  }
673
702
  } }));
674
- }, function () {
675
- var latestDiffToResult = diffToResult(latestDiff);
676
- return resultRef.current &&
677
- equality.equal(resultRef.current.data, latestDiffToResult.data)
678
- ? resultRef.current
679
- : (resultRef.current = latestDiffToResult);
680
- });
703
+ }, getSnapshot, getSnapshot);
681
704
  }
682
705
  function diffToResult(diff) {
683
706
  var result = {
@@ -698,20 +721,14 @@ function useDeepMemo(memoFn, deps) {
698
721
  return ref.current.value;
699
722
  }
700
723
 
701
- typeof WeakMap === 'function' &&
702
- globals.maybe(function () { return navigator.product; }) !== 'ReactNative';
703
- var canUseDOM = typeof globals.maybe(function () { return window.document.createElement; }) === "function";
704
- var usingJSDOM = globals.maybe(function () { return navigator.userAgent.indexOf("jsdom") >= 0; }) || false;
705
- var canUseLayoutEffect = canUseDOM && !usingJSDOM;
706
-
707
- var useIsomorphicLayoutEffect = canUseLayoutEffect
724
+ var useIsomorphicLayoutEffect = utilities.canUseLayoutEffect
708
725
  ? React.useLayoutEffect
709
726
  : React.useEffect;
710
727
 
711
728
  function useSuspenseCache() {
712
729
  var suspenseCache = React.useContext(context.getApolloContext()).suspenseCache;
713
- __DEV__ ? globals.invariant(suspenseCache, 'Could not find a "suspenseCache" in the context. Wrap the root component ' +
714
- 'in an <ApolloProvider> and provide a suspenseCache.') : globals.invariant(suspenseCache, 32);
730
+ globals.__DEV__ ? globals.invariant(suspenseCache, 'Could not find a "suspenseCache" in the context. Wrap the root component ' +
731
+ 'in an <ApolloProvider> and provide a suspenseCache.') : globals.invariant(suspenseCache, 33);
715
732
  return suspenseCache;
716
733
  }
717
734
 
@@ -777,6 +794,7 @@ function useSuspenseQuery_experimental(query, options) {
777
794
  }, []);
778
795
  return React.useMemo(function () {
779
796
  return {
797
+ client: client,
780
798
  data: result.data,
781
799
  error: errorPolicy === 'ignore' ? void 0 : toApolloError(result),
782
800
  fetchMore: function (options) {
@@ -795,8 +813,9 @@ function useSuspenseQuery_experimental(query, options) {
795
813
  });
796
814
  return promise;
797
815
  },
816
+ subscribeToMore: function (options) { return observable.subscribeToMore(options); },
798
817
  };
799
- }, [result, observable, errorPolicy]);
818
+ }, [client, result, observable, errorPolicy]);
800
819
  }
801
820
  function validateOptions(options) {
802
821
  var query = options.query, _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? DEFAULT_FETCH_POLICY : _a, returnPartialData = options.returnPartialData;
@@ -805,11 +824,11 @@ function validateOptions(options) {
805
824
  validatePartialDataReturn(fetchPolicy, returnPartialData);
806
825
  }
807
826
  function validateFetchPolicy(fetchPolicy) {
808
- __DEV__ ? globals.invariant(SUPPORTED_FETCH_POLICIES.includes(fetchPolicy), "The fetch policy `".concat(fetchPolicy, "` is not supported with suspense.")) : globals.invariant(SUPPORTED_FETCH_POLICIES.includes(fetchPolicy), 33);
827
+ globals.__DEV__ ? globals.invariant(SUPPORTED_FETCH_POLICIES.includes(fetchPolicy), "The fetch policy `".concat(fetchPolicy, "` is not supported with suspense.")) : globals.invariant(SUPPORTED_FETCH_POLICIES.includes(fetchPolicy), 34);
809
828
  }
810
829
  function validatePartialDataReturn(fetchPolicy, returnPartialData) {
811
830
  if (fetchPolicy === 'no-cache' && returnPartialData) {
812
- __DEV__ && globals.invariant.warn('Using `returnPartialData` with a `no-cache` fetch policy has no effect. To read partial data from the cache, consider using an alternate fetch policy.');
831
+ globals.__DEV__ && globals.invariant.warn('Using `returnPartialData` with a `no-cache` fetch policy has no effect. To read partial data from the cache, consider using an alternate fetch policy.');
813
832
  }
814
833
  }
815
834
  function toApolloError(result) {
@@ -839,7 +858,7 @@ function useWatchQueryOptions(_a) {
839
858
  var errorPolicy = options.errorPolicy, fetchPolicy = options.fetchPolicy, _a = options.suspensePolicy, suspensePolicy = _a === void 0 ? DEFAULT_SUSPENSE_POLICY : _a, variables = options.variables, watchQueryOptions = tslib.__rest(options, ["errorPolicy", "fetchPolicy", "suspensePolicy", "variables"]);
840
859
  return tslib.__assign(tslib.__assign({}, watchQueryOptions), { query: query, errorPolicy: errorPolicy || (defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.errorPolicy) || DEFAULT_ERROR_POLICY, fetchPolicy: fetchPolicy || (defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.fetchPolicy) || DEFAULT_FETCH_POLICY, notifyOnNetworkStatusChange: suspensePolicy === 'always', fetchOnFirstSubscribe: false, variables: utilities.compact(tslib.__assign(tslib.__assign({}, defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.variables), variables)) });
841
860
  }, [options, query, defaultOptions]);
842
- if (__DEV__) {
861
+ if (globals.__DEV__) {
843
862
  validateOptions(watchQueryOptions);
844
863
  }
845
864
  return watchQueryOptions;
@@ -1,5 +1,5 @@
1
1
  import { useLayoutEffect, useEffect } from 'react';
2
- import { canUseLayoutEffect } from "../../../utilities/common/canUse.js";
2
+ import { canUseLayoutEffect } from "../../../utilities/index.js";
3
3
  export var useIsomorphicLayoutEffect = canUseLayoutEffect
4
4
  ? useLayoutEffect
5
5
  : useEffect;
@@ -1 +1 @@
1
- {"version":3,"file":"useIsomorphicLayoutEffect.js","sourceRoot":"","sources":["../../../../src/react/hooks/internal/useIsomorphicLayoutEffect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAEtE,MAAM,CAAC,IAAM,yBAAyB,GAAG,kBAAkB;IACzD,CAAC,CAAC,eAAe;IACjB,CAAC,CAAC,SAAS,CAAC","sourcesContent":["import { useLayoutEffect, useEffect } from 'react';\nimport { canUseLayoutEffect } from '../../../utilities/common/canUse';\n\nexport const useIsomorphicLayoutEffect = canUseLayoutEffect\n ? useLayoutEffect\n : useEffect;\n"]}
1
+ {"version":3,"file":"useIsomorphicLayoutEffect.js","sourceRoot":"","sources":["../../../../src/react/hooks/internal/useIsomorphicLayoutEffect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD,MAAM,CAAC,IAAM,yBAAyB,GAAG,kBAAkB;IACzD,CAAC,CAAC,eAAe;IACjB,CAAC,CAAC,SAAS,CAAC","sourcesContent":["import { useLayoutEffect, useEffect } from 'react';\nimport { canUseLayoutEffect } from '../../../utilities';\n\nexport const useIsomorphicLayoutEffect = canUseLayoutEffect\n ? useLayoutEffect\n : useEffect;\n"]}
@@ -1,4 +1,4 @@
1
- import { invariant } from "../../utilities/globals/index.js";
1
+ import { invariant, __DEV__ } from "../../utilities/globals/index.js";
2
2
  import { useContext } from 'react';
3
3
  import { getApolloContext } from "../context/index.js";
4
4
  export function useApolloClient(override) {
@@ -6,7 +6,7 @@ export function useApolloClient(override) {
6
6
  var client = override || context.client;
7
7
  __DEV__ ? invariant(!!client, 'Could not find "client" in the context or passed in as an option. ' +
8
8
  'Wrap the root component in an <ApolloProvider>, or pass an ApolloClient ' +
9
- 'instance in via options.') : invariant(!!client, 31);
9
+ 'instance in via options.') : invariant(!!client, 32);
10
10
  return client;
11
11
  }
12
12
  //# sourceMappingURL=useApolloClient.js.map
@@ -1,4 +1,5 @@
1
1
  import { Cache, Reference, StoreObject, MissingTree } from "../../cache";
2
+ import { OperationVariables } from "../../core";
2
3
  export interface UseFragmentOptions<TData, TVars> extends Omit<Cache.DiffOptions<TData, TVars>, "id" | "query" | "optimistic" | "previousResult">, Omit<Cache.ReadFragmentOptions<TData, TVars>, "id"> {
3
4
  from: StoreObject | Reference | string;
4
5
  optimistic?: boolean;
@@ -8,5 +9,5 @@ export interface UseFragmentResult<TData> {
8
9
  complete: boolean;
9
10
  missing?: MissingTree;
10
11
  }
11
- export declare function useFragment_experimental<TData, TVars>(options: UseFragmentOptions<TData, TVars>): UseFragmentResult<TData>;
12
+ export declare function useFragment_experimental<TData = any, TVars = OperationVariables>(options: UseFragmentOptions<TData, TVars>): UseFragmentResult<TData>;
12
13
  //# sourceMappingURL=useFragment.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useFragment.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useFragment.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,EACL,SAAS,EACT,WAAW,EACX,WAAW,EACZ,MAAM,aAAa,CAAC;AAKrB,MAAM,WAAW,kBAAkB,CAAC,KAAK,EAAE,KAAK,CAChD,SAAQ,IAAI,CACV,KAAK,CAAC,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,EAC7B,IAAI,GACJ,OAAO,GACP,YAAY,GACZ,gBAAgB,CACnB,EAAE,IAAI,CACL,KAAK,CAAC,mBAAmB,CAAC,KAAK,EAAE,KAAK,CAAC,EACrC,IAAI,CACP;IACC,IAAI,EAAE,WAAW,GAAG,SAAS,GAAG,MAAM,CAAC;IAEvC,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAgBD,MAAM,WAAW,iBAAiB,CAAC,KAAK;IACtC,IAAI,EAAE,KAAK,GAAG,SAAS,CAAC;IACxB,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,KAAK,EACnD,OAAO,EAAE,kBAAkB,CAAC,KAAK,EAAE,KAAK,CAAC,GACxC,iBAAiB,CAAC,KAAK,CAAC,CA2C1B"}
1
+ {"version":3,"file":"useFragment.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useFragment.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,EACL,SAAS,EACT,WAAW,EACX,WAAW,EACZ,MAAM,aAAa,CAAC;AAIrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEhD,MAAM,WAAW,kBAAkB,CAAC,KAAK,EAAE,KAAK,CAChD,SAAQ,IAAI,CACV,KAAK,CAAC,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,EAC7B,IAAI,GACJ,OAAO,GACP,YAAY,GACZ,gBAAgB,CACnB,EAAE,IAAI,CACL,KAAK,CAAC,mBAAmB,CAAC,KAAK,EAAE,KAAK,CAAC,EACrC,IAAI,CACP;IACC,IAAI,EAAE,WAAW,GAAG,SAAS,GAAG,MAAM,CAAC;IAEvC,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAgBD,MAAM,WAAW,iBAAiB,CAAC,KAAK;IACtC,IAAI,EAAE,KAAK,GAAG,SAAS,CAAC;IACxB,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB;AAED,wBAAgB,wBAAwB,CACtC,KAAK,GAAG,GAAG,EACX,KAAK,GAAG,kBAAkB,EAE1B,OAAO,EAAE,kBAAkB,CAAC,KAAK,EAAE,KAAK,CAAC,GACxC,iBAAiB,CAAC,KAAK,CAAC,CA8C1B"}
@@ -10,20 +10,21 @@ export function useFragment_experimental(options) {
10
10
  var diffOptions = __assign(__assign({}, rest), { id: typeof from === "string" ? from : cache.identify(from), query: cache["getFragmentDoc"](fragment, fragmentName), optimistic: optimistic });
11
11
  var resultRef = useRef();
12
12
  var latestDiff = cache.diff(diffOptions);
13
+ var getSnapshot = function () {
14
+ var latestDiffToResult = diffToResult(latestDiff);
15
+ return resultRef.current &&
16
+ equal(resultRef.current.data, latestDiffToResult.data)
17
+ ? resultRef.current
18
+ : (resultRef.current = latestDiffToResult);
19
+ };
13
20
  return useSyncExternalStore(function (forceUpdate) {
14
21
  return cache.watch(__assign(__assign({}, diffOptions), { immediate: true, callback: function (diff) {
15
22
  if (!equal(diff, latestDiff)) {
16
- resultRef.current = diffToResult(latestDiff = diff);
23
+ resultRef.current = diffToResult((latestDiff = diff));
17
24
  forceUpdate();
18
25
  }
19
26
  } }));
20
- }, function () {
21
- var latestDiffToResult = diffToResult(latestDiff);
22
- return resultRef.current &&
23
- equal(resultRef.current.data, latestDiffToResult.data)
24
- ? resultRef.current
25
- : (resultRef.current = latestDiffToResult);
26
- });
27
+ }, getSnapshot, getSnapshot);
27
28
  }
28
29
  function diffToResult(diff) {
29
30
  var result = {
@@ -1 +1 @@
1
- {"version":3,"file":"useFragment.js","sourceRoot":"","sources":["../../../src/react/hooks/useFragment.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAQjD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAsC9D,MAAM,UAAU,wBAAwB,CACtC,OAAyC;IAEjC,IAAA,KAAK,GAAK,eAAe,EAAE,MAAtB,CAAuB;IAGlC,IAAA,QAAQ,GAKN,OAAO,SALD,EACR,YAAY,GAIV,OAAO,aAJG,EACZ,IAAI,GAGF,OAAO,KAHL,EACJ,KAEE,OAAO,WAFQ,EAAjB,UAAU,mBAAG,IAAI,KAAA,EACd,IAAI,UACL,OAAO,EANL,kDAML,CADQ,CACG;IAEZ,IAAM,WAAW,yBACZ,IAAI,KACP,EAAE,EAAE,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAC1D,KAAK,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC,QAAQ,EAAE,YAAY,CAAC,EACtD,UAAU,YAAA,GACX,CAAC;IAEF,IAAM,SAAS,GAAG,MAAM,EAA4B,CAAC;IACrD,IAAI,UAAU,GAAG,KAAK,CAAC,IAAI,CAAQ,WAAW,CAAC,CAAC;IAEhD,OAAO,oBAAoB,CACzB,UAAA,WAAW;QACT,OAAO,KAAK,CAAC,KAAK,uBACb,WAAW,KACd,SAAS,EAAE,IAAI,EACf,QAAQ,YAAC,IAAI;gBACX,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,UAAU,CAAC,EAAE;oBAC5B,SAAS,CAAC,OAAO,GAAG,YAAY,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;oBACpD,WAAW,EAAE,CAAC;iBACf;YACH,CAAC,IACD,CAAC;IACL,CAAC,EAED;QACE,IAAM,kBAAkB,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC;QACpD,OAAO,SAAS,CAAC,OAAO;YACtB,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,kBAAkB,CAAC,IAAI,CAAC;YACtD,CAAC,CAAC,SAAS,CAAC,OAAO;YACnB,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,GAAG,kBAAkB,CAAC,CAAC;IAC/C,CAAC,CACF,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CACnB,IAA6B;IAE7B,IAAM,MAAM,GAA6B;QACvC,IAAI,EAAE,IAAI,CAAC,MAAM;QACjB,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ;KAC1B,CAAC;IAEF,IAAI,IAAI,CAAC,OAAO,EAAE;QAChB,MAAM,CAAC,OAAO,GAAG,cAAc,CAC7B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,OAAO,EAAb,CAAa,CAAC,CACzC,CAAC;KACH;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { useRef } from \"react\";\nimport { equal } from \"@wry/equality\";\n\nimport { mergeDeepArray } from \"../../utilities\";\nimport {\n Cache,\n Reference,\n StoreObject,\n MissingTree,\n} from \"../../cache\";\n\nimport { useApolloClient } from \"./useApolloClient\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore\";\n\nexport interface UseFragmentOptions<TData, TVars>\nextends Omit<\n Cache.DiffOptions<TData, TVars>,\n | \"id\"\n | \"query\"\n | \"optimistic\"\n | \"previousResult\"\n>, Omit<\n Cache.ReadFragmentOptions<TData, TVars>,\n | \"id\"\n> {\n from: StoreObject | Reference | string;\n // Override this field to make it optional (default: true).\n optimistic?: boolean;\n}\n\n// Since the above definition of UseFragmentOptions can be hard to parse without\n// help from TypeScript/VSCode, here are the intended fields and their types.\n// Uncomment this code to check that it's consistent with the definition above.\n//\n// export interface UseFragmentOptions<TData, TVars> {\n// from: string | StoreObject | Reference;\n// fragment: DocumentNode | TypedDocumentNode<TData, TVars>;\n// fragmentName?: string;\n// optimistic?: boolean;\n// variables?: TVars;\n// returnPartialData?: boolean;\n// canonizeResults?: boolean;\n// }\n\nexport interface UseFragmentResult<TData> {\n data: TData | undefined;\n complete: boolean;\n missing?: MissingTree;\n}\n\nexport function useFragment_experimental<TData, TVars>(\n options: UseFragmentOptions<TData, TVars>,\n): UseFragmentResult<TData> {\n const { cache } = useApolloClient();\n\n const {\n fragment,\n fragmentName,\n from,\n optimistic = true,\n ...rest\n } = options;\n\n const diffOptions: Cache.DiffOptions<TData, TVars> = {\n ...rest,\n id: typeof from === \"string\" ? from : cache.identify(from),\n query: cache[\"getFragmentDoc\"](fragment, fragmentName),\n optimistic,\n };\n\n const resultRef = useRef<UseFragmentResult<TData>>();\n let latestDiff = cache.diff<TData>(diffOptions);\n\n return useSyncExternalStore(\n forceUpdate => {\n return cache.watch({\n ...diffOptions,\n immediate: true,\n callback(diff) {\n if (!equal(diff, latestDiff)) {\n resultRef.current = diffToResult(latestDiff = diff);\n forceUpdate();\n }\n },\n });\n },\n\n () => {\n const latestDiffToResult = diffToResult(latestDiff);\n return resultRef.current &&\n equal(resultRef.current.data, latestDiffToResult.data)\n ? resultRef.current\n : (resultRef.current = latestDiffToResult);\n },\n );\n}\n\nfunction diffToResult<TData>(\n diff: Cache.DiffResult<TData>,\n): UseFragmentResult<TData> {\n const result: UseFragmentResult<TData> = {\n data: diff.result,\n complete: !!diff.complete,\n };\n\n if (diff.missing) {\n result.missing = mergeDeepArray(\n diff.missing.map(error => error.missing),\n );\n }\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"useFragment.js","sourceRoot":"","sources":["../../../src/react/hooks/useFragment.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAQjD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAuC9D,MAAM,UAAU,wBAAwB,CAItC,OAAyC;IAEjC,IAAA,KAAK,GAAK,eAAe,EAAE,MAAtB,CAAuB;IAGlC,IAAA,QAAQ,GAKN,OAAO,SALD,EACR,YAAY,GAIV,OAAO,aAJG,EACZ,IAAI,GAGF,OAAO,KAHL,EACJ,KAEE,OAAO,WAFQ,EAAjB,UAAU,mBAAG,IAAI,KAAA,EACd,IAAI,UACL,OAAO,EANL,kDAML,CADQ,CACG;IAEZ,IAAM,WAAW,yBACZ,IAAI,KACP,EAAE,EAAE,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAC1D,KAAK,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC,QAAQ,EAAE,YAAY,CAAC,EACtD,UAAU,YAAA,GACX,CAAC;IAEF,IAAM,SAAS,GAAG,MAAM,EAA4B,CAAC;IACrD,IAAI,UAAU,GAAG,KAAK,CAAC,IAAI,CAAQ,WAAW,CAAC,CAAC;IAGhD,IAAM,WAAW,GAAG;QAClB,IAAM,kBAAkB,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC;QACpD,OAAO,SAAS,CAAC,OAAO;YACtB,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,kBAAkB,CAAC,IAAI,CAAC;YACtD,CAAC,CAAC,SAAS,CAAC,OAAO;YACnB,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,GAAG,kBAAkB,CAAC,CAAC;IAC/C,CAAC,CAAC;IAEF,OAAO,oBAAoB,CACzB,UAAC,WAAW;QACV,OAAO,KAAK,CAAC,KAAK,uBACb,WAAW,KACd,SAAS,EAAE,IAAI,EACf,QAAQ,YAAC,IAAI;gBACX,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,UAAU,CAAC,EAAE;oBAC5B,SAAS,CAAC,OAAO,GAAG,YAAY,CAAC,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC;oBACtD,WAAW,EAAE,CAAC;iBACf;YACH,CAAC,IACD,CAAC;IACL,CAAC,EACD,WAAW,EACX,WAAW,CACZ,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CACnB,IAA6B;IAE7B,IAAM,MAAM,GAA6B;QACvC,IAAI,EAAE,IAAI,CAAC,MAAM;QACjB,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ;KAC1B,CAAC;IAEF,IAAI,IAAI,CAAC,OAAO,EAAE;QAChB,MAAM,CAAC,OAAO,GAAG,cAAc,CAC7B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,OAAO,EAAb,CAAa,CAAC,CACzC,CAAC;KACH;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { useRef } from \"react\";\nimport { equal } from \"@wry/equality\";\n\nimport { mergeDeepArray } from \"../../utilities\";\nimport {\n Cache,\n Reference,\n StoreObject,\n MissingTree,\n} from \"../../cache\";\n\nimport { useApolloClient } from \"./useApolloClient\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore\";\nimport { OperationVariables } from \"../../core\";\n\nexport interface UseFragmentOptions<TData, TVars>\nextends Omit<\n Cache.DiffOptions<TData, TVars>,\n | \"id\"\n | \"query\"\n | \"optimistic\"\n | \"previousResult\"\n>, Omit<\n Cache.ReadFragmentOptions<TData, TVars>,\n | \"id\"\n> {\n from: StoreObject | Reference | string;\n // Override this field to make it optional (default: true).\n optimistic?: boolean;\n}\n\n// Since the above definition of UseFragmentOptions can be hard to parse without\n// help from TypeScript/VSCode, here are the intended fields and their types.\n// Uncomment this code to check that it's consistent with the definition above.\n//\n// export interface UseFragmentOptions<TData, TVars> {\n// from: string | StoreObject | Reference;\n// fragment: DocumentNode | TypedDocumentNode<TData, TVars>;\n// fragmentName?: string;\n// optimistic?: boolean;\n// variables?: TVars;\n// returnPartialData?: boolean;\n// canonizeResults?: boolean;\n// }\n\nexport interface UseFragmentResult<TData> {\n data: TData | undefined;\n complete: boolean;\n missing?: MissingTree;\n}\n\nexport function useFragment_experimental<\n TData = any,\n TVars = OperationVariables\n>(\n options: UseFragmentOptions<TData, TVars>,\n): UseFragmentResult<TData> {\n const { cache } = useApolloClient();\n\n const {\n fragment,\n fragmentName,\n from,\n optimistic = true,\n ...rest\n } = options;\n\n const diffOptions: Cache.DiffOptions<TData, TVars> = {\n ...rest,\n id: typeof from === \"string\" ? from : cache.identify(from),\n query: cache[\"getFragmentDoc\"](fragment, fragmentName),\n optimistic,\n };\n\n const resultRef = useRef<UseFragmentResult<TData>>();\n let latestDiff = cache.diff<TData>(diffOptions);\n\n // Used for both getSnapshot and getServerSnapshot\n const getSnapshot = () => {\n const latestDiffToResult = diffToResult(latestDiff);\n return resultRef.current &&\n equal(resultRef.current.data, latestDiffToResult.data)\n ? resultRef.current\n : (resultRef.current = latestDiffToResult);\n };\n\n return useSyncExternalStore(\n (forceUpdate) => {\n return cache.watch({\n ...diffOptions,\n immediate: true,\n callback(diff) {\n if (!equal(diff, latestDiff)) {\n resultRef.current = diffToResult((latestDiff = diff));\n forceUpdate();\n }\n },\n });\n },\n getSnapshot,\n getSnapshot\n );\n}\n\nfunction diffToResult<TData>(\n diff: Cache.DiffResult<TData>,\n): UseFragmentResult<TData> {\n const result: UseFragmentResult<TData> = {\n data: diff.result,\n complete: !!diff.complete,\n };\n\n if (diff.missing) {\n result.missing = mergeDeepArray(\n diff.missing.map(error => error.missing),\n );\n }\n\n return result;\n}\n"]}
@@ -2,5 +2,5 @@ import { DocumentNode } from 'graphql';
2
2
  import { TypedDocumentNode } from '@graphql-typed-document-node/core';
3
3
  import { OperationVariables } from '../../core';
4
4
  import { LazyQueryHookOptions, LazyQueryResultTuple } from '../types/types';
5
- export declare function useLazyQuery<TData = any, TVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: LazyQueryHookOptions<TData, TVariables>): LazyQueryResultTuple<TData, TVariables>;
5
+ export declare function useLazyQuery<TData = any, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: LazyQueryHookOptions<TData, TVariables>): LazyQueryResultTuple<TData, TVariables>;
6
6
  //# sourceMappingURL=useLazyQuery.d.ts.map
@@ -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,EACL,oBAAoB,EACpB,oBAAoB,EAErB,MAAM,gBAAgB,CAAC;AAexB,wBAAgB,YAAY,CAAC,KAAK,GAAG,GAAG,EAAE,UAAU,GAAG,kBAAkB,EACvE,KAAK,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,EAC1D,OAAO,CAAC,EAAE,oBAAoB,CAAC,KAAK,EAAE,UAAU,CAAC,GAChD,oBAAoB,CAAC,KAAK,EAAE,UAAU,CAAC,CAmEzC"}
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,EACL,oBAAoB,EACpB,oBAAoB,EAErB,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,KAAK,EAAE,UAAU,CAAC,GAChD,oBAAoB,CAAC,KAAK,EAAE,UAAU,CAAC,CAkFzC"}
@@ -1,5 +1,5 @@
1
1
  import { __assign } from "tslib";
2
- import { useCallback, useMemo, useRef } from 'react';
2
+ import { useCallback, useEffect, 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,11 @@ var EAGER_METHODS = [
12
12
  'subscribeToMore',
13
13
  ];
14
14
  export function useLazyQuery(query, options) {
15
- var internalState = useInternalState(useApolloClient(options && options.client), query);
15
+ var _a;
16
+ var abortControllersRef = useRef(new Set());
16
17
  var execOptionsRef = useRef();
17
- var merged = execOptionsRef.current
18
- ? mergeOptions(options, execOptionsRef.current)
19
- : options;
18
+ var merged = execOptionsRef.current ? mergeOptions(options, execOptionsRef.current) : options;
19
+ var internalState = useInternalState(useApolloClient(options && options.client), (_a = merged === null || merged === void 0 ? void 0 : merged.query) !== null && _a !== void 0 ? _a : query);
20
20
  var useQueryResult = internalState.useQuery(__assign(__assign({}, merged), { skip: !execOptionsRef.current }));
21
21
  var initialFetchPolicy = useQueryResult.observable.options.initialFetchPolicy ||
22
22
  internalState.getDefaultFetchPolicy();
@@ -42,14 +42,28 @@ export function useLazyQuery(query, options) {
42
42
  return eagerMethods;
43
43
  }, []);
44
44
  Object.assign(result, eagerMethods);
45
+ useEffect(function () {
46
+ return function () {
47
+ abortControllersRef.current.forEach(function (controller) {
48
+ controller.abort();
49
+ });
50
+ };
51
+ }, []);
45
52
  var execute = useCallback(function (executeOptions) {
53
+ var controller = new AbortController();
54
+ abortControllersRef.current.add(controller);
46
55
  execOptionsRef.current = executeOptions ? __assign(__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
47
56
  fetchPolicy: initialFetchPolicy,
48
57
  };
49
58
  var promise = internalState
50
- .asyncUpdate()
51
- .then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
52
- promise.catch(function () { });
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
+ });
53
67
  return promise;
54
68
  }, []);
55
69
  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,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAGrD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAM/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,OAAiD;IAEjD,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,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAEpC,IAAM,OAAO,GAAG,WAAW,CAEzB,UAAA,cAAc;QACd,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,EAAE;aACb,IAAI,CAAC,UAAA,WAAW,IAAI,OAAA,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,YAAY,CAAC,EAAxC,CAAwC,CAAC,CAAC;QAIjE,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 LazyQueryHookOptions,\n LazyQueryResultTuple,\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 = OperationVariables>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: LazyQueryHookOptions<TData, TVariables>\n): LazyQueryResultTuple<TData, TVariables> {\n const internalState = useInternalState(\n useApolloClient(options && options.client),\n query,\n );\n\n const execOptionsRef = useRef<Partial<LazyQueryHookOptions<TData, TVariables>>>();\n const merged = execOptionsRef.current\n ? mergeOptions(options, execOptionsRef.current)\n : options;\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 promise = internalState\n .asyncUpdate() // Like internalState.forceUpdate, but returns a Promise.\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"]}
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;AAM/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAm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AC;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 LazyQueryHookOptions,\n LazyQueryResultTuple,\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<TData, TVariables>\n): LazyQueryResultTuple<TData, TVariables> {\n const abortControllersRef = useRef(new Set<AbortController>());\n\n const execOptionsRef = useRef<Partial<LazyQueryHookOptions<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 merged?.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 +1 @@
1
- {"version":3,"file":"useMutation.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useMutation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAEL,mBAAmB,EAEnB,aAAa,EACd,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,WAAW,EACX,cAAc,EAEd,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAMpB,wBAAgB,WAAW,CACzB,KAAK,GAAG,GAAG,EACX,UAAU,GAAG,kBAAkB,EAC/B,QAAQ,GAAG,cAAc,EACzB,MAAM,SAAS,WAAW,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,EAElD,QAAQ,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,EAC7D,OAAO,CAAC,EAAE,mBAAmB,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,CAAC,GACjE,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,CAAC,CAwHpD"}
1
+ {"version":3,"file":"useMutation.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useMutation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAEL,mBAAmB,EAEnB,aAAa,EACd,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,WAAW,EACX,cAAc,EAEd,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAMpB,wBAAgB,WAAW,CACzB,KAAK,GAAG,GAAG,EACX,UAAU,GAAG,kBAAkB,EAC/B,QAAQ,GAAG,cAAc,EACzB,MAAM,SAAS,WAAW,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,EAElD,QAAQ,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,EAC7D,OAAO,CAAC,EAAE,mBAAmB,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,CAAC,GACjE,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,CAAC,CA4HpD"}
@@ -40,7 +40,7 @@ export function useMutation(mutation, options) {
40
40
  var mutationId = ++ref.current.mutationId;
41
41
  var clientOptions = mergeOptions(baseOptions, executeOptions);
42
42
  return client.mutate(clientOptions).then(function (response) {
43
- var _a, _b, _c;
43
+ var _a;
44
44
  var data = response.data, errors = response.errors;
45
45
  var error = errors && errors.length > 0
46
46
  ? new ApolloError({ graphQLErrors: errors })
@@ -58,11 +58,11 @@ export function useMutation(mutation, options) {
58
58
  setResult(ref.current.result = result_1);
59
59
  }
60
60
  }
61
- (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onCompleted) === null || _b === void 0 ? void 0 : _b.call(_a, response.data, clientOptions);
62
- (_c = executeOptions.onCompleted) === null || _c === void 0 ? void 0 : _c.call(executeOptions, response.data, clientOptions);
61
+ var onCompleted = executeOptions.onCompleted || ((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onCompleted);
62
+ onCompleted === null || onCompleted === void 0 ? void 0 : onCompleted(response.data, clientOptions);
63
63
  return response;
64
64
  }).catch(function (error) {
65
- var _a, _b, _c, _d;
65
+ var _a;
66
66
  if (mutationId === ref.current.mutationId &&
67
67
  ref.current.isMounted) {
68
68
  var result_2 = {
@@ -76,9 +76,9 @@ export function useMutation(mutation, options) {
76
76
  setResult(ref.current.result = result_2);
77
77
  }
78
78
  }
79
- if (((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) || clientOptions.onError) {
80
- (_c = (_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.onError) === null || _c === void 0 ? void 0 : _c.call(_b, error, clientOptions);
81
- (_d = executeOptions.onError) === null || _d === void 0 ? void 0 : _d.call(executeOptions, error, clientOptions);
79
+ var onError = executeOptions.onError || ((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError);
80
+ if (onError) {
81
+ onError(error, clientOptions);
82
82
  return { data: void 0, errors: error };
83
83
  }
84
84
  throw error;
@@ -1 +1 @@
1
- {"version":3,"file":"useMutation.js","sourceRoot":"","sources":["../../../src/react/hooks/useMutation.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAUjE,OAAO,EAGL,YAAY,GAEb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,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C,CAAC;IAEP,OAAO,CAAC,OAAO,aAAI,KAAK,OAAA,IAAK,MAAM,EAAG,CAAC;AACzC,CAAC","sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\nimport { DocumentNode } from 'graphql';\nimport { TypedDocumentNode } from '@graphql-typed-document-node/core';\nimport {\n MutationFunctionOptions,\n MutationHookOptions,\n MutationResult,\n MutationTuple,\n} from '../types/types';\n\nimport {\n ApolloCache,\n DefaultContext,\n mergeOptions,\n OperationVariables,\n} from '../../core';\nimport { equal } from '@wry/equality';\nimport { DocumentType, verifyDocumentType } from '../parser';\nimport { ApolloError } from '../../errors';\nimport { useApolloClient } from './useApolloClient';\n\nexport function useMutation<\n TData = any,\n TVariables = OperationVariables,\n TContext = DefaultContext,\n TCache extends ApolloCache<any> = ApolloCache<any>,\n>(\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: MutationHookOptions<TData, TVariables, TContext, TCache>,\n): MutationTuple<TData, TVariables, TContext, TCache> {\n const client = useApolloClient(options?.client);\n verifyDocumentType(mutation, DocumentType.Mutation);\n const [result, setResult] = useState<Omit<MutationResult, 'reset'>>({\n called: false,\n loading: false,\n client,\n });\n\n const ref = useRef({\n result,\n mutationId: 0,\n isMounted: true,\n client,\n mutation,\n options,\n });\n\n // TODO: Trying to assign these in a useEffect or useLayoutEffect breaks\n // higher-order components.\n {\n Object.assign(ref.current, { client, options, mutation });\n }\n\n const execute = useCallback((\n executeOptions: MutationFunctionOptions<\n TData,\n TVariables,\n TContext,\n TCache\n > = {}\n ) => {\n const {client, options, mutation} = ref.current;\n const baseOptions = { ...options, mutation };\n if (!ref.current.result.loading && !baseOptions.ignoreResults && ref.current.isMounted) {\n setResult(ref.current.result = {\n loading: true,\n error: void 0,\n data: void 0,\n called: true,\n client,\n });\n }\n\n const mutationId = ++ref.current.mutationId;\n const clientOptions = mergeOptions(\n baseOptions,\n executeOptions as any,\n );\n\n return client.mutate(clientOptions).then((response) => {\n const { data, errors } = response;\n const error =\n errors && errors.length > 0\n ? new ApolloError({ graphQLErrors: errors })\n : void 0;\n\n if (\n mutationId === ref.current.mutationId &&\n !clientOptions.ignoreResults\n ) {\n const result = {\n called: true,\n loading: false,\n data,\n error,\n client,\n };\n\n if (ref.current.isMounted && !equal(ref.current.result, result)) {\n setResult(ref.current.result = result);\n }\n }\n ref.current.options?.onCompleted?.(response.data!, clientOptions);\n executeOptions.onCompleted?.(response.data!, clientOptions);\n return response;\n }).catch((error) => {\n if (\n mutationId === ref.current.mutationId &&\n ref.current.isMounted\n ) {\n const result = {\n loading: false,\n error,\n data: void 0,\n called: true,\n client,\n };\n\n if (!equal(ref.current.result, result)) {\n setResult(ref.current.result = result);\n }\n }\n\n if (ref.current.options?.onError || clientOptions.onError) {\n ref.current.options?.onError?.(error, clientOptions);\n executeOptions.onError?.(error, clientOptions);\n // TODO(brian): why are we returning this here???\n return { data: void 0, errors: error };\n }\n\n throw error;\n });\n }, []);\n\n const reset = useCallback(() => {\n if (ref.current.isMounted) {\n setResult({ called: false, loading: false, client });\n }\n }, []);\n\n useEffect(() => {\n ref.current.isMounted = true;\n\n return () => {\n ref.current.isMounted = false;\n };\n }, []);\n\n return [execute, { reset, ...result }];\n}\n"]}
1
+ {"version":3,"file":"useMutation.js","sourceRoot":"","sources":["../../../src/react/hooks/useMutation.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAUjE,OAAO,EAGL,YAAY,GAEb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,UAAU,WAAW,CAMzB,QAA6D,EAC7D,OAAk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ql';\nimport { TypedDocumentNode } from '@graphql-typed-document-node/core';\nimport {\n MutationFunctionOptions,\n MutationHookOptions,\n MutationResult,\n MutationTuple,\n} from '../types/types';\n\nimport {\n ApolloCache,\n DefaultContext,\n mergeOptions,\n OperationVariables,\n} from '../../core';\nimport { equal } from '@wry/equality';\nimport { DocumentType, verifyDocumentType } from '../parser';\nimport { ApolloError } from '../../errors';\nimport { useApolloClient } from './useApolloClient';\n\nexport function useMutation<\n TData = any,\n TVariables = OperationVariables,\n TContext = DefaultContext,\n TCache extends ApolloCache<any> = ApolloCache<any>,\n>(\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: MutationHookOptions<TData, TVariables, TContext, TCache>,\n): MutationTuple<TData, TVariables, TContext, TCache> {\n const client = useApolloClient(options?.client);\n verifyDocumentType(mutation, DocumentType.Mutation);\n const [result, setResult] = useState<Omit<MutationResult, 'reset'>>({\n called: false,\n loading: false,\n client,\n });\n\n const ref = useRef({\n result,\n mutationId: 0,\n isMounted: true,\n client,\n mutation,\n options,\n });\n\n // TODO: Trying to assign these in a useEffect or useLayoutEffect breaks\n // higher-order components.\n {\n Object.assign(ref.current, { client, options, mutation });\n }\n\n const execute = useCallback((\n executeOptions: MutationFunctionOptions<\n TData,\n TVariables,\n TContext,\n TCache\n > = {}\n ) => {\n const {client, options, mutation} = ref.current;\n const baseOptions = { ...options, mutation };\n if (!ref.current.result.loading && !baseOptions.ignoreResults && ref.current.isMounted) {\n setResult(ref.current.result = {\n loading: true,\n error: void 0,\n data: void 0,\n called: true,\n client,\n });\n }\n\n const mutationId = ++ref.current.mutationId;\n const clientOptions = mergeOptions(\n baseOptions,\n executeOptions as any,\n );\n\n return client.mutate(clientOptions).then((response) => {\n const { data, errors } = response;\n const error =\n errors && errors.length > 0\n ? new ApolloError({ graphQLErrors: errors })\n : void 0;\n\n if (\n mutationId === ref.current.mutationId &&\n !clientOptions.ignoreResults\n ) {\n const result = {\n called: true,\n loading: false,\n data,\n error,\n client,\n };\n\n if (ref.current.isMounted && !equal(ref.current.result, result)) {\n setResult(ref.current.result = result);\n }\n }\n\n const onCompleted = executeOptions.onCompleted || ref.current.options?.onCompleted\n onCompleted?.(response.data!, clientOptions);\n\n return response;\n }).catch((error) => {\n if (\n mutationId === ref.current.mutationId &&\n ref.current.isMounted\n ) {\n const result = {\n loading: false,\n error,\n data: void 0,\n called: true,\n client,\n };\n\n if (!equal(ref.current.result, result)) {\n setResult(ref.current.result = result);\n }\n }\n\n const onError = executeOptions.onError || ref.current.options?.onError\n\n if (onError) {\n onError(error, clientOptions);\n\n // TODO(brian): why are we returning this here???\n return { data: void 0, errors: error };\n }\n\n throw error;\n });\n }, []);\n\n const reset = useCallback(() => {\n if (ref.current.isMounted) {\n setResult({ called: false, loading: false, client });\n }\n }, []);\n\n useEffect(() => {\n ref.current.isMounted = true;\n\n return () => {\n ref.current.isMounted = false;\n };\n }, []);\n\n return [execute, { reset, ...result }];\n}\n"]}
@@ -2,14 +2,14 @@ import { OperationVariables, WatchQueryFetchPolicy } from '../../core';
2
2
  import { ApolloClient, ApolloQueryResult, DocumentNode, TypedDocumentNode } from '../../core';
3
3
  import { QueryHookOptions, QueryResult } from '../types/types';
4
4
  import { useApolloClient } from './useApolloClient';
5
- export declare function useQuery<TData = any, TVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: QueryHookOptions<TData, TVariables>): QueryResult<TData, TVariables>;
6
- export declare function useInternalState<TData, TVariables>(client: ApolloClient<any>, query: DocumentNode | TypedDocumentNode<TData, TVariables>): InternalState<TData, TVariables>;
7
- declare class InternalState<TData, TVariables> {
5
+ export declare function useQuery<TData = any, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: QueryHookOptions<TData, TVariables>): QueryResult<TData, TVariables>;
6
+ export declare function useInternalState<TData, TVariables extends OperationVariables>(client: ApolloClient<any>, query: DocumentNode | TypedDocumentNode<TData, TVariables>): InternalState<TData, TVariables>;
7
+ declare class InternalState<TData, TVariables extends OperationVariables> {
8
8
  readonly client: ReturnType<typeof useApolloClient>;
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(): Promise<QueryResult<TData, TVariables>>;
12
+ asyncUpdate(signal: AbortSignal): Promise<QueryResult<TData, TVariables>>;
13
13
  private asyncResolveFns;
14
14
  private optionsToIgnoreOnce;
15
15
  useQuery(options: QueryHookOptions<TData, TVariables>): QueryResult<TData, TVariables>;
@@ -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,EAEZ,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AASpD,wBAAgB,QAAQ,CACtB,KAAK,GAAG,GAAG,EACX,UAAU,GAAG,kBAAkB,EAE/B,KAAK,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,EAC1D,OAAO,GAAE,gBAAgB,CAAC,KAAK,EAAE,UAAU,CAAuB,GACjE,WAAW,CAAC,KAAK,EAAE,UAAU,CAAC,CAKhC;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,EAChD,MAAM,EAAE,YAAY,CAAC,GAAG,CAAC,EACzB,KAAK,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,GACzD,aAAa,CAAC,KAAK,EAAE,UAAU,CAAC,CAuB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