@apollo/client 3.8.0-alpha.1 → 3.8.0-alpha.10

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 (343) hide show
  1. package/README.md +3 -1
  2. package/apollo-client.cjs +471 -291
  3. package/apollo-client.cjs.map +1 -1
  4. package/apollo-client.min.cjs +1 -1
  5. package/cache/cache.cjs +54 -44
  6. package/cache/cache.cjs.map +1 -1
  7. package/cache/cache.cjs.native.js +54 -44
  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/DataProxy.d.ts +3 -2
  12. package/cache/core/types/DataProxy.d.ts.map +1 -1
  13. package/cache/core/types/DataProxy.js.map +1 -1
  14. package/cache/core/types/common.d.ts +7 -7
  15. package/cache/core/types/common.d.ts.map +1 -1
  16. package/cache/inmemory/entityStore.d.ts +1 -1
  17. package/cache/inmemory/entityStore.d.ts.map +1 -1
  18. package/cache/inmemory/entityStore.js +1 -1
  19. package/cache/inmemory/helpers.d.ts +2 -2
  20. package/cache/inmemory/helpers.d.ts.map +1 -1
  21. package/cache/inmemory/helpers.js +2 -2
  22. package/cache/inmemory/helpers.js.map +1 -1
  23. package/cache/inmemory/inMemoryCache.d.ts +3 -2
  24. package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
  25. package/cache/inmemory/inMemoryCache.js +1 -1
  26. package/cache/inmemory/inMemoryCache.js.map +1 -1
  27. package/cache/inmemory/key-extractor.js +1 -1
  28. package/cache/inmemory/object-canon.d.ts +0 -1
  29. package/cache/inmemory/object-canon.d.ts.map +1 -1
  30. package/cache/inmemory/object-canon.js +1 -1
  31. package/cache/inmemory/object-canon.js.map +1 -1
  32. package/cache/inmemory/policies.d.ts +12 -12
  33. package/cache/inmemory/policies.d.ts.map +1 -1
  34. package/cache/inmemory/policies.js +15 -4
  35. package/cache/inmemory/policies.js.map +1 -1
  36. package/cache/inmemory/reactiveVars.d.ts +1 -1
  37. package/cache/inmemory/reactiveVars.d.ts.map +1 -1
  38. package/cache/inmemory/readFromStore.d.ts +2 -2
  39. package/cache/inmemory/readFromStore.d.ts.map +1 -1
  40. package/cache/inmemory/readFromStore.js +1 -1
  41. package/cache/inmemory/readFromStore.js.map +1 -1
  42. package/cache/inmemory/types.d.ts +4 -4
  43. package/cache/inmemory/types.d.ts.map +1 -1
  44. package/cache/inmemory/writeToStore.d.ts +1 -1
  45. package/cache/inmemory/writeToStore.d.ts.map +1 -1
  46. package/cache/inmemory/writeToStore.js +1 -1
  47. package/cache/inmemory/writeToStore.js.map +1 -1
  48. package/core/ApolloClient.d.ts +10 -9
  49. package/core/ApolloClient.d.ts.map +1 -1
  50. package/core/ApolloClient.js +11 -5
  51. package/core/ApolloClient.js.map +1 -1
  52. package/core/LocalState.d.ts +12 -7
  53. package/core/LocalState.d.ts.map +1 -1
  54. package/core/LocalState.js +71 -17
  55. package/core/LocalState.js.map +1 -1
  56. package/core/ObservableQuery.d.ts +5 -5
  57. package/core/ObservableQuery.d.ts.map +1 -1
  58. package/core/ObservableQuery.js +2 -2
  59. package/core/ObservableQuery.js.map +1 -1
  60. package/core/QueryInfo.d.ts +1 -1
  61. package/core/QueryInfo.d.ts.map +1 -1
  62. package/core/QueryInfo.js +1 -1
  63. package/core/QueryInfo.js.map +1 -1
  64. package/core/QueryManager.d.ts +7 -7
  65. package/core/QueryManager.d.ts.map +1 -1
  66. package/core/QueryManager.js +22 -12
  67. package/core/QueryManager.js.map +1 -1
  68. package/core/core.cjs +132 -69
  69. package/core/core.cjs.map +1 -1
  70. package/core/core.cjs.native.js +132 -69
  71. package/core/index.js +2 -2
  72. package/core/index.js.map +1 -1
  73. package/core/types.d.ts +21 -17
  74. package/core/types.d.ts.map +1 -1
  75. package/core/types.js +1 -0
  76. package/core/types.js.map +1 -1
  77. package/core/watchQueryOptions.d.ts +11 -11
  78. package/core/watchQueryOptions.d.ts.map +1 -1
  79. package/core/watchQueryOptions.js.map +1 -1
  80. package/errors/index.d.ts +2 -2
  81. package/errors/index.d.ts.map +1 -1
  82. package/invariantErrorCodes.js +36 -35
  83. package/link/batch/batch.cjs +5 -3
  84. package/link/batch/batch.cjs.map +1 -1
  85. package/link/batch/batch.cjs.native.js +5 -3
  86. package/link/batch/batching.d.ts +2 -2
  87. package/link/batch/batching.d.ts.map +1 -1
  88. package/link/batch/batching.js +5 -3
  89. package/link/batch/batching.js.map +1 -1
  90. package/link/batch-http/batch-http.cjs +12 -2
  91. package/link/batch-http/batch-http.cjs.map +1 -1
  92. package/link/batch-http/batch-http.cjs.native.js +12 -2
  93. package/link/batch-http/batchHttpLink.d.ts.map +1 -1
  94. package/link/batch-http/batchHttpLink.js +13 -3
  95. package/link/batch-http/batchHttpLink.js.map +1 -1
  96. package/link/context/index.d.ts +2 -1
  97. package/link/context/index.d.ts.map +1 -1
  98. package/link/context/index.js.map +1 -1
  99. package/link/core/ApolloLink.js +2 -2
  100. package/link/core/core.cjs +2 -2
  101. package/link/core/core.cjs.map +1 -1
  102. package/link/core/core.cjs.native.js +2 -2
  103. package/link/core/types.d.ts +15 -15
  104. package/link/core/types.d.ts.map +1 -1
  105. package/link/core/types.js.map +1 -1
  106. package/link/http/checkFetcher.js +2 -2
  107. package/link/http/createHttpLink.d.ts +0 -1
  108. package/link/http/createHttpLink.d.ts.map +1 -1
  109. package/link/http/createHttpLink.js +10 -2
  110. package/link/http/createHttpLink.js.map +1 -1
  111. package/link/http/http.cjs +20 -38
  112. package/link/http/http.cjs.map +1 -1
  113. package/link/http/http.cjs.native.js +20 -38
  114. package/link/http/iterators/async.js.map +1 -1
  115. package/link/http/iterators/nodeStream.js.map +1 -1
  116. package/link/http/iterators/promise.js.map +1 -1
  117. package/link/http/iterators/reader.js.map +1 -1
  118. package/link/http/parseAndCheckHttpResponse.d.ts +2 -2
  119. package/link/http/parseAndCheckHttpResponse.d.ts.map +1 -1
  120. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  121. package/link/http/responseIterator.js +1 -1
  122. package/link/http/responseIterator.js.map +1 -1
  123. package/link/http/selectHttpOptionsAndBody.d.ts +2 -2
  124. package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
  125. package/link/http/selectHttpOptionsAndBody.js +3 -1
  126. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  127. package/link/http/serializeFetchParameter.d.ts +1 -1
  128. package/link/http/serializeFetchParameter.d.ts.map +1 -1
  129. package/link/http/serializeFetchParameter.js +2 -2
  130. package/link/persisted-queries/index.d.ts +2 -2
  131. package/link/persisted-queries/index.d.ts.map +1 -1
  132. package/link/persisted-queries/index.js +3 -3
  133. package/link/persisted-queries/persisted-queries.cjs +3 -3
  134. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  135. package/link/persisted-queries/persisted-queries.cjs.native.js +3 -3
  136. package/link/utils/throwServerError.d.ts +1 -1
  137. package/link/utils/throwServerError.d.ts.map +1 -1
  138. package/link/utils/toPromise.js +1 -1
  139. package/link/utils/utils.cjs +2 -2
  140. package/link/utils/utils.cjs.map +1 -1
  141. package/link/utils/utils.cjs.native.js +2 -2
  142. package/link/utils/validateOperation.js +2 -2
  143. package/package.json +25 -23
  144. package/react/cache/SuspenseCache.d.ts +1 -1
  145. package/react/cache/SuspenseCache.d.ts.map +1 -1
  146. package/react/cache/SuspenseCache.js.map +1 -1
  147. package/react/components/Query.d.ts +2 -2
  148. package/react/components/Query.d.ts.map +1 -1
  149. package/react/components/Query.js.map +1 -1
  150. package/react/components/Subscription.d.ts +2 -2
  151. package/react/components/Subscription.d.ts.map +1 -1
  152. package/react/components/Subscription.js.map +1 -1
  153. package/react/components/types.d.ts +2 -2
  154. package/react/components/types.d.ts.map +1 -1
  155. package/react/components/types.js.map +1 -1
  156. package/react/context/ApolloConsumer.js +2 -2
  157. package/react/context/ApolloProvider.js +2 -2
  158. package/react/context/context.cjs +4 -4
  159. package/react/context/context.cjs.map +1 -1
  160. package/react/context/context.cjs.native.js +4 -4
  161. package/react/hoc/graphql.d.ts +2 -1
  162. package/react/hoc/graphql.d.ts.map +1 -1
  163. package/react/hoc/graphql.js.map +1 -1
  164. package/react/hoc/hoc-utils.d.ts +1 -1
  165. package/react/hoc/hoc-utils.d.ts.map +1 -1
  166. package/react/hoc/hoc-utils.js +2 -2
  167. package/react/hoc/hoc.cjs +4 -4
  168. package/react/hoc/hoc.cjs.map +1 -1
  169. package/react/hoc/hoc.cjs.native.js +4 -4
  170. package/react/hoc/mutation-hoc.d.ts +2 -2
  171. package/react/hoc/mutation-hoc.d.ts.map +1 -1
  172. package/react/hoc/mutation-hoc.js.map +1 -1
  173. package/react/hoc/query-hoc.d.ts +1 -1
  174. package/react/hoc/query-hoc.d.ts.map +1 -1
  175. package/react/hoc/query-hoc.js.map +1 -1
  176. package/react/hoc/subscription-hoc.d.ts +1 -1
  177. package/react/hoc/subscription-hoc.d.ts.map +1 -1
  178. package/react/hoc/subscription-hoc.js.map +1 -1
  179. package/react/hoc/types.d.ts +6 -6
  180. package/react/hoc/types.d.ts.map +1 -1
  181. package/react/hoc/types.js.map +1 -1
  182. package/react/hoc/withApollo.js +2 -2
  183. package/react/hooks/hooks.cjs +129 -69
  184. package/react/hooks/hooks.cjs.map +1 -1
  185. package/react/hooks/hooks.cjs.native.js +129 -69
  186. package/react/hooks/internal/index.d.ts +1 -0
  187. package/react/hooks/internal/index.d.ts.map +1 -1
  188. package/react/hooks/internal/index.js +1 -0
  189. package/react/hooks/internal/index.js.map +1 -1
  190. package/react/hooks/internal/useIsomorphicLayoutEffect.d.ts +3 -0
  191. package/react/hooks/internal/useIsomorphicLayoutEffect.d.ts.map +1 -0
  192. package/react/hooks/internal/useIsomorphicLayoutEffect.js +6 -0
  193. package/react/hooks/internal/useIsomorphicLayoutEffect.js.map +1 -0
  194. package/react/hooks/useApolloClient.js +2 -2
  195. package/react/hooks/useFragment.d.ts +4 -2
  196. package/react/hooks/useFragment.d.ts.map +1 -1
  197. package/react/hooks/useFragment.js +9 -8
  198. package/react/hooks/useFragment.js.map +1 -1
  199. package/react/hooks/useLazyQuery.d.ts +2 -2
  200. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  201. package/react/hooks/useLazyQuery.js +22 -8
  202. package/react/hooks/useLazyQuery.js.map +1 -1
  203. package/react/hooks/useMutation.d.ts +2 -2
  204. package/react/hooks/useMutation.d.ts.map +1 -1
  205. package/react/hooks/useMutation.js +9 -8
  206. package/react/hooks/useMutation.js.map +1 -1
  207. package/react/hooks/useQuery.d.ts +6 -5
  208. package/react/hooks/useQuery.d.ts.map +1 -1
  209. package/react/hooks/useQuery.js +21 -7
  210. package/react/hooks/useQuery.js.map +1 -1
  211. package/react/hooks/useSubscription.d.ts +2 -3
  212. package/react/hooks/useSubscription.d.ts.map +1 -1
  213. package/react/hooks/useSubscription.js +1 -2
  214. package/react/hooks/useSubscription.js.map +1 -1
  215. package/react/hooks/useSuspenseCache.d.ts +2 -1
  216. package/react/hooks/useSuspenseCache.d.ts.map +1 -1
  217. package/react/hooks/useSuspenseCache.js +7 -5
  218. package/react/hooks/useSuspenseCache.js.map +1 -1
  219. package/react/hooks/useSuspenseQuery.d.ts +11 -4
  220. package/react/hooks/useSuspenseQuery.d.ts.map +1 -1
  221. package/react/hooks/useSuspenseQuery.js +54 -30
  222. package/react/hooks/useSuspenseQuery.js.map +1 -1
  223. package/react/hooks/useSyncExternalStore.d.ts +1 -1
  224. package/react/hooks/useSyncExternalStore.d.ts.map +1 -1
  225. package/react/hooks/useSyncExternalStore.js +1 -1
  226. package/react/hooks/useSyncExternalStore.js.map +1 -1
  227. package/react/parser/index.js +6 -6
  228. package/react/parser/parser.cjs +10 -10
  229. package/react/parser/parser.cjs.map +1 -1
  230. package/react/parser/parser.cjs.native.js +10 -10
  231. package/react/ssr/RenderPromises.d.ts +4 -4
  232. package/react/ssr/RenderPromises.d.ts.map +1 -1
  233. package/react/ssr/RenderPromises.js.map +1 -1
  234. package/react/ssr/getDataFromTree.d.ts +1 -1
  235. package/react/ssr/getDataFromTree.d.ts.map +1 -1
  236. package/react/types/types.d.ts +26 -23
  237. package/react/types/types.d.ts.map +1 -1
  238. package/react/types/types.js.map +1 -1
  239. package/testing/core/core.cjs +30 -3
  240. package/testing/core/core.cjs.map +1 -1
  241. package/testing/core/core.cjs.native.js +30 -3
  242. package/testing/core/index.d.ts +2 -1
  243. package/testing/core/index.d.ts.map +1 -1
  244. package/testing/core/index.js +1 -0
  245. package/testing/core/index.js.map +1 -1
  246. package/testing/core/itAsync.js.map +1 -1
  247. package/testing/core/mocking/mockFetch.js.map +1 -1
  248. package/testing/core/mocking/mockLink.d.ts +8 -4
  249. package/testing/core/mocking/mockLink.d.ts.map +1 -1
  250. package/testing/core/mocking/mockLink.js +14 -4
  251. package/testing/core/mocking/mockLink.js.map +1 -1
  252. package/testing/core/mocking/mockQueryManager.d.ts +1 -1
  253. package/testing/core/mocking/mockQueryManager.d.ts.map +1 -1
  254. package/testing/core/mocking/mockQueryManager.js +3 -3
  255. package/testing/core/mocking/mockQueryManager.js.map +1 -1
  256. package/testing/core/mocking/mockWatchQuery.d.ts +1 -1
  257. package/testing/core/mocking/mockWatchQuery.d.ts.map +1 -1
  258. package/testing/core/mocking/mockWatchQuery.js +4 -5
  259. package/testing/core/mocking/mockWatchQuery.js.map +1 -1
  260. package/testing/core/observableToPromise.d.ts +2 -2
  261. package/testing/core/observableToPromise.d.ts.map +1 -1
  262. package/testing/core/observableToPromise.js.map +1 -1
  263. package/testing/core/wait.d.ts +3 -0
  264. package/testing/core/wait.d.ts.map +1 -0
  265. package/testing/core/wait.js +16 -0
  266. package/testing/core/wait.js.map +1 -0
  267. package/testing/react/MockedProvider.d.ts +1 -0
  268. package/testing/react/MockedProvider.d.ts.map +1 -1
  269. package/testing/react/MockedProvider.js +2 -2
  270. package/testing/react/MockedProvider.js.map +1 -1
  271. package/testing/testing.cjs +2 -2
  272. package/testing/testing.cjs.map +1 -1
  273. package/testing/testing.cjs.native.js +2 -2
  274. package/utilities/common/arrays.d.ts +1 -0
  275. package/utilities/common/arrays.d.ts.map +1 -1
  276. package/utilities/common/arrays.js +1 -0
  277. package/utilities/common/arrays.js.map +1 -1
  278. package/utilities/common/cloneDeep.js.map +1 -1
  279. package/utilities/common/errorHandling.d.ts +2 -2
  280. package/utilities/common/errorHandling.d.ts.map +1 -1
  281. package/utilities/common/errorHandling.js.map +1 -1
  282. package/utilities/common/incrementalResult.d.ts +4 -4
  283. package/utilities/common/incrementalResult.d.ts.map +1 -1
  284. package/utilities/common/incrementalResult.js.map +1 -1
  285. package/utilities/common/maybeDeepFreeze.d.ts +0 -1
  286. package/utilities/common/maybeDeepFreeze.d.ts.map +1 -1
  287. package/utilities/common/maybeDeepFreeze.js +1 -1
  288. package/utilities/common/maybeDeepFreeze.js.map +1 -1
  289. package/utilities/common/mergeDeep.d.ts +2 -2
  290. package/utilities/common/mergeDeep.d.ts.map +1 -1
  291. package/utilities/common/mergeOptions.d.ts +3 -3
  292. package/utilities/common/mergeOptions.d.ts.map +1 -1
  293. package/utilities/common/mergeOptions.js.map +1 -1
  294. package/utilities/globals/DEV.d.ts +1 -1
  295. package/utilities/globals/DEV.d.ts.map +1 -1
  296. package/utilities/globals/DEV.js +1 -17
  297. package/utilities/globals/DEV.js.map +1 -1
  298. package/utilities/globals/global.d.ts +5 -2
  299. package/utilities/globals/global.d.ts.map +1 -1
  300. package/utilities/globals/global.js.map +1 -1
  301. package/utilities/globals/globals.cjs +5 -22
  302. package/utilities/globals/globals.cjs.map +1 -1
  303. package/utilities/globals/globals.cjs.native.js +5 -22
  304. package/utilities/globals/index.d.ts +1 -1
  305. package/utilities/globals/index.d.ts.map +1 -1
  306. package/utilities/globals/index.js +1 -4
  307. package/utilities/globals/index.js.map +1 -1
  308. package/utilities/graphql/directives.d.ts +2 -2
  309. package/utilities/graphql/directives.d.ts.map +1 -1
  310. package/utilities/graphql/directives.js +1 -1
  311. package/utilities/graphql/directives.js.map +1 -1
  312. package/utilities/graphql/fragments.d.ts +1 -1
  313. package/utilities/graphql/fragments.d.ts.map +1 -1
  314. package/utilities/graphql/fragments.js +1 -1
  315. package/utilities/graphql/getFromAST.d.ts.map +1 -1
  316. package/utilities/graphql/getFromAST.js +8 -4
  317. package/utilities/graphql/getFromAST.js.map +1 -1
  318. package/utilities/graphql/storeUtils.d.ts +3 -3
  319. package/utilities/graphql/storeUtils.d.ts.map +1 -1
  320. package/utilities/graphql/storeUtils.js +1 -1
  321. package/utilities/graphql/storeUtils.js.map +1 -1
  322. package/utilities/graphql/transform.d.ts +9 -9
  323. package/utilities/graphql/transform.d.ts.map +1 -1
  324. package/utilities/graphql/transform.js +168 -91
  325. package/utilities/graphql/transform.js.map +1 -1
  326. package/utilities/index.d.ts +2 -0
  327. package/utilities/index.d.ts.map +1 -1
  328. package/utilities/index.js +2 -0
  329. package/utilities/index.js.map +1 -1
  330. package/utilities/observables/Concast.d.ts +5 -5
  331. package/utilities/observables/Concast.d.ts.map +1 -1
  332. package/utilities/observables/Concast.js +2 -2
  333. package/utilities/observables/Concast.js.map +1 -1
  334. package/utilities/observables/asyncMap.js.map +1 -1
  335. package/utilities/policies/pagination.d.ts +7 -7
  336. package/utilities/policies/pagination.d.ts.map +1 -1
  337. package/utilities/policies/pagination.js.map +1 -1
  338. package/utilities/types/IsStrictlyAny.d.ts +3 -3
  339. package/utilities/types/IsStrictlyAny.d.ts.map +1 -1
  340. package/utilities/utilities.cjs +252 -124
  341. package/utilities/utilities.cjs.map +1 -1
  342. package/utilities/utilities.cjs.native.js +252 -124
  343. 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
  };
@@ -182,7 +190,7 @@ var InternalState = (function () {
182
190
  }
183
191
  };
184
192
  var subscription = obsQuery.subscribe(onNext, onError);
185
- return function () { return subscription.unsubscribe(); };
193
+ return function () { return setTimeout(function () { return subscription.unsubscribe(); }); };
186
194
  }, [
187
195
  obsQuery,
188
196
  this.renderPromises,
@@ -309,9 +317,10 @@ var InternalState = (function () {
309
317
  InternalState.prototype.handleErrorOrCompleted = function (result, previousResult) {
310
318
  var _this = this;
311
319
  if (!result.loading) {
320
+ var error_1 = this.toApolloError(result);
312
321
  Promise.resolve().then(function () {
313
- if (result.error) {
314
- _this.onError(result.error);
322
+ if (error_1) {
323
+ _this.onError(error_1);
315
324
  }
316
325
  else if (result.data &&
317
326
  (previousResult === null || previousResult === void 0 ? void 0 : previousResult.networkStatus) !== result.networkStatus &&
@@ -319,10 +328,15 @@ var InternalState = (function () {
319
328
  _this.onCompleted(result.data);
320
329
  }
321
330
  }).catch(function (error) {
322
- __DEV__ && globals.invariant.warn(error);
331
+ globals.__DEV__ && globals.invariant.warn(error);
323
332
  });
324
333
  }
325
334
  };
335
+ InternalState.prototype.toApolloError = function (result) {
336
+ return utilities.isNonEmptyArray(result.errors)
337
+ ? new errors.ApolloError({ graphQLErrors: result.errors })
338
+ : result.error;
339
+ };
326
340
  InternalState.prototype.getCurrentResult = function () {
327
341
  if (!this.result) {
328
342
  this.handleErrorOrCompleted(this.result = this.observable.getCurrentResult());
@@ -365,11 +379,11 @@ var EAGER_METHODS = [
365
379
  'subscribeToMore',
366
380
  ];
367
381
  function useLazyQuery(query, options) {
368
- var internalState = useInternalState(useApolloClient(options && options.client), query);
382
+ var _a, _b;
383
+ var abortControllersRef = React.useRef(new Set());
369
384
  var execOptionsRef = React.useRef();
370
- var merged = execOptionsRef.current
371
- ? utilities.mergeOptions(options, execOptionsRef.current)
372
- : options;
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);
373
387
  var useQueryResult = internalState.useQuery(tslib.__assign(tslib.__assign({}, merged), { skip: !execOptionsRef.current }));
374
388
  var initialFetchPolicy = useQueryResult.observable.options.initialFetchPolicy ||
375
389
  internalState.getDefaultFetchPolicy();
@@ -395,14 +409,28 @@ function useLazyQuery(query, options) {
395
409
  return eagerMethods;
396
410
  }, []);
397
411
  Object.assign(result, eagerMethods);
412
+ React.useEffect(function () {
413
+ return function () {
414
+ abortControllersRef.current.forEach(function (controller) {
415
+ controller.abort();
416
+ });
417
+ };
418
+ }, []);
398
419
  var execute = React.useCallback(function (executeOptions) {
420
+ var controller = new AbortController();
421
+ abortControllersRef.current.add(controller);
399
422
  execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
400
423
  fetchPolicy: initialFetchPolicy,
401
424
  };
402
425
  var promise = internalState
403
- .asyncUpdate()
404
- .then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
405
- 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
+ });
406
434
  return promise;
407
435
  }, []);
408
436
  return [execute, result];
@@ -429,8 +457,9 @@ function useMutation(mutation, options) {
429
457
  }
430
458
  var execute = React.useCallback(function (executeOptions) {
431
459
  if (executeOptions === void 0) { executeOptions = {}; }
432
- var _a = ref.current, client = _a.client, options = _a.options, mutation = _a.mutation;
460
+ var _a = ref.current, options = _a.options, mutation = _a.mutation;
433
461
  var baseOptions = tslib.__assign(tslib.__assign({}, options), { mutation: mutation });
462
+ var client = executeOptions.client || ref.current.client;
434
463
  if (!ref.current.result.loading && !baseOptions.ignoreResults && ref.current.isMounted) {
435
464
  setResult(ref.current.result = {
436
465
  loading: true,
@@ -443,7 +472,7 @@ function useMutation(mutation, options) {
443
472
  var mutationId = ++ref.current.mutationId;
444
473
  var clientOptions = core.mergeOptions(baseOptions, executeOptions);
445
474
  return client.mutate(clientOptions).then(function (response) {
446
- var _a, _b, _c;
475
+ var _a;
447
476
  var data = response.data, errors$1 = response.errors;
448
477
  var error = errors$1 && errors$1.length > 0
449
478
  ? new errors.ApolloError({ graphQLErrors: errors$1 })
@@ -461,11 +490,11 @@ function useMutation(mutation, options) {
461
490
  setResult(ref.current.result = result_1);
462
491
  }
463
492
  }
464
- (_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);
465
- (_c = executeOptions.onCompleted) === null || _c === void 0 ? void 0 : _c.call(executeOptions, response.data, clientOptions);
493
+ var onCompleted = executeOptions.onCompleted || ((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onCompleted);
494
+ onCompleted === null || onCompleted === void 0 ? void 0 : onCompleted(response.data, clientOptions);
466
495
  return response;
467
496
  }).catch(function (error) {
468
- var _a, _b, _c, _d;
497
+ var _a;
469
498
  if (mutationId === ref.current.mutationId &&
470
499
  ref.current.isMounted) {
471
500
  var result_2 = {
@@ -479,9 +508,9 @@ function useMutation(mutation, options) {
479
508
  setResult(ref.current.result = result_2);
480
509
  }
481
510
  }
482
- if (((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) || clientOptions.onError) {
483
- (_c = (_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.onError) === null || _c === void 0 ? void 0 : _c.call(_b, error, clientOptions);
484
- (_d = executeOptions.onError) === null || _d === void 0 ? void 0 : _d.call(executeOptions, error, clientOptions);
511
+ var onError = executeOptions.onError || ((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError);
512
+ if (onError) {
513
+ onError(error, clientOptions);
485
514
  return { data: void 0, errors: error };
486
515
  }
487
516
  throw error;
@@ -514,12 +543,12 @@ function useSubscription(subscription, options) {
514
543
  if (!hasIssuedDeprecationWarningRef.current) {
515
544
  hasIssuedDeprecationWarningRef.current = true;
516
545
  if (options === null || options === void 0 ? void 0 : options.onSubscriptionData) {
517
- __DEV__ && globals.invariant.warn(options.onData
546
+ globals.__DEV__ && globals.invariant.warn(options.onData
518
547
  ? "'useSubscription' supports only the 'onSubscriptionData' or 'onData' option, but not both. Only the 'onData' option will be used."
519
548
  : "'onSubscriptionData' is deprecated and will be removed in a future major version. Please use the 'onData' option instead.");
520
549
  }
521
550
  if (options === null || options === void 0 ? void 0 : options.onSubscriptionComplete) {
522
- __DEV__ && globals.invariant.warn(options.onComplete
551
+ globals.__DEV__ && globals.invariant.warn(options.onComplete
523
552
  ? "'useSubscription' supports only the 'onSubscriptionComplete' or 'onComplete' option, but not both. Only the 'onComplete' option will be used."
524
553
  : "'onSubscriptionComplete' is deprecated and will be removed in a future major version. Please use the 'onComplete' option instead.");
525
554
  }
@@ -658,20 +687,21 @@ function useFragment_experimental(options) {
658
687
  var diffOptions = tslib.__assign(tslib.__assign({}, rest), { id: typeof from === "string" ? from : cache.identify(from), query: cache["getFragmentDoc"](fragment, fragmentName), optimistic: optimistic });
659
688
  var resultRef = React.useRef();
660
689
  var latestDiff = cache.diff(diffOptions);
690
+ var getSnapshot = function () {
691
+ var latestDiffToResult = diffToResult(latestDiff);
692
+ return resultRef.current &&
693
+ equality.equal(resultRef.current.data, latestDiffToResult.data)
694
+ ? resultRef.current
695
+ : (resultRef.current = latestDiffToResult);
696
+ };
661
697
  return useSyncExternalStore(function (forceUpdate) {
662
698
  return cache.watch(tslib.__assign(tslib.__assign({}, diffOptions), { immediate: true, callback: function (diff) {
663
699
  if (!equality.equal(diff, latestDiff)) {
664
- resultRef.current = diffToResult(latestDiff = diff);
700
+ resultRef.current = diffToResult((latestDiff = diff));
665
701
  forceUpdate();
666
702
  }
667
703
  } }));
668
- }, function () {
669
- var latestDiffToResult = diffToResult(latestDiff);
670
- return resultRef.current &&
671
- equality.equal(resultRef.current.data, latestDiffToResult.data)
672
- ? resultRef.current
673
- : (resultRef.current = latestDiffToResult);
674
- });
704
+ }, getSnapshot, getSnapshot);
675
705
  }
676
706
  function diffToResult(diff) {
677
707
  var result = {
@@ -692,10 +722,16 @@ function useDeepMemo(memoFn, deps) {
692
722
  return ref.current.value;
693
723
  }
694
724
 
695
- function useSuspenseCache() {
696
- var suspenseCache = React.useContext(context.getApolloContext()).suspenseCache;
697
- __DEV__ ? globals.invariant(suspenseCache, 'Could not find a "suspenseCache" in the context. Wrap the root component ' +
698
- 'in an <ApolloProvider> and provide a suspenseCache.') : globals.invariant(suspenseCache, 32);
725
+ var useIsomorphicLayoutEffect = utilities.canUseLayoutEffect
726
+ ? React.useLayoutEffect
727
+ : React.useEffect;
728
+
729
+ function useSuspenseCache(override) {
730
+ var context$1 = React.useContext(context.getApolloContext());
731
+ var suspenseCache = override || context$1.suspenseCache;
732
+ globals.__DEV__ ? globals.invariant(suspenseCache, 'Could not find a "suspenseCache" in the context or passed in as an option. ' +
733
+ 'Wrap the root component in an <ApolloProvider> and provide a suspenseCache, ' +
734
+ 'or pass a SuspenseCache instance in via options.') : globals.invariant(suspenseCache, 33);
699
735
  return suspenseCache;
700
736
  }
701
737
 
@@ -710,7 +746,7 @@ var DEFAULT_SUSPENSE_POLICY = 'always';
710
746
  var DEFAULT_ERROR_POLICY = 'none';
711
747
  function useSuspenseQuery_experimental(query, options) {
712
748
  if (options === void 0) { options = Object.create(null); }
713
- var suspenseCache = useSuspenseCache();
749
+ var suspenseCache = useSuspenseCache(options.suspenseCache);
714
750
  var client = useApolloClient(options.client);
715
751
  var watchQueryOptions = useWatchQueryOptions({ query: query, options: options, client: client });
716
752
  var previousWatchQueryOptionsRef = React.useRef(watchQueryOptions);
@@ -724,9 +760,9 @@ function useSuspenseQuery_experimental(query, options) {
724
760
  var hasFullResult = result.data && !result.partial;
725
761
  var hasPartialResult = result.data && result.partial;
726
762
  var usePartialResult = returnPartialData && hasPartialResult;
763
+ var allowsThrownErrors = errorPolicy === 'none' && (!deferred || !hasPartialResult);
727
764
  if (result.error &&
728
- errorPolicy === 'none' &&
729
- (!deferred || !hasPartialResult)) {
765
+ (result.error.networkError || allowsThrownErrors)) {
730
766
  throw result.error;
731
767
  }
732
768
  if (result.loading) {
@@ -759,28 +795,42 @@ function useSuspenseQuery_experimental(query, options) {
759
795
  suspenseCache.remove(query, variables);
760
796
  };
761
797
  }, []);
798
+ var fetchMore = React.useCallback(function (options) {
799
+ var promise = observable.fetchMore(options);
800
+ suspenseCache.add(query, watchQueryOptions.variables, {
801
+ promise: promise,
802
+ observable: observable,
803
+ });
804
+ return promise;
805
+ }, [observable]);
806
+ var refetch = React.useCallback(function (variables) {
807
+ var promise = observable.refetch(variables);
808
+ suspenseCache.add(query, watchQueryOptions.variables, {
809
+ promise: promise,
810
+ observable: observable,
811
+ });
812
+ return promise;
813
+ }, [observable]);
814
+ var subscribeToMore = React.useCallback(function (options) { return observable.subscribeToMore(options); }, [observable]);
762
815
  return React.useMemo(function () {
763
816
  return {
817
+ client: client,
764
818
  data: result.data,
765
819
  error: errorPolicy === 'ignore' ? void 0 : toApolloError(result),
766
- fetchMore: function (options) {
767
- var promise = observable.fetchMore(options);
768
- suspenseCache.add(query, watchQueryOptions.variables, {
769
- promise: promise,
770
- observable: observable,
771
- });
772
- return promise;
773
- },
774
- refetch: function (variables) {
775
- var promise = observable.refetch(variables);
776
- suspenseCache.add(query, watchQueryOptions.variables, {
777
- promise: promise,
778
- observable: observable,
779
- });
780
- return promise;
781
- },
820
+ networkStatus: result.networkStatus,
821
+ fetchMore: fetchMore,
822
+ refetch: refetch,
823
+ subscribeToMore: subscribeToMore,
782
824
  };
783
- }, [result, observable, errorPolicy]);
825
+ }, [
826
+ client,
827
+ fetchMore,
828
+ refetch,
829
+ result,
830
+ observable,
831
+ errorPolicy,
832
+ subscribeToMore,
833
+ ]);
784
834
  }
785
835
  function validateOptions(options) {
786
836
  var query = options.query, _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? DEFAULT_FETCH_POLICY : _a, returnPartialData = options.returnPartialData;
@@ -789,11 +839,11 @@ function validateOptions(options) {
789
839
  validatePartialDataReturn(fetchPolicy, returnPartialData);
790
840
  }
791
841
  function validateFetchPolicy(fetchPolicy) {
792
- __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);
842
+ 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);
793
843
  }
794
844
  function validatePartialDataReturn(fetchPolicy, returnPartialData) {
795
845
  if (fetchPolicy === 'no-cache' && returnPartialData) {
796
- __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.');
846
+ 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.');
797
847
  }
798
848
  }
799
849
  function toApolloError(result) {
@@ -823,7 +873,7 @@ function useWatchQueryOptions(_a) {
823
873
  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"]);
824
874
  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)) });
825
875
  }, [options, query, defaultOptions]);
826
- if (__DEV__) {
876
+ if (globals.__DEV__) {
827
877
  validateOptions(watchQueryOptions);
828
878
  }
829
879
  return watchQueryOptions;
@@ -834,16 +884,18 @@ function useIsDeferred(query) {
834
884
  function useObservableQueryResult(observable) {
835
885
  var resultRef = React.useRef();
836
886
  var isMountedRef = React.useRef(false);
887
+ var subscribeTimeoutRef = React.useRef();
837
888
  if (!resultRef.current) {
838
889
  resultRef.current = observable.getCurrentResult();
839
890
  }
840
- React.useLayoutEffect(function () {
891
+ useIsomorphicLayoutEffect(function () {
841
892
  isMountedRef.current = true;
842
893
  return function () {
843
894
  isMountedRef.current = false;
844
895
  };
845
896
  }, []);
846
897
  return useSyncExternalStore(React.useCallback(function (forceUpdate) {
898
+ clearTimeout(subscribeTimeoutRef.current);
847
899
  function handleUpdate() {
848
900
  var previousResult = resultRef.current;
849
901
  var result = observable.getCurrentResult();
@@ -857,12 +909,20 @@ function useObservableQueryResult(observable) {
857
909
  forceUpdate();
858
910
  }
859
911
  }
860
- var subscription = observable.subscribe({
861
- next: handleUpdate,
862
- error: handleUpdate,
912
+ var subscription;
913
+ subscribeTimeoutRef.current = setTimeout(function () {
914
+ subscription = observable.subscribe({
915
+ next: handleUpdate,
916
+ error: handleUpdate,
917
+ });
918
+ var result = resultRef.current;
919
+ if (result.networkStatus !== observable['queryInfo'].networkStatus &&
920
+ result.networkStatus === core.NetworkStatus.ready) {
921
+ observable['queryInfo'].markReady();
922
+ }
863
923
  });
864
924
  return function () {
865
- subscription.unsubscribe();
925
+ subscription === null || subscription === void 0 ? void 0 : subscription.unsubscribe();
866
926
  };
867
927
  }, [observable]), function () { return resultRef.current; }, function () { return resultRef.current; });
868
928
  }