@apollo/client 3.9.0-alpha.4 → 3.9.0-beta.0

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 (738) hide show
  1. package/.changeset/README.md +8 -0
  2. package/.changeset/beige-geese-wink.md +5 -0
  3. package/.changeset/breezy-spiders-tap.md +38 -0
  4. package/.changeset/clean-items-smash.md +5 -0
  5. package/.changeset/cold-llamas-turn.md +8 -0
  6. package/.changeset/config.json +14 -0
  7. package/.changeset/dirty-kids-crash.md +5 -0
  8. package/.changeset/dirty-tigers-matter.md +13 -0
  9. package/.changeset/forty-cups-shop.md +5 -0
  10. package/.changeset/friendly-clouds-laugh.md +7 -0
  11. package/.changeset/hot-ducks-burn.md +5 -0
  12. package/.changeset/mighty-coats-check.md +47 -0
  13. package/.changeset/polite-avocados-warn.md +5 -0
  14. package/.changeset/pre.json +37 -0
  15. package/.changeset/quick-hats-marry.md +5 -0
  16. package/.changeset/rare-snakes-melt.md +24 -0
  17. package/.changeset/shaggy-ears-scream.md +5 -0
  18. package/.changeset/shaggy-sheep-pull.md +5 -0
  19. package/.changeset/sixty-boxes-rest.md +8 -0
  20. package/.changeset/sour-sheep-walk.md +7 -0
  21. package/.changeset/strong-terms-perform.md +46 -0
  22. package/.changeset/swift-zoos-collect.md +19 -0
  23. package/.changeset/thick-mice-collect.md +5 -0
  24. package/.changeset/thick-tips-cry.md +9 -0
  25. package/.changeset/thirty-ties-arrive.md +26 -0
  26. package/.changeset/tough-timers-begin.md +8 -0
  27. package/.changeset/unlucky-rats-decide.md +5 -0
  28. package/.changeset/violet-lions-draw.md +5 -0
  29. package/.changeset/wet-forks-rhyme.md +5 -0
  30. package/.changeset/wild-dolphins-jog.md +5 -0
  31. package/.changeset/yellow-flies-repeat.md +5 -0
  32. package/CHANGELOG.md +3649 -0
  33. package/apollo-client.cjs +775 -451
  34. package/apollo-client.cjs.map +1 -1
  35. package/apollo-client.min.cjs +1 -1
  36. package/cache/cache.cjs +210 -156
  37. package/cache/cache.cjs.map +1 -1
  38. package/cache/cache.cjs.native.js +210 -156
  39. package/cache/core/cache.d.ts +19 -0
  40. package/cache/core/cache.js +28 -7
  41. package/cache/core/cache.js.map +1 -1
  42. package/cache/core/types/Cache.d.ts +8 -1
  43. package/cache/core/types/Cache.js.map +1 -1
  44. package/cache/core/types/DataProxy.d.ts +104 -0
  45. package/cache/core/types/DataProxy.js.map +1 -1
  46. package/cache/core/types/common.d.ts +5 -1
  47. package/cache/core/types/common.js +4 -1
  48. package/cache/core/types/common.js.map +1 -1
  49. package/cache/inmemory/entityStore.d.ts +10 -1
  50. package/cache/inmemory/entityStore.js +190 -29
  51. package/cache/inmemory/entityStore.js.map +1 -1
  52. package/cache/inmemory/fixPolyfills.js +9 -0
  53. package/cache/inmemory/fixPolyfills.js.map +1 -1
  54. package/cache/inmemory/fixPolyfills.native.js +12 -0
  55. package/cache/inmemory/fixPolyfills.native.js.map +1 -1
  56. package/cache/inmemory/fragmentRegistry.d.ts +1 -0
  57. package/cache/inmemory/fragmentRegistry.js +39 -14
  58. package/cache/inmemory/fragmentRegistry.js.map +1 -1
  59. package/cache/inmemory/helpers.js +20 -11
  60. package/cache/inmemory/helpers.js.map +1 -1
  61. package/cache/inmemory/inMemoryCache.d.ts +9 -0
  62. package/cache/inmemory/inMemoryCache.js +172 -10
  63. package/cache/inmemory/inMemoryCache.js.map +1 -1
  64. package/cache/inmemory/key-extractor.js +72 -4
  65. package/cache/inmemory/key-extractor.js.map +1 -1
  66. package/cache/inmemory/object-canon.js +87 -3
  67. package/cache/inmemory/object-canon.js.map +1 -1
  68. package/cache/inmemory/policies.js +190 -43
  69. package/cache/inmemory/policies.js.map +1 -1
  70. package/cache/inmemory/reactiveVars.js +20 -2
  71. package/cache/inmemory/reactiveVars.js.map +1 -1
  72. package/cache/inmemory/readFromStore.d.ts +4 -0
  73. package/cache/inmemory/readFromStore.js +65 -12
  74. package/cache/inmemory/readFromStore.js.map +1 -1
  75. package/cache/inmemory/types.d.ts +46 -0
  76. package/cache/inmemory/types.js.map +1 -1
  77. package/cache/inmemory/writeToStore.js +152 -25
  78. package/cache/inmemory/writeToStore.js.map +1 -1
  79. package/config/jest/setup.js +2 -0
  80. package/config/jest/setup.js.map +1 -1
  81. package/core/ApolloClient.d.ts +273 -3
  82. package/core/ApolloClient.js +239 -7
  83. package/core/ApolloClient.js.map +1 -1
  84. package/core/LocalState.d.ts +4 -6
  85. package/core/LocalState.js +56 -18
  86. package/core/LocalState.js.map +1 -1
  87. package/core/ObservableQuery.d.ts +27 -0
  88. package/core/ObservableQuery.js +246 -31
  89. package/core/ObservableQuery.js.map +1 -1
  90. package/core/QueryInfo.d.ts +4 -3
  91. package/core/QueryInfo.js +122 -13
  92. package/core/QueryInfo.js.map +1 -1
  93. package/core/QueryManager.d.ts +9 -2
  94. package/core/QueryManager.js +259 -53
  95. package/core/QueryManager.js.map +1 -1
  96. package/core/core.cjs +222 -122
  97. package/core/core.cjs.map +1 -1
  98. package/core/core.cjs.native.js +222 -122
  99. package/core/equalByQuery.js +20 -1
  100. package/core/equalByQuery.js.map +1 -1
  101. package/core/index.d.ts +1 -1
  102. package/core/index.js +19 -0
  103. package/core/index.js.map +1 -1
  104. package/core/networkStatus.d.ts +39 -0
  105. package/core/networkStatus.js +39 -0
  106. package/core/networkStatus.js.map +1 -1
  107. package/core/types.d.ts +9 -0
  108. package/core/types.js.map +1 -1
  109. package/core/watchQueryOptions.d.ts +245 -2
  110. package/core/watchQueryOptions.js.map +1 -1
  111. package/dev/dev.cjs +10 -119
  112. package/dev/dev.cjs.map +1 -1
  113. package/dev/dev.cjs.native.js +10 -119
  114. package/dev/loadErrorMessageHandler.js.map +1 -1
  115. package/errors/errors.cjs +1 -1
  116. package/errors/errors.cjs.map +1 -1
  117. package/errors/errors.cjs.native.js +1 -1
  118. package/errors/index.js +14 -1
  119. package/errors/index.js.map +1 -1
  120. package/invariantErrorCodes.js +6 -8
  121. package/link/batch/batch.cjs +2 -2
  122. package/link/batch/batch.cjs.map +1 -1
  123. package/link/batch/batch.cjs.native.js +2 -2
  124. package/link/batch/batchLink.d.ts +21 -0
  125. package/link/batch/batchLink.js +2 -1
  126. package/link/batch/batchLink.js.map +1 -1
  127. package/link/batch/batching.js +24 -1
  128. package/link/batch/batching.js.map +1 -1
  129. package/link/batch-http/batch-http.cjs +3 -2
  130. package/link/batch-http/batch-http.cjs.map +1 -1
  131. package/link/batch-http/batch-http.cjs.native.js +3 -2
  132. package/link/batch-http/batchHttpLink.d.ts +4 -0
  133. package/link/batch-http/batchHttpLink.js +53 -2
  134. package/link/batch-http/batchHttpLink.js.map +1 -1
  135. package/link/context/context.cjs.map +1 -1
  136. package/link/context/index.js +1 -0
  137. package/link/context/index.js.map +1 -1
  138. package/link/core/ApolloLink.d.ts +15 -0
  139. package/link/core/ApolloLink.js +20 -9
  140. package/link/core/ApolloLink.js.map +1 -1
  141. package/link/core/core.cjs +13 -9
  142. package/link/core/core.cjs.map +1 -1
  143. package/link/core/core.cjs.native.js +13 -9
  144. package/link/error/error.cjs +1 -1
  145. package/link/error/error.cjs.map +1 -1
  146. package/link/error/error.cjs.native.js +1 -1
  147. package/link/error/index.d.ts +3 -0
  148. package/link/error/index.js +4 -1
  149. package/link/error/index.js.map +1 -1
  150. package/link/http/HttpLink.d.ts +0 -2
  151. package/link/http/HttpLink.js +1 -1
  152. package/link/http/HttpLink.js.map +1 -1
  153. package/link/http/checkFetcher.js.map +1 -1
  154. package/link/http/createHttpLink.js +23 -1
  155. package/link/http/createHttpLink.js.map +1 -1
  156. package/link/http/createSignalIfSupported.d.ts +5 -0
  157. package/link/http/createSignalIfSupported.js +5 -0
  158. package/link/http/createSignalIfSupported.js.map +1 -1
  159. package/link/http/http.cjs +14 -12
  160. package/link/http/http.cjs.map +1 -1
  161. package/link/http/http.cjs.native.js +14 -12
  162. package/link/http/index.js +2 -1
  163. package/link/http/index.js.map +1 -1
  164. package/link/http/iterators/async.d.ts +4 -0
  165. package/link/http/iterators/async.js +4 -0
  166. package/link/http/iterators/async.js.map +1 -1
  167. package/link/http/iterators/nodeStream.d.ts +4 -0
  168. package/link/http/iterators/nodeStream.js +4 -0
  169. package/link/http/iterators/nodeStream.js.map +1 -1
  170. package/link/http/iterators/promise.d.ts +4 -0
  171. package/link/http/iterators/promise.js +4 -0
  172. package/link/http/iterators/promise.js.map +1 -1
  173. package/link/http/iterators/reader.d.ts +4 -0
  174. package/link/http/iterators/reader.js +4 -0
  175. package/link/http/iterators/reader.js.map +1 -1
  176. package/link/http/parseAndCheckHttpResponse.js +51 -10
  177. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  178. package/link/http/responseIterator.d.ts +4 -0
  179. package/link/http/responseIterator.js +6 -0
  180. package/link/http/responseIterator.js.map +1 -1
  181. package/link/http/rewriteURIForGET.d.ts +1 -1
  182. package/link/http/rewriteURIForGET.js +10 -0
  183. package/link/http/rewriteURIForGET.js.map +1 -1
  184. package/link/http/selectHttpOptionsAndBody.d.ts +45 -0
  185. package/link/http/selectHttpOptionsAndBody.js +23 -0
  186. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  187. package/link/http/selectURI.js.map +1 -1
  188. package/link/http/serializeFetchParameter.js.map +1 -1
  189. package/link/persisted-queries/index.d.ts +11 -1
  190. package/link/persisted-queries/index.js +62 -7
  191. package/link/persisted-queries/index.js.map +1 -1
  192. package/link/persisted-queries/persisted-queries.cjs +30 -7
  193. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  194. package/link/persisted-queries/persisted-queries.cjs.native.js +30 -7
  195. package/link/remove-typename/remove-typename.cjs +30 -11
  196. package/link/remove-typename/remove-typename.cjs.map +1 -1
  197. package/link/remove-typename/remove-typename.cjs.native.js +30 -11
  198. package/link/remove-typename/removeTypenameFromVariables.d.ts +9 -1
  199. package/link/remove-typename/removeTypenameFromVariables.js +31 -12
  200. package/link/remove-typename/removeTypenameFromVariables.js.map +1 -1
  201. package/link/retry/delayFunction.d.ts +29 -0
  202. package/link/retry/delayFunction.js +6 -0
  203. package/link/retry/delayFunction.js.map +1 -1
  204. package/link/retry/retry.cjs +5 -5
  205. package/link/retry/retry.cjs.map +1 -1
  206. package/link/retry/retry.cjs.native.js +5 -5
  207. package/link/retry/retryFunction.d.ts +20 -0
  208. package/link/retry/retryLink.d.ts +6 -0
  209. package/link/retry/retryLink.js +31 -6
  210. package/link/retry/retryLink.js.map +1 -1
  211. package/link/schema/index.d.ts +13 -0
  212. package/link/schema/index.js +3 -3
  213. package/link/schema/index.js.map +1 -1
  214. package/link/schema/schema.cjs +3 -3
  215. package/link/schema/schema.cjs.map +1 -1
  216. package/link/schema/schema.cjs.native.js +3 -3
  217. package/link/subscriptions/index.js +35 -2
  218. package/link/subscriptions/index.js.map +1 -1
  219. package/link/subscriptions/subscriptions.cjs +3 -2
  220. package/link/subscriptions/subscriptions.cjs.map +1 -1
  221. package/link/subscriptions/subscriptions.cjs.native.js +3 -2
  222. package/link/utils/createOperation.js.map +1 -1
  223. package/link/utils/filterOperationVariables.js +4 -0
  224. package/link/utils/filterOperationVariables.js.map +1 -1
  225. package/link/utils/toPromise.js.map +1 -1
  226. package/link/utils/transformOperation.js +3 -2
  227. package/link/utils/transformOperation.js.map +1 -1
  228. package/link/utils/utils.cjs +2 -2
  229. package/link/utils/utils.cjs.map +1 -1
  230. package/link/utils/utils.cjs.native.js +2 -2
  231. package/link/utils/validateOperation.js.map +1 -1
  232. package/link/ws/index.d.ts +12 -0
  233. package/link/ws/index.js +1 -1
  234. package/link/ws/index.js.map +1 -1
  235. package/link/ws/ws.cjs +1 -1
  236. package/link/ws/ws.cjs.map +1 -1
  237. package/link/ws/ws.cjs.native.js +1 -1
  238. package/package.json +53 -41
  239. package/react/cache/QueryReference.d.ts +27 -13
  240. package/react/cache/QueryReference.js +122 -42
  241. package/react/cache/QueryReference.js.map +1 -1
  242. package/react/cache/SuspenseCache.d.ts +10 -0
  243. package/react/cache/SuspenseCache.js +1 -2
  244. package/react/cache/SuspenseCache.js.map +1 -1
  245. package/react/cache/getSuspenseCache.js.map +1 -1
  246. package/react/cache/types.d.ts +3 -0
  247. package/react/cache/types.js.map +1 -1
  248. package/react/context/ApolloContext.d.ts +5 -0
  249. package/react/context/ApolloContext.js +10 -3
  250. package/react/context/ApolloContext.js.map +1 -1
  251. package/react/context/context.cjs +1 -3
  252. package/react/context/context.cjs.map +1 -1
  253. package/react/context/context.cjs.native.js +1 -3
  254. package/react/hoc/graphql.js.map +1 -1
  255. package/react/hoc/hoc-utils.js +3 -1
  256. package/react/hoc/hoc-utils.js.map +1 -1
  257. package/react/hoc/hoc.cjs +9 -17
  258. package/react/hoc/hoc.cjs.map +1 -1
  259. package/react/hoc/hoc.cjs.native.js +9 -17
  260. package/react/hoc/mutation-hoc.js +9 -4
  261. package/react/hoc/mutation-hoc.js.map +1 -1
  262. package/react/hoc/query-hoc.js +10 -4
  263. package/react/hoc/query-hoc.js.map +1 -1
  264. package/react/hoc/subscription-hoc.js +10 -4
  265. package/react/hoc/subscription-hoc.js.map +1 -1
  266. package/react/hoc/withApollo.js +3 -4
  267. package/react/hoc/withApollo.js.map +1 -1
  268. package/react/hooks/hooks.cjs +230 -98
  269. package/react/hooks/hooks.cjs.map +1 -1
  270. package/react/hooks/hooks.cjs.native.js +230 -98
  271. package/react/hooks/index.d.ts +4 -0
  272. package/react/hooks/index.js +2 -0
  273. package/react/hooks/index.js.map +1 -1
  274. package/react/hooks/internal/__use.js +5 -0
  275. package/react/hooks/internal/__use.js.map +1 -1
  276. package/react/hooks/internal/index.d.ts +1 -0
  277. package/react/hooks/internal/index.js +2 -0
  278. package/react/hooks/internal/index.js.map +1 -1
  279. package/react/hooks/internal/useDeepMemo.js.map +1 -1
  280. package/react/hooks/internal/useIsomorphicLayoutEffect.js +6 -3
  281. package/react/hooks/internal/useIsomorphicLayoutEffect.js.map +1 -1
  282. package/react/hooks/internal/useRenderGuard.d.ts +2 -0
  283. package/react/hooks/internal/useRenderGuard.js +17 -0
  284. package/react/hooks/internal/useRenderGuard.js.map +1 -0
  285. package/react/hooks/useBackgroundQuery.d.ts +12 -9
  286. package/react/hooks/useBackgroundQuery.js +14 -11
  287. package/react/hooks/useBackgroundQuery.js.map +1 -1
  288. package/react/hooks/useFragment.js +4 -3
  289. package/react/hooks/useFragment.js.map +1 -1
  290. package/react/hooks/useLazyQuery.js +13 -4
  291. package/react/hooks/useLazyQuery.js.map +1 -1
  292. package/react/hooks/useLoadableQuery.d.ts +30 -0
  293. package/react/hooks/useLoadableQuery.js +61 -0
  294. package/react/hooks/useLoadableQuery.js.map +1 -0
  295. package/react/hooks/useMutation.js +8 -3
  296. package/react/hooks/useMutation.js.map +1 -1
  297. package/react/hooks/useQuery.d.ts +11 -0
  298. package/react/hooks/useQuery.js +138 -6
  299. package/react/hooks/useQuery.js.map +1 -1
  300. package/react/hooks/useQueryRefHandlers.d.ts +35 -0
  301. package/react/hooks/useQueryRefHandlers.js +48 -0
  302. package/react/hooks/useQueryRefHandlers.js.map +1 -0
  303. package/react/hooks/useReactiveVar.js +5 -0
  304. package/react/hooks/useReactiveVar.js.map +1 -1
  305. package/react/hooks/useReadQuery.d.ts +19 -0
  306. package/react/hooks/useReadQuery.js +9 -9
  307. package/react/hooks/useReadQuery.js.map +1 -1
  308. package/react/hooks/useSubscription.js +5 -0
  309. package/react/hooks/useSubscription.js.map +1 -1
  310. package/react/hooks/useSuspenseQuery.js +22 -22
  311. package/react/hooks/useSuspenseQuery.js.map +1 -1
  312. package/react/hooks/useSyncExternalStore.js +53 -1
  313. package/react/hooks/useSyncExternalStore.js.map +1 -1
  314. package/react/index.d.ts +2 -0
  315. package/react/index.js +1 -0
  316. package/react/index.js.map +1 -1
  317. package/react/parser/index.d.ts +3 -0
  318. package/react/parser/index.js +16 -6
  319. package/react/parser/index.js.map +1 -1
  320. package/react/parser/parser.cjs +19 -5
  321. package/react/parser/parser.cjs.map +1 -1
  322. package/react/parser/parser.cjs.native.js +19 -5
  323. package/react/query-preloader/createQueryPreloader.d.ts +253 -0
  324. package/react/query-preloader/createQueryPreloader.js +29 -0
  325. package/react/query-preloader/createQueryPreloader.js.map +1 -0
  326. package/react/react.cjs +248 -1
  327. package/react/react.cjs.map +1 -1
  328. package/react/react.cjs.native.js +248 -1
  329. package/react/ssr/RenderPromises.js +21 -1
  330. package/react/ssr/RenderPromises.js.map +1 -1
  331. package/react/ssr/getDataFromTree.js +18 -3
  332. package/react/ssr/getDataFromTree.js.map +1 -1
  333. package/react/ssr/ssr.cjs +6 -4
  334. package/react/ssr/ssr.cjs.map +1 -1
  335. package/react/ssr/ssr.cjs.native.js +6 -4
  336. package/react/types/types.d.ts +129 -1
  337. package/react/types/types.js.map +1 -1
  338. package/testing/core/core.cjs +14 -11
  339. package/testing/core/core.cjs.map +1 -1
  340. package/testing/core/core.cjs.native.js +14 -11
  341. package/testing/core/itAsync.d.ts +1 -1
  342. package/testing/core/itAsync.js.map +1 -1
  343. package/testing/core/mocking/mockFetch.d.ts +2 -2
  344. package/testing/core/mocking/mockFetch.js +8 -4
  345. package/testing/core/mocking/mockFetch.js.map +1 -1
  346. package/testing/core/mocking/mockLink.d.ts +1 -1
  347. package/testing/core/mocking/mockLink.js +17 -7
  348. package/testing/core/mocking/mockLink.js.map +1 -1
  349. package/testing/core/mocking/mockQueryManager.js +2 -0
  350. package/testing/core/mocking/mockQueryManager.js.map +1 -1
  351. package/testing/core/mocking/mockSubscriptionLink.d.ts +1 -1
  352. package/testing/core/mocking/mockSubscriptionLink.js +1 -1
  353. package/testing/core/mocking/mockSubscriptionLink.js.map +1 -1
  354. package/testing/core/mocking/mockWatchQuery.js +1 -1
  355. package/testing/core/mocking/mockWatchQuery.js.map +1 -1
  356. package/testing/core/observableToPromise.d.ts +17 -3
  357. package/testing/core/observableToPromise.js +5 -0
  358. package/testing/core/observableToPromise.js.map +1 -1
  359. package/testing/core/subscribeAndCount.js +3 -0
  360. package/testing/core/subscribeAndCount.js.map +1 -1
  361. package/testing/core/wait.js +2 -2
  362. package/testing/core/wait.js.map +1 -1
  363. package/testing/core/withConsoleSpy.d.ts +3 -0
  364. package/testing/core/withConsoleSpy.js +7 -1
  365. package/testing/core/withConsoleSpy.js.map +1 -1
  366. package/testing/core/wrap.js +2 -0
  367. package/testing/core/wrap.js.map +1 -1
  368. package/testing/internal/ObservableStream.js +14 -14
  369. package/testing/internal/ObservableStream.js.map +1 -1
  370. package/testing/internal/disposables/disableActWarnings.d.ts +10 -0
  371. package/testing/internal/disposables/disableActWarnings.js +15 -0
  372. package/testing/internal/disposables/disableActWarnings.js.map +1 -0
  373. package/testing/internal/disposables/index.d.ts +1 -0
  374. package/testing/internal/disposables/index.js +1 -0
  375. package/testing/internal/disposables/index.js.map +1 -1
  376. package/testing/internal/disposables/spyOnConsole.d.ts +1 -0
  377. package/testing/internal/disposables/spyOnConsole.js +2 -0
  378. package/testing/internal/disposables/spyOnConsole.js.map +1 -1
  379. package/testing/internal/disposables/withCleanup.d.ts +1 -0
  380. package/testing/internal/disposables/withCleanup.js +3 -0
  381. package/testing/internal/disposables/withCleanup.js.map +1 -1
  382. package/testing/internal/index.d.ts +4 -0
  383. package/testing/internal/index.js +2 -0
  384. package/testing/internal/index.js.map +1 -1
  385. package/testing/internal/profile/Render.d.ts +32 -1
  386. package/testing/internal/profile/Render.js +14 -2
  387. package/testing/internal/profile/Render.js.map +1 -1
  388. package/testing/internal/profile/context.d.ts +10 -0
  389. package/testing/internal/profile/context.js +14 -0
  390. package/testing/internal/profile/context.js.map +1 -0
  391. package/testing/internal/profile/index.d.ts +2 -2
  392. package/testing/internal/profile/index.js +1 -1
  393. package/testing/internal/profile/index.js.map +1 -1
  394. package/testing/internal/profile/profile.d.ts +67 -13
  395. package/testing/internal/profile/profile.js +153 -79
  396. package/testing/internal/profile/profile.js.map +1 -1
  397. package/testing/internal/profile/traces.d.ts +4 -0
  398. package/testing/internal/profile/traces.js +9 -5
  399. package/testing/internal/profile/traces.js.map +1 -1
  400. package/testing/internal/renderHelpers.d.ts +12 -0
  401. package/testing/internal/renderHelpers.js +22 -0
  402. package/testing/internal/renderHelpers.js.map +1 -0
  403. package/testing/internal/scenarios/index.d.ts +41 -0
  404. package/testing/internal/scenarios/index.js +46 -0
  405. package/testing/internal/scenarios/index.js.map +1 -0
  406. package/testing/matchers/ProfiledComponent.js +29 -26
  407. package/testing/matchers/ProfiledComponent.js.map +1 -1
  408. package/testing/matchers/index.js +4 -0
  409. package/testing/matchers/index.js.map +1 -1
  410. package/testing/matchers/toBeDisposed.d.ts +3 -0
  411. package/testing/matchers/toBeDisposed.js +26 -0
  412. package/testing/matchers/toBeDisposed.js.map +1 -0
  413. package/testing/matchers/toBeGarbageCollected.d.ts +8 -0
  414. package/testing/matchers/toBeGarbageCollected.js +48 -0
  415. package/testing/matchers/toBeGarbageCollected.js.map +1 -0
  416. package/testing/matchers/toHaveSuspenseCacheEntryUsing.js.map +1 -1
  417. package/testing/matchers/toMatchDocument.js.map +1 -1
  418. package/testing/react/MockedProvider.d.ts +5 -1
  419. package/testing/react/MockedProvider.js +6 -2
  420. package/testing/react/MockedProvider.js.map +1 -1
  421. package/testing/testing.cjs +4 -2
  422. package/testing/testing.cjs.map +1 -1
  423. package/testing/testing.cjs.native.js +4 -2
  424. package/utilities/caching/caches.d.ts +34 -0
  425. package/utilities/caching/caches.js +64 -0
  426. package/utilities/caching/caches.js.map +1 -0
  427. package/utilities/caching/getMemoryInternals.d.ts +76 -0
  428. package/utilities/caching/getMemoryInternals.js +112 -0
  429. package/utilities/caching/getMemoryInternals.js.map +1 -0
  430. package/utilities/caching/index.d.ts +4 -0
  431. package/utilities/caching/index.js +3 -0
  432. package/utilities/caching/index.js.map +1 -0
  433. package/utilities/caching/sizes.d.ts +261 -0
  434. package/utilities/caching/sizes.js +27 -0
  435. package/utilities/caching/sizes.js.map +1 -0
  436. package/utilities/common/arrays.js +1 -0
  437. package/utilities/common/arrays.js.map +1 -1
  438. package/utilities/common/canUse.js +17 -2
  439. package/utilities/common/canUse.js.map +1 -1
  440. package/utilities/common/canonicalStringify.d.ts +17 -0
  441. package/utilities/common/canonicalStringify.js +49 -2
  442. package/utilities/common/canonicalStringify.js.map +1 -1
  443. package/utilities/common/cloneDeep.d.ts +3 -0
  444. package/utilities/common/cloneDeep.js +5 -0
  445. package/utilities/common/cloneDeep.js.map +1 -1
  446. package/utilities/common/compact.d.ts +4 -0
  447. package/utilities/common/compact.js +4 -0
  448. package/utilities/common/compact.js.map +1 -1
  449. package/utilities/common/errorHandling.js +1 -3
  450. package/utilities/common/errorHandling.js.map +1 -1
  451. package/utilities/common/incrementalResult.js +3 -0
  452. package/utilities/common/incrementalResult.js.map +1 -1
  453. package/utilities/common/makeUniqueId.js +2 -0
  454. package/utilities/common/makeUniqueId.js.map +1 -1
  455. package/utilities/common/maybeDeepFreeze.js +3 -0
  456. package/utilities/common/maybeDeepFreeze.js.map +1 -1
  457. package/utilities/common/mergeDeep.js +12 -1
  458. package/utilities/common/mergeDeep.js.map +1 -1
  459. package/utilities/common/mergeOptions.d.ts +1 -1
  460. package/utilities/common/mergeOptions.js.map +1 -1
  461. package/utilities/common/omitDeep.js.map +1 -1
  462. package/utilities/globals/global.js +7 -1
  463. package/utilities/globals/global.js.map +1 -1
  464. package/utilities/globals/globals.cjs +4 -5
  465. package/utilities/globals/globals.cjs.map +1 -1
  466. package/utilities/globals/globals.cjs.native.js +4 -5
  467. package/utilities/globals/index.d.ts +4 -0
  468. package/utilities/globals/index.js +7 -0
  469. package/utilities/globals/index.js.map +1 -1
  470. package/utilities/globals/invariantWrappers.d.ts +40 -0
  471. package/utilities/globals/invariantWrappers.js +11 -3
  472. package/utilities/globals/invariantWrappers.js.map +1 -1
  473. package/utilities/globals/maybe.js.map +1 -1
  474. package/utilities/graphql/DocumentTransform.d.ts +20 -6
  475. package/utilities/graphql/DocumentTransform.js +54 -29
  476. package/utilities/graphql/DocumentTransform.js.map +1 -1
  477. package/utilities/graphql/directives.js +3 -0
  478. package/utilities/graphql/directives.js.map +1 -1
  479. package/utilities/graphql/fragments.d.ts +25 -0
  480. package/utilities/graphql/fragments.js +36 -0
  481. package/utilities/graphql/fragments.js.map +1 -1
  482. package/utilities/graphql/getFromAST.d.ts +5 -0
  483. package/utilities/graphql/getFromAST.js +9 -0
  484. package/utilities/graphql/getFromAST.js.map +1 -1
  485. package/utilities/graphql/print.js +8 -5
  486. package/utilities/graphql/print.js.map +1 -1
  487. package/utilities/graphql/storeUtils.d.ts +14 -0
  488. package/utilities/graphql/storeUtils.js +8 -2
  489. package/utilities/graphql/storeUtils.js.map +1 -1
  490. package/utilities/graphql/transform.js +106 -7
  491. package/utilities/graphql/transform.js.map +1 -1
  492. package/utilities/index.d.ts +4 -0
  493. package/utilities/index.js +1 -0
  494. package/utilities/index.js.map +1 -1
  495. package/utilities/observables/Concast.d.ts +1 -1
  496. package/utilities/observables/Concast.js +85 -2
  497. package/utilities/observables/Concast.js.map +1 -1
  498. package/utilities/observables/Observable.js +6 -0
  499. package/utilities/observables/Observable.js.map +1 -1
  500. package/utilities/observables/asyncMap.js +12 -3
  501. package/utilities/observables/asyncMap.js.map +1 -1
  502. package/utilities/observables/iteration.js +3 -0
  503. package/utilities/observables/iteration.js.map +1 -1
  504. package/utilities/observables/subclassing.js +14 -0
  505. package/utilities/observables/subclassing.js.map +1 -1
  506. package/utilities/policies/pagination.js +47 -3
  507. package/utilities/policies/pagination.js.map +1 -1
  508. package/utilities/promises/decoration.js +1 -0
  509. package/utilities/promises/decoration.js.map +1 -1
  510. package/utilities/subscriptions/relay/index.js.map +1 -1
  511. package/utilities/subscriptions/relay/relay.cjs +9 -8
  512. package/utilities/subscriptions/relay/relay.cjs.map +1 -1
  513. package/utilities/subscriptions/relay/relay.cjs.native.js +9 -8
  514. package/utilities/subscriptions/urql/index.js.map +1 -1
  515. package/utilities/subscriptions/urql/urql.cjs +9 -8
  516. package/utilities/subscriptions/urql/urql.cjs.map +1 -1
  517. package/utilities/subscriptions/urql/urql.cjs.native.js +9 -8
  518. package/utilities/types/DeepOmit.js.map +1 -1
  519. package/utilities/types/DeepPartial.d.ts +1 -1
  520. package/utilities/types/DeepPartial.js +4 -0
  521. package/utilities/types/DeepPartial.js.map +1 -1
  522. package/utilities/types/IsStrictlyAny.js.map +1 -1
  523. package/utilities/types/OnlyRequiredProperties.d.ts +7 -0
  524. package/utilities/types/OnlyRequiredProperties.js +2 -0
  525. package/utilities/types/OnlyRequiredProperties.js.map +1 -0
  526. package/utilities/types/TODO.d.ts +3 -0
  527. package/utilities/types/TODO.js +2 -0
  528. package/utilities/types/TODO.js.map +1 -0
  529. package/utilities/utilities.cjs +114 -58
  530. package/utilities/utilities.cjs.map +1 -1
  531. package/utilities/utilities.cjs.native.js +114 -58
  532. package/version.js +1 -1
  533. package/cache/core/cache.d.ts.map +0 -1
  534. package/cache/core/types/Cache.d.ts.map +0 -1
  535. package/cache/core/types/DataProxy.d.ts.map +0 -1
  536. package/cache/core/types/common.d.ts.map +0 -1
  537. package/cache/index.d.ts.map +0 -1
  538. package/cache/inmemory/entityStore.d.ts.map +0 -1
  539. package/cache/inmemory/fixPolyfills.d.ts.map +0 -1
  540. package/cache/inmemory/fixPolyfills.native.d.ts.map +0 -1
  541. package/cache/inmemory/fragmentRegistry.d.ts.map +0 -1
  542. package/cache/inmemory/helpers.d.ts.map +0 -1
  543. package/cache/inmemory/inMemoryCache.d.ts.map +0 -1
  544. package/cache/inmemory/key-extractor.d.ts.map +0 -1
  545. package/cache/inmemory/object-canon.d.ts.map +0 -1
  546. package/cache/inmemory/policies.d.ts.map +0 -1
  547. package/cache/inmemory/reactiveVars.d.ts.map +0 -1
  548. package/cache/inmemory/readFromStore.d.ts.map +0 -1
  549. package/cache/inmemory/types.d.ts.map +0 -1
  550. package/cache/inmemory/writeToStore.d.ts.map +0 -1
  551. package/config/jest/setup.d.ts.map +0 -1
  552. package/core/ApolloClient.d.ts.map +0 -1
  553. package/core/LocalState.d.ts.map +0 -1
  554. package/core/ObservableQuery.d.ts.map +0 -1
  555. package/core/QueryInfo.d.ts.map +0 -1
  556. package/core/QueryManager.d.ts.map +0 -1
  557. package/core/equalByQuery.d.ts.map +0 -1
  558. package/core/index.d.ts.map +0 -1
  559. package/core/networkStatus.d.ts.map +0 -1
  560. package/core/types.d.ts.map +0 -1
  561. package/core/watchQueryOptions.d.ts.map +0 -1
  562. package/dev/index.d.ts.map +0 -1
  563. package/dev/loadDevMessages.d.ts.map +0 -1
  564. package/dev/loadErrorMessageHandler.d.ts.map +0 -1
  565. package/dev/loadErrorMessages.d.ts.map +0 -1
  566. package/errors/index.d.ts.map +0 -1
  567. package/index.d.ts.map +0 -1
  568. package/invariantErrorCodes.d.ts.map +0 -1
  569. package/link/batch/batchLink.d.ts.map +0 -1
  570. package/link/batch/batching.d.ts.map +0 -1
  571. package/link/batch/index.d.ts.map +0 -1
  572. package/link/batch-http/batchHttpLink.d.ts.map +0 -1
  573. package/link/batch-http/index.d.ts.map +0 -1
  574. package/link/context/index.d.ts.map +0 -1
  575. package/link/core/ApolloLink.d.ts.map +0 -1
  576. package/link/core/concat.d.ts.map +0 -1
  577. package/link/core/empty.d.ts.map +0 -1
  578. package/link/core/execute.d.ts.map +0 -1
  579. package/link/core/from.d.ts.map +0 -1
  580. package/link/core/index.d.ts.map +0 -1
  581. package/link/core/split.d.ts.map +0 -1
  582. package/link/core/types.d.ts.map +0 -1
  583. package/link/error/index.d.ts.map +0 -1
  584. package/link/http/HttpLink.d.ts.map +0 -1
  585. package/link/http/checkFetcher.d.ts.map +0 -1
  586. package/link/http/createHttpLink.d.ts.map +0 -1
  587. package/link/http/createSignalIfSupported.d.ts.map +0 -1
  588. package/link/http/index.d.ts.map +0 -1
  589. package/link/http/iterators/async.d.ts.map +0 -1
  590. package/link/http/iterators/nodeStream.d.ts.map +0 -1
  591. package/link/http/iterators/promise.d.ts.map +0 -1
  592. package/link/http/iterators/reader.d.ts.map +0 -1
  593. package/link/http/parseAndCheckHttpResponse.d.ts.map +0 -1
  594. package/link/http/responseIterator.d.ts.map +0 -1
  595. package/link/http/rewriteURIForGET.d.ts.map +0 -1
  596. package/link/http/selectHttpOptionsAndBody.d.ts.map +0 -1
  597. package/link/http/selectURI.d.ts.map +0 -1
  598. package/link/http/serializeFetchParameter.d.ts.map +0 -1
  599. package/link/persisted-queries/index.d.ts.map +0 -1
  600. package/link/remove-typename/index.d.ts.map +0 -1
  601. package/link/remove-typename/removeTypenameFromVariables.d.ts.map +0 -1
  602. package/link/retry/delayFunction.d.ts.map +0 -1
  603. package/link/retry/index.d.ts.map +0 -1
  604. package/link/retry/retryFunction.d.ts.map +0 -1
  605. package/link/retry/retryLink.d.ts.map +0 -1
  606. package/link/schema/index.d.ts.map +0 -1
  607. package/link/subscriptions/index.d.ts.map +0 -1
  608. package/link/utils/createOperation.d.ts.map +0 -1
  609. package/link/utils/filterOperationVariables.d.ts.map +0 -1
  610. package/link/utils/fromError.d.ts.map +0 -1
  611. package/link/utils/fromPromise.d.ts.map +0 -1
  612. package/link/utils/index.d.ts.map +0 -1
  613. package/link/utils/throwServerError.d.ts.map +0 -1
  614. package/link/utils/toPromise.d.ts.map +0 -1
  615. package/link/utils/transformOperation.d.ts.map +0 -1
  616. package/link/utils/validateOperation.d.ts.map +0 -1
  617. package/link/ws/index.d.ts.map +0 -1
  618. package/react/cache/QueryReference.d.ts.map +0 -1
  619. package/react/cache/SuspenseCache.d.ts.map +0 -1
  620. package/react/cache/getSuspenseCache.d.ts.map +0 -1
  621. package/react/cache/index.d.ts.map +0 -1
  622. package/react/cache/types.d.ts.map +0 -1
  623. package/react/components/Mutation.d.ts.map +0 -1
  624. package/react/components/Query.d.ts.map +0 -1
  625. package/react/components/Subscription.d.ts.map +0 -1
  626. package/react/components/index.d.ts.map +0 -1
  627. package/react/components/types.d.ts.map +0 -1
  628. package/react/context/ApolloConsumer.d.ts.map +0 -1
  629. package/react/context/ApolloContext.d.ts.map +0 -1
  630. package/react/context/ApolloProvider.d.ts.map +0 -1
  631. package/react/context/index.d.ts.map +0 -1
  632. package/react/hoc/graphql.d.ts.map +0 -1
  633. package/react/hoc/hoc-utils.d.ts.map +0 -1
  634. package/react/hoc/index.d.ts.map +0 -1
  635. package/react/hoc/mutation-hoc.d.ts.map +0 -1
  636. package/react/hoc/query-hoc.d.ts.map +0 -1
  637. package/react/hoc/subscription-hoc.d.ts.map +0 -1
  638. package/react/hoc/types.d.ts.map +0 -1
  639. package/react/hoc/withApollo.d.ts.map +0 -1
  640. package/react/hooks/constants.d.ts.map +0 -1
  641. package/react/hooks/index.d.ts.map +0 -1
  642. package/react/hooks/internal/__use.d.ts.map +0 -1
  643. package/react/hooks/internal/index.d.ts.map +0 -1
  644. package/react/hooks/internal/useDeepMemo.d.ts.map +0 -1
  645. package/react/hooks/internal/useIsomorphicLayoutEffect.d.ts.map +0 -1
  646. package/react/hooks/useApolloClient.d.ts.map +0 -1
  647. package/react/hooks/useBackgroundQuery.d.ts.map +0 -1
  648. package/react/hooks/useFragment.d.ts.map +0 -1
  649. package/react/hooks/useLazyQuery.d.ts.map +0 -1
  650. package/react/hooks/useMutation.d.ts.map +0 -1
  651. package/react/hooks/useQuery.d.ts.map +0 -1
  652. package/react/hooks/useReactiveVar.d.ts.map +0 -1
  653. package/react/hooks/useReadQuery.d.ts.map +0 -1
  654. package/react/hooks/useSubscription.d.ts.map +0 -1
  655. package/react/hooks/useSuspenseQuery.d.ts.map +0 -1
  656. package/react/hooks/useSyncExternalStore.d.ts.map +0 -1
  657. package/react/index.d.ts.map +0 -1
  658. package/react/parser/index.d.ts.map +0 -1
  659. package/react/ssr/RenderPromises.d.ts.map +0 -1
  660. package/react/ssr/getDataFromTree.d.ts.map +0 -1
  661. package/react/ssr/index.d.ts.map +0 -1
  662. package/react/ssr/renderToStringWithData.d.ts.map +0 -1
  663. package/react/types/types.d.ts.map +0 -1
  664. package/testing/core/index.d.ts.map +0 -1
  665. package/testing/core/itAsync.d.ts.map +0 -1
  666. package/testing/core/mocking/mockClient.d.ts.map +0 -1
  667. package/testing/core/mocking/mockFetch.d.ts.map +0 -1
  668. package/testing/core/mocking/mockLink.d.ts.map +0 -1
  669. package/testing/core/mocking/mockQueryManager.d.ts.map +0 -1
  670. package/testing/core/mocking/mockSubscriptionLink.d.ts.map +0 -1
  671. package/testing/core/mocking/mockWatchQuery.d.ts.map +0 -1
  672. package/testing/core/observableToPromise.d.ts.map +0 -1
  673. package/testing/core/subscribeAndCount.d.ts.map +0 -1
  674. package/testing/core/wait.d.ts.map +0 -1
  675. package/testing/core/withConsoleSpy.d.ts.map +0 -1
  676. package/testing/core/wrap.d.ts.map +0 -1
  677. package/testing/index.d.ts.map +0 -1
  678. package/testing/internal/ObservableStream.d.ts.map +0 -1
  679. package/testing/internal/disposables/index.d.ts.map +0 -1
  680. package/testing/internal/disposables/spyOnConsole.d.ts.map +0 -1
  681. package/testing/internal/disposables/withCleanup.d.ts.map +0 -1
  682. package/testing/internal/index.d.ts.map +0 -1
  683. package/testing/internal/profile/Render.d.ts.map +0 -1
  684. package/testing/internal/profile/index.d.ts.map +0 -1
  685. package/testing/internal/profile/profile.d.ts.map +0 -1
  686. package/testing/internal/profile/traces.d.ts.map +0 -1
  687. package/testing/matchers/ProfiledComponent.d.ts.map +0 -1
  688. package/testing/matchers/index.d.ts.map +0 -1
  689. package/testing/matchers/toHaveSuspenseCacheEntryUsing.d.ts.map +0 -1
  690. package/testing/matchers/toMatchDocument.d.ts.map +0 -1
  691. package/testing/react/MockedProvider.d.ts.map +0 -1
  692. package/utilities/common/arrays.d.ts.map +0 -1
  693. package/utilities/common/canUse.d.ts.map +0 -1
  694. package/utilities/common/canonicalStringify.d.ts.map +0 -1
  695. package/utilities/common/cloneDeep.d.ts.map +0 -1
  696. package/utilities/common/compact.d.ts.map +0 -1
  697. package/utilities/common/errorHandling.d.ts.map +0 -1
  698. package/utilities/common/filterInPlace.d.ts +0 -2
  699. package/utilities/common/filterInPlace.d.ts.map +0 -1
  700. package/utilities/common/filterInPlace.js +0 -11
  701. package/utilities/common/filterInPlace.js.map +0 -1
  702. package/utilities/common/incrementalResult.d.ts.map +0 -1
  703. package/utilities/common/makeUniqueId.d.ts.map +0 -1
  704. package/utilities/common/maybeDeepFreeze.d.ts.map +0 -1
  705. package/utilities/common/mergeDeep.d.ts.map +0 -1
  706. package/utilities/common/mergeOptions.d.ts.map +0 -1
  707. package/utilities/common/objects.d.ts.map +0 -1
  708. package/utilities/common/omitDeep.d.ts.map +0 -1
  709. package/utilities/common/stringifyForDisplay.d.ts.map +0 -1
  710. package/utilities/common/stripTypename.d.ts.map +0 -1
  711. package/utilities/globals/global.d.ts.map +0 -1
  712. package/utilities/globals/index.d.ts.map +0 -1
  713. package/utilities/globals/invariantWrappers.d.ts.map +0 -1
  714. package/utilities/globals/maybe.d.ts.map +0 -1
  715. package/utilities/graphql/DocumentTransform.d.ts.map +0 -1
  716. package/utilities/graphql/directives.d.ts.map +0 -1
  717. package/utilities/graphql/fragments.d.ts.map +0 -1
  718. package/utilities/graphql/getFromAST.d.ts.map +0 -1
  719. package/utilities/graphql/operations.d.ts.map +0 -1
  720. package/utilities/graphql/print.d.ts.map +0 -1
  721. package/utilities/graphql/storeUtils.d.ts.map +0 -1
  722. package/utilities/graphql/transform.d.ts.map +0 -1
  723. package/utilities/index.d.ts.map +0 -1
  724. package/utilities/observables/Concast.d.ts.map +0 -1
  725. package/utilities/observables/Observable.d.ts.map +0 -1
  726. package/utilities/observables/asyncMap.d.ts.map +0 -1
  727. package/utilities/observables/iteration.d.ts.map +0 -1
  728. package/utilities/observables/subclassing.d.ts.map +0 -1
  729. package/utilities/policies/pagination.d.ts.map +0 -1
  730. package/utilities/promises/decoration.d.ts.map +0 -1
  731. package/utilities/subscriptions/relay/index.d.ts.map +0 -1
  732. package/utilities/subscriptions/shared.d.ts.map +0 -1
  733. package/utilities/subscriptions/urql/index.d.ts.map +0 -1
  734. package/utilities/types/DeepOmit.d.ts.map +0 -1
  735. package/utilities/types/DeepPartial.d.ts.map +0 -1
  736. package/utilities/types/IsStrictlyAny.d.ts.map +0 -1
  737. package/utilities/types/Primitive.d.ts.map +0 -1
  738. package/version.d.ts.map +0 -1
@@ -1,6 +1,9 @@
1
1
  import * as React from "rehackt";
2
2
  import { canUseDOM } from "../../../utilities/index.js";
3
- export var useIsomorphicLayoutEffect = canUseDOM
4
- ? React.useLayoutEffect
5
- : React.useEffect;
3
+ // use canUseDOM here instead of canUseLayoutEffect because we want to be able
4
+ // to use useLayoutEffect in our jest tests. useLayoutEffect seems to work fine
5
+ // in useSuspenseQuery tests, but to honor the original comment about the
6
+ // warnings for useSyncExternalStore implementation, canUseLayoutEffect is left
7
+ // alone.
8
+ export var useIsomorphicLayoutEffect = canUseDOM ? React.useLayoutEffect : React.useEffect;
6
9
  //# sourceMappingURL=useIsomorphicLayoutEffect.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useIsomorphicLayoutEffect.js","sourceRoot":"","sources":["../../../../src/react/hooks/internal/useIsomorphicLayoutEffect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAOxD,MAAM,CAAC,IAAM,yBAAyB,GAAG,SAAS;IAChD,CAAC,CAAC,KAAK,CAAC,eAAe;IACvB,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC","sourcesContent":["import * as React from \"rehackt\";\nimport { canUseDOM } from \"../../../utilities/index.js\";\n\n// use canUseDOM here instead of canUseLayoutEffect because we want to be able\n// to use useLayoutEffect in our jest tests. useLayoutEffect seems to work fine\n// in useSuspenseQuery tests, but to honor the original comment about the\n// warnings for useSyncExternalStore implementation, canUseLayoutEffect is left\n// alone.\nexport const useIsomorphicLayoutEffect = canUseDOM\n ? React.useLayoutEffect\n : React.useEffect;\n"]}
1
+ {"version":3,"file":"useIsomorphicLayoutEffect.js","sourceRoot":"","sources":["../../../../src/react/hooks/internal/useIsomorphicLayoutEffect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAExD,8EAA8E;AAC9E,+EAA+E;AAC/E,yEAAyE;AACzE,+EAA+E;AAC/E,SAAS;AACT,MAAM,CAAC,IAAM,yBAAyB,GACpC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC","sourcesContent":["import * as React from \"rehackt\";\nimport { canUseDOM } from \"../../../utilities/index.js\";\n\n// use canUseDOM here instead of canUseLayoutEffect because we want to be able\n// to use useLayoutEffect in our jest tests. useLayoutEffect seems to work fine\n// in useSuspenseQuery tests, but to honor the original comment about the\n// warnings for useSyncExternalStore implementation, canUseLayoutEffect is left\n// alone.\nexport const useIsomorphicLayoutEffect =\n canUseDOM ? React.useLayoutEffect : React.useEffect;\n"]}
@@ -0,0 +1,2 @@
1
+ export declare function useRenderGuard(): () => boolean;
2
+ //# sourceMappingURL=useRenderGuard.d.ts.map
@@ -0,0 +1,17 @@
1
+ import * as React from "rehackt";
2
+ function getRenderDispatcher() {
3
+ var _a, _b;
4
+ return (_b = (_a = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED) === null || _a === void 0 ? void 0 : _a.ReactCurrentDispatcher) === null || _b === void 0 ? void 0 : _b.current;
5
+ }
6
+ var RenderDispatcher = null;
7
+ /*
8
+ Relay does this too, so we hope this is safe.
9
+ https://github.com/facebook/relay/blob/8651fbca19adbfbb79af7a3bc40834d105fd7747/packages/react-relay/relay-hooks/loadQuery.js#L90-L98
10
+ */
11
+ export function useRenderGuard() {
12
+ RenderDispatcher = getRenderDispatcher();
13
+ return React.useCallback(function () {
14
+ return (RenderDispatcher !== null && RenderDispatcher === getRenderDispatcher());
15
+ }, []);
16
+ }
17
+ //# sourceMappingURL=useRenderGuard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRenderGuard.js","sourceRoot":"","sources":["../../../../src/react/hooks/internal/useRenderGuard.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAEjC,SAAS,mBAAmB;;IAC1B,OAAO,MAAA,MAAC,KAAa,CAAC,kDAAkD,0CACpE,sBAAsB,0CAAE,OAAO,CAAC;AACtC,CAAC;AAED,IAAI,gBAAgB,GAAY,IAAI,CAAC;AAErC;;;EAGE;AACF,MAAM,UAAU,cAAc;IAC5B,gBAAgB,GAAG,mBAAmB,EAAE,CAAC;IAEzC,OAAO,KAAK,CAAC,WAAW,CAAC;QACvB,OAAO,CACL,gBAAgB,KAAK,IAAI,IAAI,gBAAgB,KAAK,mBAAmB,EAAE,CACxE,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC","sourcesContent":["import * as React from \"rehackt\";\n\nfunction getRenderDispatcher() {\n return (React as any).__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED\n ?.ReactCurrentDispatcher?.current;\n}\n\nlet RenderDispatcher: unknown = null;\n\n/*\nRelay does this too, so we hope this is safe.\nhttps://github.com/facebook/relay/blob/8651fbca19adbfbb79af7a3bc40834d105fd7747/packages/react-relay/relay-hooks/loadQuery.js#L90-L98\n*/\nexport function useRenderGuard() {\n RenderDispatcher = getRenderDispatcher();\n\n return React.useCallback(() => {\n return (\n RenderDispatcher !== null && RenderDispatcher === getRenderDispatcher()\n );\n }, []);\n}\n"]}
@@ -10,51 +10,54 @@ export type UseBackgroundQueryResult<TData = unknown, TVariables extends Operati
10
10
  };
11
11
  type BackgroundQueryHookOptionsNoInfer<TData, TVariables extends OperationVariables> = BackgroundQueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>;
12
12
  export declare function useBackgroundQuery<TData, TVariables extends OperationVariables, TOptions extends Omit<BackgroundQueryHookOptions<TData>, "variables">>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & TOptions): [
13
- (QueryReference<TOptions["errorPolicy"] extends "ignore" | "all" ? TOptions["returnPartialData"] extends true ? DeepPartial<TData> | undefined : TData | undefined : TOptions["returnPartialData"] extends true ? DeepPartial<TData> : TData> | (TOptions["skip"] extends boolean ? undefined : never)),
13
+ (QueryReference<TOptions["errorPolicy"] extends "ignore" | "all" ? TOptions["returnPartialData"] extends true ? DeepPartial<TData> | undefined : TData | undefined : TOptions["returnPartialData"] extends true ? DeepPartial<TData> : TData, TVariables> | (TOptions["skip"] extends boolean ? undefined : never)),
14
14
  UseBackgroundQueryResult<TData, TVariables>
15
15
  ];
16
16
  export declare function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {
17
17
  returnPartialData: true;
18
18
  errorPolicy: "ignore" | "all";
19
19
  }): [
20
- QueryReference<DeepPartial<TData> | undefined>,
20
+ QueryReference<DeepPartial<TData> | undefined, TVariables>,
21
21
  UseBackgroundQueryResult<TData, TVariables>
22
22
  ];
23
23
  export declare function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {
24
24
  errorPolicy: "ignore" | "all";
25
25
  }): [
26
- QueryReference<TData | undefined>,
26
+ QueryReference<TData | undefined, TVariables>,
27
27
  UseBackgroundQueryResult<TData, TVariables>
28
28
  ];
29
29
  export declare function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {
30
30
  skip: boolean;
31
31
  returnPartialData: true;
32
32
  }): [
33
- QueryReference<DeepPartial<TData>> | undefined,
33
+ QueryReference<DeepPartial<TData>, TVariables> | undefined,
34
34
  UseBackgroundQueryResult<TData, TVariables>
35
35
  ];
36
36
  export declare function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {
37
37
  returnPartialData: true;
38
38
  }): [
39
- QueryReference<DeepPartial<TData>>,
39
+ QueryReference<DeepPartial<TData>, TVariables>,
40
40
  UseBackgroundQueryResult<TData, TVariables>
41
41
  ];
42
42
  export declare function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {
43
43
  skip: boolean;
44
44
  }): [
45
- QueryReference<TData> | undefined,
45
+ QueryReference<TData, TVariables> | undefined,
46
+ UseBackgroundQueryResult<TData, TVariables>
47
+ ];
48
+ export declare function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: BackgroundQueryHookOptionsNoInfer<TData, TVariables>): [
49
+ QueryReference<TData, TVariables>,
46
50
  UseBackgroundQueryResult<TData, TVariables>
47
51
  ];
48
- export declare function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: BackgroundQueryHookOptionsNoInfer<TData, TVariables>): [QueryReference<TData>, UseBackgroundQueryResult<TData, TVariables>];
49
52
  export declare function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: SkipToken): [undefined, UseBackgroundQueryResult<TData, TVariables>];
50
53
  export declare function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: SkipToken | (BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {
51
54
  returnPartialData: true;
52
55
  })): [
53
- QueryReference<DeepPartial<TData>> | undefined,
56
+ QueryReference<DeepPartial<TData>, TVariables> | undefined,
54
57
  UseBackgroundQueryResult<TData, TVariables>
55
58
  ];
56
59
  export declare function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: SkipToken | BackgroundQueryHookOptionsNoInfer<TData, TVariables>): [
57
- QueryReference<TData> | undefined,
60
+ QueryReference<TData, TVariables> | undefined,
58
61
  UseBackgroundQueryResult<TData, TVariables>
59
62
  ];
60
63
  export {};
@@ -1,7 +1,7 @@
1
1
  import { __spreadArray } from "tslib";
2
2
  import * as React from "rehackt";
3
3
  import { useApolloClient } from "./useApolloClient.js";
4
- import { wrapQueryRef } from "../cache/QueryReference.js";
4
+ import { unwrapQueryRef, updateWrappedQueryRef, wrapQueryRef, } from "../cache/QueryReference.js";
5
5
  import { getSuspenseCache } from "../cache/index.js";
6
6
  import { useWatchQueryOptions } from "./useSuspenseQuery.js";
7
7
  import { canonicalStringify } from "../../cache/index.js";
@@ -12,6 +12,12 @@ export function useBackgroundQuery(query, options) {
12
12
  var watchQueryOptions = useWatchQueryOptions({ client: client, query: query, options: options });
13
13
  var fetchPolicy = watchQueryOptions.fetchPolicy, variables = watchQueryOptions.variables;
14
14
  var _a = options.queryKey, queryKey = _a === void 0 ? [] : _a;
15
+ // This ref tracks the first time query execution is enabled to determine
16
+ // whether to return a query ref or `undefined`. When initialized
17
+ // in a skipped state (either via `skip: true` or `skipToken`) we return
18
+ // `undefined` for the `queryRef` until the query has been enabled. Once
19
+ // enabled, a query ref is always returned regardless of whether the query is
20
+ // skipped again later.
15
21
  var didFetchResult = React.useRef(fetchPolicy !== "standby");
16
22
  didFetchResult.current || (didFetchResult.current = fetchPolicy !== "standby");
17
23
  var cacheKey = __spreadArray([
@@ -21,28 +27,25 @@ export function useBackgroundQuery(query, options) {
21
27
  var queryRef = suspenseCache.getQueryRef(cacheKey, function () {
22
28
  return client.watchQuery(watchQueryOptions);
23
29
  });
24
- var _b = React.useState(function () { return new Map([[queryRef.key, queryRef.promise]]); }), promiseCache = _b[0], setPromiseCache = _b[1];
30
+ var _b = React.useState(wrapQueryRef(queryRef)), wrappedQueryRef = _b[0], setWrappedQueryRef = _b[1];
31
+ if (unwrapQueryRef(wrappedQueryRef) !== queryRef) {
32
+ setWrappedQueryRef(wrapQueryRef(queryRef));
33
+ }
25
34
  if (queryRef.didChangeOptions(watchQueryOptions)) {
26
35
  var promise = queryRef.applyOptions(watchQueryOptions);
27
- promiseCache.set(queryRef.key, promise);
36
+ updateWrappedQueryRef(wrappedQueryRef, promise);
28
37
  }
29
38
  React.useEffect(function () { return queryRef.retain(); }, [queryRef]);
30
39
  var fetchMore = React.useCallback(function (options) {
31
40
  var promise = queryRef.fetchMore(options);
32
- setPromiseCache(function (promiseCache) {
33
- return new Map(promiseCache).set(queryRef.key, queryRef.promise);
34
- });
41
+ setWrappedQueryRef(wrapQueryRef(queryRef));
35
42
  return promise;
36
43
  }, [queryRef]);
37
44
  var refetch = React.useCallback(function (variables) {
38
45
  var promise = queryRef.refetch(variables);
39
- setPromiseCache(function (promiseCache) {
40
- return new Map(promiseCache).set(queryRef.key, queryRef.promise);
41
- });
46
+ setWrappedQueryRef(wrapQueryRef(queryRef));
42
47
  return promise;
43
48
  }, [queryRef]);
44
- queryRef.promiseCache = promiseCache;
45
- var wrappedQueryRef = React.useMemo(function () { return wrapQueryRef(queryRef); }, [queryRef]);
46
49
  return [
47
50
  didFetchResult.current ? wrappedQueryRef : void 0,
48
51
  { fetchMore: fetchMore, refetch: refetch },
@@ -1 +1 @@
1
- {"version":3,"file":"useBackgroundQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useBackgroundQuery.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAMjC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAI1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAE7D,OAAO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AAO,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,KAAK,CAAC;QACjD,EAAE,SAAS,WAAA,EAAE,OAAO,SAAA,EAAE;KACvB,CAAC;AACJ,CAAC","sourcesContent":["import * as React from \"rehackt\";\nimport type {\n DocumentNode,\n OperationVariables,\n TypedDocumentNode,\n} from \"../../core/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport { wrapQueryRef } from \"../cache/QueryReference.js\";\nimport type { QueryReference } from \"../cache/QueryReference.js\";\nimport type { BackgroundQueryHookOptions, NoInfer } from \"../types/types.js\";\nimport { __use } from \"./internal/index.js\";\nimport { getSuspenseCache } from \"../cache/index.js\";\nimport { useWatchQueryOptions } from \"./useSuspenseQuery.js\";\nimport type { FetchMoreFunction, RefetchFunction } from \"./useSuspenseQuery.js\";\nimport { canonicalStringify } from \"../../cache/index.js\";\nimport type { DeepPartial } from \"../../utilities/index.js\";\nimport type { CacheKey } from \"../cache/types.js\";\nimport type { SkipToken } from \"./constants.js\";\n\nexport type UseBackgroundQueryResult<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n> = {\n fetchMore: FetchMoreFunction<TData, TVariables>;\n refetch: RefetchFunction<TData, TVariables>;\n};\n\ntype BackgroundQueryHookOptionsNoInfer<\n TData,\n TVariables extends OperationVariables,\n> = BackgroundQueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>;\n\nexport function useBackgroundQuery<\n TData,\n TVariables extends OperationVariables,\n TOptions extends Omit<BackgroundQueryHookOptions<TData>, \"variables\">,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & TOptions\n): [\n (\n | QueryReference<\n TOptions[\"errorPolicy\"] extends \"ignore\" | \"all\"\n ? TOptions[\"returnPartialData\"] extends true\n ? DeepPartial<TData> | undefined\n : TData | undefined\n : TOptions[\"returnPartialData\"] extends true\n ? DeepPartial<TData>\n : TData\n >\n | (TOptions[\"skip\"] extends boolean ? undefined : never)\n ),\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n returnPartialData: true;\n errorPolicy: \"ignore\" | \"all\";\n }\n): [\n QueryReference<DeepPartial<TData> | undefined>,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n errorPolicy: \"ignore\" | \"all\";\n }\n): [\n QueryReference<TData | undefined>,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n skip: boolean;\n returnPartialData: true;\n }\n): [\n QueryReference<DeepPartial<TData>> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n returnPartialData: true;\n }\n): [\n QueryReference<DeepPartial<TData>>,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n skip: boolean;\n }\n): [\n QueryReference<TData> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: BackgroundQueryHookOptionsNoInfer<TData, TVariables>\n): [QueryReference<TData>, UseBackgroundQueryResult<TData, TVariables>];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SkipToken\n): [undefined, UseBackgroundQueryResult<TData, TVariables>];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | SkipToken\n | (BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n returnPartialData: true;\n })\n): [\n QueryReference<DeepPartial<TData>> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: SkipToken | BackgroundQueryHookOptionsNoInfer<TData, TVariables>\n): [\n QueryReference<TData> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | (SkipToken &\n Partial<BackgroundQueryHookOptionsNoInfer<TData, TVariables>>)\n | BackgroundQueryHookOptionsNoInfer<TData, TVariables> = Object.create(null)\n): [\n QueryReference<TData> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n] {\n const client = useApolloClient(options.client);\n const suspenseCache = getSuspenseCache(client);\n const watchQueryOptions = useWatchQueryOptions({ client, query, options });\n const { fetchPolicy, variables } = watchQueryOptions;\n const { queryKey = [] } = options;\n\n // This ref tracks the first time query execution is enabled to determine\n // whether to return a query ref or `undefined`. When initialized\n // in a skipped state (either via `skip: true` or `skipToken`) we return\n // `undefined` for the `queryRef` until the query has been enabled. Once\n // enabled, a query ref is always returned regardless of whether the query is\n // skipped again later.\n const didFetchResult = React.useRef(fetchPolicy !== \"standby\");\n didFetchResult.current ||= fetchPolicy !== \"standby\";\n\n const cacheKey: CacheKey = [\n query,\n canonicalStringify(variables),\n ...([] as any[]).concat(queryKey),\n ];\n\n const queryRef = suspenseCache.getQueryRef(cacheKey, () =>\n client.watchQuery(watchQueryOptions)\n );\n\n const [promiseCache, setPromiseCache] = React.useState(\n () => new Map([[queryRef.key, queryRef.promise]])\n );\n\n if (queryRef.didChangeOptions(watchQueryOptions)) {\n const promise = queryRef.applyOptions(watchQueryOptions);\n promiseCache.set(queryRef.key, promise);\n }\n\n React.useEffect(() => queryRef.retain(), [queryRef]);\n\n const fetchMore: FetchMoreFunction<TData, TVariables> = React.useCallback(\n (options) => {\n const promise = queryRef.fetchMore(options);\n\n setPromiseCache((promiseCache) =>\n new Map(promiseCache).set(queryRef.key, queryRef.promise)\n );\n\n return promise;\n },\n [queryRef]\n );\n\n const refetch: RefetchFunction<TData, TVariables> = React.useCallback(\n (variables) => {\n const promise = queryRef.refetch(variables);\n\n setPromiseCache((promiseCache) =>\n new Map(promiseCache).set(queryRef.key, queryRef.promise)\n );\n\n return promise;\n },\n [queryRef]\n );\n\n queryRef.promiseCache = promiseCache;\n\n const wrappedQueryRef = React.useMemo(\n () => wrapQueryRef(queryRef),\n [queryRef]\n );\n\n return [\n didFetchResult.current ? wrappedQueryRef : void 0,\n { fetchMore, refetch },\n ];\n}\n"]}
1
+ {"version":3,"file":"useBackgroundQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useBackgroundQuery.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAQjC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,YAAY,GACb,MAAM,4BAA4B,CAAC;AAIpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,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entNode,\n WatchQueryOptions,\n} from \"../../core/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport {\n unwrapQueryRef,\n updateWrappedQueryRef,\n wrapQueryRef,\n} from \"../cache/QueryReference.js\";\nimport type { QueryReference } from \"../cache/QueryReference.js\";\nimport type { BackgroundQueryHookOptions, NoInfer } from \"../types/types.js\";\nimport { __use } from \"./internal/index.js\";\nimport { getSuspenseCache } from \"../cache/index.js\";\nimport { useWatchQueryOptions } from \"./useSuspenseQuery.js\";\nimport type { FetchMoreFunction, RefetchFunction } from \"./useSuspenseQuery.js\";\nimport { canonicalStringify } from \"../../cache/index.js\";\nimport type { DeepPartial } from \"../../utilities/index.js\";\nimport type { CacheKey } from \"../cache/types.js\";\nimport type { SkipToken } from \"./constants.js\";\n\nexport type UseBackgroundQueryResult<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n> = {\n fetchMore: FetchMoreFunction<TData, TVariables>;\n refetch: RefetchFunction<TData, TVariables>;\n};\n\ntype BackgroundQueryHookOptionsNoInfer<\n TData,\n TVariables extends OperationVariables,\n> = BackgroundQueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>;\n\nexport function useBackgroundQuery<\n TData,\n TVariables extends OperationVariables,\n TOptions extends Omit<BackgroundQueryHookOptions<TData>, \"variables\">,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & TOptions\n): [\n (\n | QueryReference<\n TOptions[\"errorPolicy\"] extends \"ignore\" | \"all\" ?\n TOptions[\"returnPartialData\"] extends true ?\n DeepPartial<TData> | undefined\n : TData | undefined\n : TOptions[\"returnPartialData\"] extends true ? DeepPartial<TData>\n : TData,\n TVariables\n >\n | (TOptions[\"skip\"] extends boolean ? undefined : never)\n ),\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n returnPartialData: true;\n errorPolicy: \"ignore\" | \"all\";\n }\n): [\n QueryReference<DeepPartial<TData> | undefined, TVariables>,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n errorPolicy: \"ignore\" | \"all\";\n }\n): [\n QueryReference<TData | undefined, TVariables>,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n skip: boolean;\n returnPartialData: true;\n }\n): [\n QueryReference<DeepPartial<TData>, TVariables> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n returnPartialData: true;\n }\n): [\n QueryReference<DeepPartial<TData>, TVariables>,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n skip: boolean;\n }\n): [\n QueryReference<TData, TVariables> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: BackgroundQueryHookOptionsNoInfer<TData, TVariables>\n): [\n QueryReference<TData, TVariables>,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SkipToken\n): [undefined, UseBackgroundQueryResult<TData, TVariables>];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | SkipToken\n | (BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n returnPartialData: true;\n })\n): [\n QueryReference<DeepPartial<TData>, TVariables> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: SkipToken | BackgroundQueryHookOptionsNoInfer<TData, TVariables>\n): [\n QueryReference<TData, TVariables> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | (SkipToken &\n Partial<BackgroundQueryHookOptionsNoInfer<TData, TVariables>>)\n | BackgroundQueryHookOptionsNoInfer<TData, TVariables> = Object.create(null)\n): [\n QueryReference<TData, TVariables> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n] {\n const client = useApolloClient(options.client);\n const suspenseCache = getSuspenseCache(client);\n const watchQueryOptions = useWatchQueryOptions({ client, query, options });\n const { fetchPolicy, variables } = watchQueryOptions;\n const { queryKey = [] } = options;\n\n // This ref tracks the first time query execution is enabled to determine\n // whether to return a query ref or `undefined`. When initialized\n // in a skipped state (either via `skip: true` or `skipToken`) we return\n // `undefined` for the `queryRef` until the query has been enabled. Once\n // enabled, a query ref is always returned regardless of whether the query is\n // skipped again later.\n const didFetchResult = React.useRef(fetchPolicy !== \"standby\");\n didFetchResult.current ||= fetchPolicy !== \"standby\";\n\n const cacheKey: CacheKey = [\n query,\n canonicalStringify(variables),\n ...([] as any[]).concat(queryKey),\n ];\n\n const queryRef = suspenseCache.getQueryRef(cacheKey, () =>\n client.watchQuery(watchQueryOptions as WatchQueryOptions<any, any>)\n );\n\n const [wrappedQueryRef, setWrappedQueryRef] = React.useState(\n wrapQueryRef(queryRef)\n );\n if (unwrapQueryRef(wrappedQueryRef) !== queryRef) {\n setWrappedQueryRef(wrapQueryRef(queryRef));\n }\n if (queryRef.didChangeOptions(watchQueryOptions)) {\n const promise = queryRef.applyOptions(watchQueryOptions);\n updateWrappedQueryRef(wrappedQueryRef, promise);\n }\n\n React.useEffect(() => queryRef.retain(), [queryRef]);\n\n const fetchMore: FetchMoreFunction<TData, TVariables> = React.useCallback(\n (options) => {\n const promise = queryRef.fetchMore(options as FetchMoreQueryOptions<any>);\n\n setWrappedQueryRef(wrapQueryRef(queryRef));\n\n return promise;\n },\n [queryRef]\n );\n\n const refetch: RefetchFunction<TData, TVariables> = React.useCallback(\n (variables) => {\n const promise = queryRef.refetch(variables);\n\n setWrappedQueryRef(wrapQueryRef(queryRef));\n\n return promise;\n },\n [queryRef]\n );\n\n return [\n didFetchResult.current ? wrappedQueryRef : void 0,\n { fetchMore, refetch },\n ];\n}\n"]}
@@ -10,11 +10,12 @@ export function useFragment(options) {
10
10
  var diffOptions = __assign(__assign({}, rest), { returnPartialData: true, id: typeof from === "string" ? from : cache.identify(from), query: cache["getFragmentDoc"](fragment, fragmentName), optimistic: optimistic });
11
11
  var resultRef = React.useRef();
12
12
  var latestDiff = cache.diff(diffOptions);
13
+ // Used for both getSnapshot and getServerSnapshot
13
14
  var getSnapshot = function () {
14
15
  var latestDiffToResult = diffToResult(latestDiff);
15
- return resultRef.current &&
16
- equal(resultRef.current.data, latestDiffToResult.data)
17
- ? resultRef.current
16
+ return (resultRef.current &&
17
+ equal(resultRef.current.data, latestDiffToResult.data)) ?
18
+ resultRef.current
18
19
  : (resultRef.current = latestDiffToResult);
19
20
  };
20
21
  return useSyncExternalStore(function (forceUpdate) {
@@ -1 +1 @@
1
- {"version":3,"file":"useFragment.js","sourceRoot":"","sources":["../../../src/react/hooks/useFragment.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAGtC,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAQ1D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AA8BjE,MAAM,UAAU,WAAW,CACzB,OAAyC;IAEjC,IAAA,KAAK,GAAK,eAAe,EAAE,MAAtB,CAAuB;IAE5B,IAAA,QAAQ,GAAqD,OAAO,SAA5D,EAAE,YAAY,GAAuC,OAAO,aAA9C,EAAE,IAAI,GAAiC,OAAO,KAAxC,EAAE,KAA+B,OAAO,WAArB,EAAjB,UAAU,mBAAG,IAAI,KAAA,EAAK,IAAI,UAAK,OAAO,EAAtE,kDAA4D,CAAF,CAAa;IAE7E,IAAM,WAAW,yBACZ,IAAI,KACP,iBAAiB,EAAE,IAAI,EACvB,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,KAAK,CAAC,MAAM,EAA4B,CAAC;IAC3D,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,IAAI,WAAW,GAAG,CAAC,CAAC;QACpB,IAAM,UAAU,GAAG,KAAK,CAAC,KAAK,uBACzB,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,GAAG,UAAU,CAAC,WAAW,CAAQ,CAAC;iBAC9C;YACH,CAAC,IACD,CAAC;QACH,OAAO;YACL,UAAU,EAAE,CAAC;YACb,YAAY,CAAC,WAAW,CAAC,CAAC;QAC5B,CAAC,CAAC;IACJ,CAAC,EACD,WAAW,EACX,WAAW,CACZ,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CACnB,IAA6B;IAE7B,IAAM,MAAM,GAAG;QACb,IAAI,EAAE,IAAI,CAAC,MAAO;QAClB,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ;KACE,CAAC;IAE9B,IAAI,IAAI,CAAC,OAAO,EAAE;QAChB,MAAM,CAAC,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAC,KAAK,IAAK,OAAA,KAAK,CAAC,OAAO,EAAb,CAAa,CAAC,CAAC,CAAC;KAC7E;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import * as React from \"rehackt\";\nimport { equal } from \"@wry/equality\";\n\nimport type { DeepPartial } from \"../../utilities/index.js\";\nimport { mergeDeepArray } from \"../../utilities/index.js\";\nimport type {\n Cache,\n Reference,\n StoreObject,\n MissingTree,\n} from \"../../cache/index.js\";\n\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore.js\";\nimport type { OperationVariables } from \"../../core/index.js\";\nimport type { NoInfer } from \"../types/types.js\";\n\nexport interface UseFragmentOptions<TData, TVars>\n extends Omit<\n Cache.DiffOptions<NoInfer<TData>, NoInfer<TVars>>,\n \"id\" | \"query\" | \"optimistic\" | \"previousResult\" | \"returnPartialData\"\n >,\n Omit<\n Cache.ReadFragmentOptions<TData, TVars>,\n \"id\" | \"variables\" | \"returnPartialData\"\n > {\n from: StoreObject | Reference | string;\n // Override this field to make it optional (default: true).\n optimistic?: boolean;\n}\n\nexport type UseFragmentResult<TData> =\n | {\n data: TData;\n complete: true;\n missing?: never;\n }\n | {\n data: DeepPartial<TData>;\n complete: false;\n missing?: MissingTree;\n };\n\nexport function useFragment<TData = any, TVars = OperationVariables>(\n options: UseFragmentOptions<TData, TVars>\n): UseFragmentResult<TData> {\n const { cache } = useApolloClient();\n\n const { fragment, fragmentName, from, optimistic = true, ...rest } = options;\n\n const diffOptions: Cache.DiffOptions<TData, TVars> = {\n ...rest,\n returnPartialData: true,\n id: typeof from === \"string\" ? from : cache.identify(from),\n query: cache[\"getFragmentDoc\"](fragment, fragmentName),\n optimistic,\n };\n\n const resultRef = React.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 let lastTimeout = 0;\n const unsubcribe = cache.watch({\n ...diffOptions,\n immediate: true,\n callback(diff) {\n if (!equal(diff, latestDiff)) {\n resultRef.current = diffToResult((latestDiff = diff));\n lastTimeout = setTimeout(forceUpdate) as any;\n }\n },\n });\n return () => {\n unsubcribe();\n clearTimeout(lastTimeout);\n };\n },\n getSnapshot,\n getSnapshot\n );\n}\n\nfunction diffToResult<TData>(\n diff: Cache.DiffResult<TData>\n): UseFragmentResult<TData> {\n const result = {\n data: diff.result!,\n complete: !!diff.complete,\n } as UseFragmentResult<TData>;\n\n if (diff.missing) {\n result.missing = mergeDeepArray(diff.missing.map((error) => error.missing));\n }\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"useFragment.js","sourceRoot":"","sources":["../../../src/react/hooks/useFragment.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAGtC,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAQ1D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AA8BjE,MAAM,UAAU,WAAW,CACzB,OAAyC;IAEjC,IAAA,KAAK,GAAK,eAAe,EAAE,MAAtB,CAAuB;IAE5B,IAAA,QAAQ,GAAqD,OAAO,SAA5D,EAAE,YAAY,GAAuC,OAAO,aAA9C,EAAE,IAAI,GAAiC,OAAO,KAAxC,EAAE,KAA+B,OAAO,WAArB,EAAjB,UAAU,mBAAG,IAAI,KAAA,EAAK,IAAI,UAAK,OAAO,EAAtE,kDAA4D,CAAF,CAAa;IAE7E,IAAM,WAAW,yBACZ,IAAI,KACP,iBAAiB,EAAE,IAAI,EACvB,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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MAAM,CAAC,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAC,KAAK,IAAK,OAAA,KAAK,CAAC,OAAO,EAAb,CAAa,CAAC,CAAC,CAAC;IAC9E,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import * as React from \"rehackt\";\nimport { equal } from \"@wry/equality\";\n\nimport type { DeepPartial } from \"../../utilities/index.js\";\nimport { mergeDeepArray } from \"../../utilities/index.js\";\nimport type {\n Cache,\n Reference,\n StoreObject,\n MissingTree,\n} from \"../../cache/index.js\";\n\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore.js\";\nimport type { OperationVariables } from \"../../core/index.js\";\nimport type { NoInfer } from \"../types/types.js\";\n\nexport interface UseFragmentOptions<TData, TVars>\n extends Omit<\n Cache.DiffOptions<NoInfer<TData>, NoInfer<TVars>>,\n \"id\" | \"query\" | \"optimistic\" | \"previousResult\" | \"returnPartialData\"\n >,\n Omit<\n Cache.ReadFragmentOptions<TData, TVars>,\n \"id\" | \"variables\" | \"returnPartialData\"\n > {\n from: StoreObject | Reference | string;\n // Override this field to make it optional (default: true).\n optimistic?: boolean;\n}\n\nexport type UseFragmentResult<TData> =\n | {\n data: TData;\n complete: true;\n missing?: never;\n }\n | {\n data: DeepPartial<TData>;\n complete: false;\n missing?: MissingTree;\n };\n\nexport function useFragment<TData = any, TVars = OperationVariables>(\n options: UseFragmentOptions<TData, TVars>\n): UseFragmentResult<TData> {\n const { cache } = useApolloClient();\n\n const { fragment, fragmentName, from, optimistic = true, ...rest } = options;\n\n const diffOptions: Cache.DiffOptions<TData, TVars> = {\n ...rest,\n returnPartialData: true,\n id: typeof from === \"string\" ? from : cache.identify(from),\n query: cache[\"getFragmentDoc\"](fragment, fragmentName),\n optimistic,\n };\n\n const resultRef = React.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 (\n resultRef.current &&\n equal(resultRef.current.data, latestDiffToResult.data)\n ) ?\n resultRef.current\n : (resultRef.current = latestDiffToResult);\n };\n\n return useSyncExternalStore(\n (forceUpdate) => {\n let lastTimeout = 0;\n const unsubcribe = cache.watch({\n ...diffOptions,\n immediate: true,\n callback(diff) {\n if (!equal(diff, latestDiff)) {\n resultRef.current = diffToResult((latestDiff = diff));\n lastTimeout = setTimeout(forceUpdate) as any;\n }\n },\n });\n return () => {\n unsubcribe();\n clearTimeout(lastTimeout);\n };\n },\n getSnapshot,\n getSnapshot\n );\n}\n\nfunction diffToResult<TData>(\n diff: Cache.DiffResult<TData>\n): UseFragmentResult<TData> {\n const result = {\n data: diff.result!,\n complete: !!diff.complete,\n } as UseFragmentResult<TData>;\n\n if (diff.missing) {\n result.missing = mergeDeepArray(diff.missing.map((error) => error.missing));\n }\n\n return result;\n}\n"]}
@@ -3,6 +3,8 @@ import * as React from "rehackt";
3
3
  import { mergeOptions } from "../../utilities/index.js";
4
4
  import { useInternalState } from "./useQuery.js";
5
5
  import { useApolloClient } from "./useApolloClient.js";
6
+ // The following methods, when called will execute the query, regardless of
7
+ // whether the useLazyQuery execute function was called before.
6
8
  var EAGER_METHODS = [
7
9
  "refetch",
8
10
  "reobserve",
@@ -18,6 +20,8 @@ export function useLazyQuery(query, options) {
18
20
  var queryRef = React.useRef();
19
21
  var merged = mergeOptions(options, execOptionsRef.current || {});
20
22
  var document = (_a = merged === null || merged === void 0 ? void 0 : merged.query) !== null && _a !== void 0 ? _a : query;
23
+ // Use refs to track options and the used query to ensure the `execute`
24
+ // function remains referentially stable between renders.
21
25
  optionsRef.current = merged;
22
26
  queryRef.current = document;
23
27
  var internalState = useInternalState(useApolloClient(options && options.client), document);
@@ -27,6 +31,7 @@ export function useLazyQuery(query, options) {
27
31
  var result = Object.assign(useQueryResult, {
28
32
  called: !!execOptionsRef.current,
29
33
  });
34
+ // We use useMemo here to make sure the eager methods have a stable identity.
30
35
  var eagerMethods = React.useMemo(function () {
31
36
  var eagerMethods = {};
32
37
  var _loop_1 = function (key) {
@@ -34,8 +39,10 @@ export function useLazyQuery(query, options) {
34
39
  eagerMethods[key] = function () {
35
40
  if (!execOptionsRef.current) {
36
41
  execOptionsRef.current = Object.create(null);
42
+ // Only the first time populating execOptionsRef.current matters here.
37
43
  internalState.forceUpdateState();
38
44
  }
45
+ // @ts-expect-error this is just too generic to type
39
46
  return method.apply(this, arguments);
40
47
  };
41
48
  };
@@ -47,14 +54,16 @@ export function useLazyQuery(query, options) {
47
54
  }, []);
48
55
  Object.assign(result, eagerMethods);
49
56
  var execute = React.useCallback(function (executeOptions) {
50
- execOptionsRef.current = executeOptions
51
- ? __assign(__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
52
- fetchPolicy: initialFetchPolicy,
53
- };
57
+ execOptionsRef.current =
58
+ executeOptions ? __assign(__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
59
+ fetchPolicy: initialFetchPolicy,
60
+ };
54
61
  var options = mergeOptions(optionsRef.current, __assign({ query: queryRef.current }, execOptionsRef.current));
55
62
  var promise = internalState
56
63
  .executeQuery(__assign(__assign({}, options), { skip: false }))
57
64
  .then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
65
+ // Because the return value of `useLazyQuery` is usually floated, we need
66
+ // to catch the promise to prevent unhandled rejections.
58
67
  promise.catch(function () { });
59
68
  return promise;
60
69
  }, []);
@@ -1 +1 @@
1
- {"version":3,"file":"useLazyQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useLazyQuery.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAGjC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAQxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EA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E,MAAM,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import type { DocumentNode } from \"graphql\";\nimport type { TypedDocumentNode } from \"@graphql-typed-document-node/core\";\nimport * as React from \"rehackt\";\n\nimport type { OperationVariables } from \"../../core/index.js\";\nimport { mergeOptions } from \"../../utilities/index.js\";\nimport type {\n LazyQueryHookExecOptions,\n LazyQueryHookOptions,\n LazyQueryResultTuple,\n NoInfer,\n QueryResult,\n} from \"../types/types.js\";\nimport { useInternalState } from \"./useQuery.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\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<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: LazyQueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>\n): LazyQueryResultTuple<TData, TVariables> {\n const execOptionsRef =\n React.useRef<Partial<LazyQueryHookExecOptions<TData, TVariables>>>();\n const optionsRef = React.useRef<LazyQueryHookOptions<TData, TVariables>>();\n const queryRef = React.useRef<\n DocumentNode | TypedDocumentNode<TData, TVariables>\n >();\n const merged = mergeOptions(options, execOptionsRef.current || {});\n const document = merged?.query ?? query;\n\n // Use refs to track options and the used query to ensure the `execute`\n // function remains referentially stable between renders.\n optionsRef.current = merged;\n queryRef.current = document;\n\n const internalState = useInternalState<TData, TVariables>(\n useApolloClient(options && options.client),\n document\n );\n\n const useQueryResult = internalState.useQuery({\n ...merged,\n skip: !execOptionsRef.current,\n });\n\n const initialFetchPolicy =\n useQueryResult.observable.options.initialFetchPolicy ||\n internalState.getDefaultFetchPolicy();\n\n const result: QueryResult<TData, TVariables> = 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 = React.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.forceUpdateState();\n }\n return method.apply(this, arguments);\n };\n }\n\n return eagerMethods;\n }, []);\n\n Object.assign(result, eagerMethods);\n\n const execute = React.useCallback<LazyQueryResultTuple<TData, TVariables>[0]>(\n (executeOptions) => {\n execOptionsRef.current = executeOptions\n ? {\n ...executeOptions,\n fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy,\n }\n : {\n fetchPolicy: initialFetchPolicy,\n };\n\n const options = mergeOptions(optionsRef.current, {\n query: queryRef.current,\n ...execOptionsRef.current,\n });\n\n const promise = internalState\n .executeQuery({ ...options, skip: false })\n .then((queryResult) => Object.assign(queryResult, eagerMethods));\n\n // Because the return value of `useLazyQuery` is usually floated, we need\n // to catch the promise to prevent unhandled rejections.\n promise.catch(() => {});\n\n return promise;\n },\n []\n );\n\n return [execute, result];\n}\n"]}
1
+ {"version":3,"file":"useLazyQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useLazyQuery.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAGjC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAQxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,2EAA2E;AAC3E,+DAA+D;AAC/D,IAAM,aAAa,GAAG;IACpB,SAAS;IACT,WAAW;IACX,WAAW;IACX,aAAa;IACb,cAAc;IACd,iBAAiB;CACT,CAAC;AAEX,MAAM,UAAU,YAAY,CAI1B,KAA0D,EAC1D,OAAmE;;IAEnE,IAAM,cAAc,GAClB,KAAK,CAAC,MAAM,EAAwD,CAAC;IACvE,IAAM,UAAU,G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AAE,CAAC;gBACnC,CAAC;gBACD,oDAAoD;gBACpD,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;YACvC,CAAC,CAAC;;QAVJ,KAAkB,UAAa,EAAb,+BAAa,EAAb,2BAAa,EAAb,IAAa;YAA1B,IAAM,GAAG,sBAAA;oBAAH,GAAG;SAWb;QAED,OAAO,YAAY,CAAC;IACtB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAEpC,IAAM,OAAO,GAAG,KAAK,CAAC,WAAW,CAC/B,UAAC,cAAc;QACb,cAAc,CAAC,OAAO;YACpB,cAAc,CAAC,CAAC,uBAET,cAAc,KACjB,WAAW,EAAE,cAAc,CAAC,WAAW,IAAI,kBAAkB,IAEjE,CAAC,CAAC;gBACE,WAAW,EAAE,kBAAkB;aAChC,CAAC;QAEN,IAAM,OAAO,GAAG,YAAY,CAAC,UAAU,CAAC,OAAO,aAC7C,KAAK,EAAE,QAAQ,CAAC,OAAO,IACpB,cAAc,CAAC,OAAO,EACzB,CAAC;QAEH,IAAM,OAAO,GAAG,aAAa;aAC1B,YAAY,uBAAM,OAAO,KAAE,IAAI,EAAE,KAAK,IAAG;aACzC,IAAI,CAAC,UAAC,WAAW,IAAK,OAAA,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,YAAY,CAAC,EAAxC,CAAwC,CAAC,CAAC;QAEnE,yEAAyE;QACzE,wDAAwD;QACxD,OAAO,CAAC,KAAK,CAAC,cAAO,CAAC,CAAC,CAAC;QAExB,OAAO,OAAO,CAAC;IACjB,CAAC,EACD,EAAE,CACH,CAAC;IAEF,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import type { DocumentNode } from \"graphql\";\nimport type { TypedDocumentNode } from \"@graphql-typed-document-node/core\";\nimport * as React from \"rehackt\";\n\nimport type { OperationVariables } from \"../../core/index.js\";\nimport { mergeOptions } from \"../../utilities/index.js\";\nimport type {\n LazyQueryHookExecOptions,\n LazyQueryHookOptions,\n LazyQueryResultTuple,\n NoInfer,\n QueryResult,\n} from \"../types/types.js\";\nimport { useInternalState } from \"./useQuery.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\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<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: LazyQueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>\n): LazyQueryResultTuple<TData, TVariables> {\n const execOptionsRef =\n React.useRef<Partial<LazyQueryHookExecOptions<TData, TVariables>>>();\n const optionsRef = React.useRef<LazyQueryHookOptions<TData, TVariables>>();\n const queryRef = React.useRef<\n DocumentNode | TypedDocumentNode<TData, TVariables>\n >();\n const merged = mergeOptions(options, execOptionsRef.current || {});\n const document = merged?.query ?? query;\n\n // Use refs to track options and the used query to ensure the `execute`\n // function remains referentially stable between renders.\n optionsRef.current = merged;\n queryRef.current = document;\n\n const internalState = useInternalState<TData, TVariables>(\n useApolloClient(options && options.client),\n document\n );\n\n const useQueryResult = internalState.useQuery({\n ...merged,\n skip: !execOptionsRef.current,\n });\n\n const initialFetchPolicy =\n useQueryResult.observable.options.initialFetchPolicy ||\n internalState.getDefaultFetchPolicy();\n\n const result: QueryResult<TData, TVariables> = 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 = React.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.forceUpdateState();\n }\n // @ts-expect-error this is just too generic to type\n return method.apply(this, arguments);\n };\n }\n\n return eagerMethods;\n }, []);\n\n Object.assign(result, eagerMethods);\n\n const execute = React.useCallback<LazyQueryResultTuple<TData, TVariables>[0]>(\n (executeOptions) => {\n execOptionsRef.current =\n executeOptions ?\n {\n ...executeOptions,\n fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy,\n }\n : {\n fetchPolicy: initialFetchPolicy,\n };\n\n const options = mergeOptions(optionsRef.current, {\n query: queryRef.current,\n ...execOptionsRef.current,\n });\n\n const promise = internalState\n .executeQuery({ ...options, skip: false })\n .then((queryResult) => Object.assign(queryResult, eagerMethods));\n\n // Because the return value of `useLazyQuery` is usually floated, we need\n // to catch the promise to prevent unhandled rejections.\n promise.catch(() => {});\n\n return promise;\n },\n []\n );\n\n return [execute, result];\n}\n"]}
@@ -0,0 +1,30 @@
1
+ import type { DocumentNode, OperationVariables, TypedDocumentNode } from "../../core/index.js";
2
+ import type { QueryReference } from "../cache/QueryReference.js";
3
+ import type { LoadableQueryHookOptions } from "../types/types.js";
4
+ import type { FetchMoreFunction, RefetchFunction } from "./useSuspenseQuery.js";
5
+ import type { DeepPartial, OnlyRequiredProperties } from "../../utilities/index.js";
6
+ export type LoadQueryFunction<TVariables extends OperationVariables> = (...args: [TVariables] extends [never] ? [] : {} extends OnlyRequiredProperties<TVariables> ? [variables?: TVariables] : [variables: TVariables]) => void;
7
+ type ResetFunction = () => void;
8
+ export type UseLoadableQueryResult<TData = unknown, TVariables extends OperationVariables = OperationVariables> = [
9
+ LoadQueryFunction<TVariables>,
10
+ QueryReference<TData, TVariables> | null,
11
+ {
12
+ fetchMore: FetchMoreFunction<TData, TVariables>;
13
+ refetch: RefetchFunction<TData, TVariables>;
14
+ reset: ResetFunction;
15
+ }
16
+ ];
17
+ export declare function useLoadableQuery<TData, TVariables extends OperationVariables, TOptions extends LoadableQueryHookOptions>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: LoadableQueryHookOptions & TOptions): UseLoadableQueryResult<TOptions["errorPolicy"] extends "ignore" | "all" ? TOptions["returnPartialData"] extends true ? DeepPartial<TData> | undefined : TData | undefined : TOptions["returnPartialData"] extends true ? DeepPartial<TData> : TData, TVariables>;
18
+ export declare function useLoadableQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: LoadableQueryHookOptions & {
19
+ returnPartialData: true;
20
+ errorPolicy: "ignore" | "all";
21
+ }): UseLoadableQueryResult<DeepPartial<TData> | undefined, TVariables>;
22
+ export declare function useLoadableQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: LoadableQueryHookOptions & {
23
+ errorPolicy: "ignore" | "all";
24
+ }): UseLoadableQueryResult<TData | undefined, TVariables>;
25
+ export declare function useLoadableQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: LoadableQueryHookOptions & {
26
+ returnPartialData: true;
27
+ }): UseLoadableQueryResult<DeepPartial<TData>, TVariables>;
28
+ export declare function useLoadableQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: LoadableQueryHookOptions): UseLoadableQueryResult<TData, TVariables>;
29
+ export {};
30
+ //# sourceMappingURL=useLoadableQuery.d.ts.map
@@ -0,0 +1,61 @@
1
+ import { __assign, __spreadArray } from "tslib";
2
+ import * as React from "rehackt";
3
+ import { useApolloClient } from "./useApolloClient.js";
4
+ import { unwrapQueryRef, updateWrappedQueryRef, wrapQueryRef, } from "../cache/QueryReference.js";
5
+ import { useRenderGuard } from "./internal/index.js";
6
+ import { getSuspenseCache } from "../cache/index.js";
7
+ import { useWatchQueryOptions } from "./useSuspenseQuery.js";
8
+ import { canonicalStringify } from "../../cache/index.js";
9
+ import { invariant } from "../../utilities/globals/index.js";
10
+ export function useLoadableQuery(query, options) {
11
+ if (options === void 0) { options = Object.create(null); }
12
+ var client = useApolloClient(options.client);
13
+ var suspenseCache = getSuspenseCache(client);
14
+ var watchQueryOptions = useWatchQueryOptions({ client: client, query: query, options: options });
15
+ var _a = options.queryKey, queryKey = _a === void 0 ? [] : _a;
16
+ var _b = React.useState(null), queryRef = _b[0], setQueryRef = _b[1];
17
+ var internalQueryRef = queryRef && unwrapQueryRef(queryRef);
18
+ if (queryRef && (internalQueryRef === null || internalQueryRef === void 0 ? void 0 : internalQueryRef.didChangeOptions(watchQueryOptions))) {
19
+ var promise = internalQueryRef.applyOptions(watchQueryOptions);
20
+ updateWrappedQueryRef(queryRef, promise);
21
+ }
22
+ var calledDuringRender = useRenderGuard();
23
+ React.useEffect(function () { return internalQueryRef === null || internalQueryRef === void 0 ? void 0 : internalQueryRef.retain(); }, [internalQueryRef]);
24
+ var fetchMore = React.useCallback(function (options) {
25
+ if (!internalQueryRef) {
26
+ throw new Error("The query has not been loaded. Please load the query.");
27
+ }
28
+ var promise = internalQueryRef.fetchMore(options);
29
+ setQueryRef(wrapQueryRef(internalQueryRef));
30
+ return promise;
31
+ }, [internalQueryRef]);
32
+ var refetch = React.useCallback(function (options) {
33
+ if (!internalQueryRef) {
34
+ throw new Error("The query has not been loaded. Please load the query.");
35
+ }
36
+ var promise = internalQueryRef.refetch(options);
37
+ setQueryRef(wrapQueryRef(internalQueryRef));
38
+ return promise;
39
+ }, [internalQueryRef]);
40
+ var loadQuery = React.useCallback(function () {
41
+ var args = [];
42
+ for (var _i = 0; _i < arguments.length; _i++) {
43
+ args[_i] = arguments[_i];
44
+ }
45
+ invariant(!calledDuringRender(), 50);
46
+ var variables = args[0];
47
+ var cacheKey = __spreadArray([
48
+ query,
49
+ canonicalStringify(variables)
50
+ ], [].concat(queryKey), true);
51
+ var queryRef = suspenseCache.getQueryRef(cacheKey, function () {
52
+ return client.watchQuery(__assign(__assign({}, watchQueryOptions), { variables: variables }));
53
+ });
54
+ setQueryRef(wrapQueryRef(queryRef));
55
+ }, [query, queryKey, suspenseCache, watchQueryOptions, calledDuringRender]);
56
+ var reset = React.useCallback(function () {
57
+ setQueryRef(null);
58
+ }, [queryRef]);
59
+ return [loadQuery, queryRef, { fetchMore: fetchMore, refetch: refetch, reset: reset }];
60
+ }
61
+ //# sourceMappingURL=useLoadableQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLoadableQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useLoadableQuery.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAQjC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,YAAY,GACb,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAS,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAE7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAM1D,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAmF7D,MAAM,UAAU,gBAAgB,CAI9B,KAA0D,EAC1D,OAAuD;IAAvD,wBAAA,EAAA,UAAoC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;IAEvD,IAAM,MAAM,GAAG,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/C,IAAM,aAAa,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAC/C,IAAM,iBAAiB,GAAG,oBAAoB,CAAC,EAAE,MAAM,QAAA,EAAE,KAAK,OAAA,EAAE,OAAO,SAAA,EAAE,CAAC,CAAC;IACnE,IAAA,KAAkB,OAAO,SAAZ,EAAb,QAAQ,mBAAG,EAAE,KAAA,CAAa;IAE5B,IAAA,KAA0B,KAAK,CAAC,QAAQ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AAC;QAE5C,OAAO,OAAO,CAAC;IACjB,CAAC,EACD,CAAC,gBAAgB,CAAC,CACnB,CAAC;IAEF,IAAM,SAAS,GAAkC,KAAK,CAAC,WAAW,CAChE;QAAC,cAAO;aAAP,UAAO,EAAP,qBAAO,EAAP,IAAO;YAAP,yBAAO;;QACN,SAAS,CACP,CAAC,kBAAkB,EAAE,EACrB,sIAAsI,CACvI,CAAC;QAEK,IAAA,SAAS,GAAI,IAAI,GAAR,CAAS;QAEzB,IAAM,QAAQ;YACZ,KAAK;YACL,kBAAkB,CAAC,SAAS,CAAC;WACzB,EAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,OAClC,CAAC;QAEF,IAAM,QAAQ,GAAG,aAAa,CAAC,WAAW,CAAC,QAAQ,EAAE;YACnD,OAAA,MAAM,CAAC,UAAU,CAAC,sBACb,iBAAiB,KACpB,SAAS,WAAA,GACqB,CAAC;QAHjC,CAGiC,CAClC,CAAC;QAEF,WAAW,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC;IACtC,CAAC,EACD,CAAC,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,iBAAiB,EAAE,kBAAkB,CAAC,CACxE,CAAC;IAEF,IAAM,KAAK,GAAkB,KAAK,CAAC,WAAW,CAAC;QAC7C,WAAW,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,OAAO,CAAC,SAAS,EAAE,QAAQ,EAAE,EAAE,SAAS,WAAA,EAAE,OAAO,SAAA,EAAE,KAAK,OAAA,EAAE,CAAC,CAAC;AAC9D,CAAC","sourcesContent":["import * as React from \"rehackt\";\nimport type {\n DocumentNode,\n FetchMoreQueryOptions,\n OperationVariables,\n TypedDocumentNode,\n WatchQueryOptions,\n} from \"../../core/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport {\n unwrapQueryRef,\n updateWrappedQueryRef,\n wrapQueryRef,\n} from \"../cache/QueryReference.js\";\nimport type { QueryReference } from \"../cache/QueryReference.js\";\nimport type { LoadableQueryHookOptions } from \"../types/types.js\";\nimport { __use, useRenderGuard } from \"./internal/index.js\";\nimport { getSuspenseCache } from \"../cache/index.js\";\nimport { useWatchQueryOptions } from \"./useSuspenseQuery.js\";\nimport type { FetchMoreFunction, RefetchFunction } from \"./useSuspenseQuery.js\";\nimport { canonicalStringify } from \"../../cache/index.js\";\nimport type {\n DeepPartial,\n OnlyRequiredProperties,\n} from \"../../utilities/index.js\";\nimport type { CacheKey } from \"../cache/types.js\";\nimport { invariant } from \"../../utilities/globals/index.js\";\n\nexport type LoadQueryFunction<TVariables extends OperationVariables> = (\n // Use variadic args to handle cases where TVariables is type `never`, in\n // which case we don't want to allow a variables argument. In other\n // words, we don't want to allow variables to be passed as an argument to this\n // function if the query does not expect variables in the document.\n ...args: [TVariables] extends [never] ? []\n : {} extends OnlyRequiredProperties<TVariables> ? [variables?: TVariables]\n : [variables: TVariables]\n) => void;\n\ntype ResetFunction = () => void;\n\nexport type UseLoadableQueryResult<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n> = [\n LoadQueryFunction<TVariables>,\n QueryReference<TData, TVariables> | null,\n {\n fetchMore: FetchMoreFunction<TData, TVariables>;\n refetch: RefetchFunction<TData, TVariables>;\n reset: ResetFunction;\n },\n];\n\nexport function useLoadableQuery<\n TData,\n TVariables extends OperationVariables,\n TOptions extends LoadableQueryHookOptions,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: LoadableQueryHookOptions & TOptions\n): UseLoadableQueryResult<\n TOptions[\"errorPolicy\"] extends \"ignore\" | \"all\" ?\n TOptions[\"returnPartialData\"] extends true ?\n DeepPartial<TData> | undefined\n : TData | undefined\n : TOptions[\"returnPartialData\"] extends true ? DeepPartial<TData>\n : TData,\n TVariables\n>;\n\nexport function useLoadableQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: LoadableQueryHookOptions & {\n returnPartialData: true;\n errorPolicy: \"ignore\" | \"all\";\n }\n): UseLoadableQueryResult<DeepPartial<TData> | undefined, TVariables>;\n\nexport function useLoadableQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: LoadableQueryHookOptions & {\n errorPolicy: \"ignore\" | \"all\";\n }\n): UseLoadableQueryResult<TData | undefined, TVariables>;\n\nexport function useLoadableQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: LoadableQueryHookOptions & {\n returnPartialData: true;\n }\n): UseLoadableQueryResult<DeepPartial<TData>, TVariables>;\n\nexport function useLoadableQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: LoadableQueryHookOptions\n): UseLoadableQueryResult<TData, TVariables>;\n\nexport function useLoadableQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: LoadableQueryHookOptions = Object.create(null)\n): UseLoadableQueryResult<TData, TVariables> {\n const client = useApolloClient(options.client);\n const suspenseCache = getSuspenseCache(client);\n const watchQueryOptions = useWatchQueryOptions({ client, query, options });\n const { queryKey = [] } = options;\n\n const [queryRef, setQueryRef] = React.useState<QueryReference<\n TData,\n TVariables\n > | null>(null);\n\n const internalQueryRef = queryRef && unwrapQueryRef(queryRef);\n\n if (queryRef && internalQueryRef?.didChangeOptions(watchQueryOptions)) {\n const promise = internalQueryRef.applyOptions(watchQueryOptions);\n updateWrappedQueryRef(queryRef, promise);\n }\n\n const calledDuringRender = useRenderGuard();\n\n React.useEffect(() => internalQueryRef?.retain(), [internalQueryRef]);\n\n const fetchMore: FetchMoreFunction<TData, TVariables> = React.useCallback(\n (options) => {\n if (!internalQueryRef) {\n throw new Error(\n \"The query has not been loaded. Please load the query.\"\n );\n }\n\n const promise = internalQueryRef.fetchMore(\n options as FetchMoreQueryOptions<TVariables, TData>\n );\n\n setQueryRef(wrapQueryRef(internalQueryRef));\n\n return promise;\n },\n [internalQueryRef]\n );\n\n const refetch: RefetchFunction<TData, TVariables> = React.useCallback(\n (options) => {\n if (!internalQueryRef) {\n throw new Error(\n \"The query has not been loaded. Please load the query.\"\n );\n }\n\n const promise = internalQueryRef.refetch(options);\n\n setQueryRef(wrapQueryRef(internalQueryRef));\n\n return promise;\n },\n [internalQueryRef]\n );\n\n const loadQuery: LoadQueryFunction<TVariables> = React.useCallback(\n (...args) => {\n invariant(\n !calledDuringRender(),\n \"useLoadableQuery: 'loadQuery' should not be called during render. To start a query during render, use the 'useBackgroundQuery' hook.\"\n );\n\n const [variables] = args;\n\n const cacheKey: CacheKey = [\n query,\n canonicalStringify(variables),\n ...([] as any[]).concat(queryKey),\n ];\n\n const queryRef = suspenseCache.getQueryRef(cacheKey, () =>\n client.watchQuery({\n ...watchQueryOptions,\n variables,\n } as WatchQueryOptions<any, any>)\n );\n\n setQueryRef(wrapQueryRef(queryRef));\n },\n [query, queryKey, suspenseCache, watchQueryOptions, calledDuringRender]\n );\n\n const reset: ResetFunction = React.useCallback(() => {\n setQueryRef(null);\n }, [queryRef]);\n\n return [loadQuery, queryRef, { fetchMore, refetch, reset }];\n}\n"]}
@@ -21,6 +21,8 @@ export function useMutation(mutation, options) {
21
21
  mutation: mutation,
22
22
  options: options,
23
23
  });
24
+ // TODO: Trying to assign these in a useEffect or useLayoutEffect breaks
25
+ // higher-order components.
24
26
  {
25
27
  Object.assign(ref.current, { client: client, options: options, mutation: mutation });
26
28
  }
@@ -47,8 +49,8 @@ export function useMutation(mutation, options) {
47
49
  .then(function (response) {
48
50
  var _a, _b;
49
51
  var data = response.data, errors = response.errors;
50
- var error = errors && errors.length > 0
51
- ? new ApolloError({ graphQLErrors: errors })
52
+ var error = errors && errors.length > 0 ?
53
+ new ApolloError({ graphQLErrors: errors })
52
54
  : void 0;
53
55
  var onError = executeOptions.onError || ((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError);
54
56
  if (error && onError) {
@@ -90,6 +92,7 @@ export function useMutation(mutation, options) {
90
92
  var onError = executeOptions.onError || ((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError);
91
93
  if (onError) {
92
94
  onError(error, clientOptions);
95
+ // TODO(brian): why are we returning this here???
93
96
  return { data: void 0, errors: error };
94
97
  }
95
98
  throw error;
@@ -97,7 +100,9 @@ export function useMutation(mutation, options) {
97
100
  }, []);
98
101
  var reset = React.useCallback(function () {
99
102
  if (ref.current.isMounted) {
100
- setResult({ called: false, loading: false, client: client });
103
+ var result_3 = { called: false, loading: false, client: client };
104
+ Object.assign(ref.current, { mutationId: 0, result: result_3 });
105
+ setResult(result_3);
101
106
  }
102
107
  }, []);
103
108
  React.useEffect(function () {
@@ -1 +1 @@
1
- {"version":3,"file":"useMutation.js","sourceRoot":"","sources":["../../../src/react/hooks/useMutation.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAgBjC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,UAAU,WAAW,CAMzB,QAA6D,EAC7D,OAKC;IAED,IAAM,MAAM,GAAG,eAAe,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,CAAC,CAAC;IAChD,kBAAkB,CAAC,QAAQ,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC;IAC9C,IAAA,KAAsB,KAAK,CAAC,QAAQ,CAAgC;QACxE,MAAM,EAAE,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ACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CAAC,OAAO,aAAI,KAAK,OAAA,IAAK,MAAM,EAAG,CAAC;AACzC,CAAC","sourcesContent":["import * as React from \"rehackt\";\nimport type { DocumentNode } from \"graphql\";\nimport type { TypedDocumentNode } from \"@graphql-typed-document-node/core\";\nimport type {\n MutationFunctionOptions,\n MutationHookOptions,\n MutationResult,\n MutationTuple,\n NoInfer,\n} from \"../types/types.js\";\n\nimport type {\n ApolloCache,\n DefaultContext,\n OperationVariables,\n} from \"../../core/index.js\";\nimport { mergeOptions } from \"../../utilities/index.js\";\nimport { equal } from \"@wry/equality\";\nimport { DocumentType, verifyDocumentType } from \"../parser/index.js\";\nimport { ApolloError } from \"../../errors/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\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<\n NoInfer<TData>,\n NoInfer<TVariables>,\n TContext,\n TCache\n >\n): MutationTuple<TData, TVariables, TContext, TCache> {\n const client = useApolloClient(options?.client);\n verifyDocumentType(mutation, DocumentType.Mutation);\n const [result, setResult] = React.useState<Omit<MutationResult, \"reset\">>({\n called: false,\n loading: false,\n client,\n });\n\n const ref = React.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 = React.useCallback(\n (\n executeOptions: MutationFunctionOptions<\n TData,\n TVariables,\n TContext,\n TCache\n > = {}\n ) => {\n const { options, mutation } = ref.current;\n const baseOptions = { ...options, mutation };\n const client = executeOptions.client || ref.current.client;\n\n if (\n !ref.current.result.loading &&\n !baseOptions.ignoreResults &&\n ref.current.isMounted\n ) {\n setResult(\n (ref.current.result = {\n loading: true,\n error: void 0,\n data: void 0,\n called: true,\n client,\n })\n );\n }\n\n const mutationId = ++ref.current.mutationId;\n const clientOptions = mergeOptions(baseOptions, executeOptions as any);\n\n return client\n .mutate(clientOptions)\n .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 const onError =\n executeOptions.onError || ref.current.options?.onError;\n\n if (error && onError) {\n onError(error, clientOptions);\n }\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 =\n executeOptions.onCompleted || ref.current.options?.onCompleted;\n\n if (!error) {\n onCompleted?.(response.data!, clientOptions);\n }\n\n return response;\n })\n .catch((error) => {\n if (mutationId === ref.current.mutationId && ref.current.isMounted) {\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 =\n 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 );\n\n const reset = React.useCallback(() => {\n if (ref.current.isMounted) {\n setResult({ called: false, loading: false, client });\n }\n }, []);\n\n React.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,KAAK,KAAK,MAAM,SAAS,CAAC;AAiBjC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,E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gBACjD,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;YACzC,CAAC;YAED,MAAM,KAAK,CAAC;QACd,CAAC,CAAC,CAAC;IACP,CAAC,EACD,EAAE,CACH,CAAC;IAEF,IAAM,KAAK,GAAG,KAAK,CAAC,WAAW,CAAC;QAC9B,IAAI,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;YAC1B,IAAM,QAAM,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,QAAA,EAAE,CAAC;YACzD,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,UAAA,EAAE,CAAC,CAAC;YACtD,SAAS,CAAC,QAAM,CAAC,CAAC;QACpB,CAAC;IACH,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,KAAK,CAAC,SAAS,CAAC;QACd,GAAG,CAAC,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;QAE7B,OAAO;YACL,GAAG,CAAC,OAAO,CAAC,SAAS,GAAG,KAAK,CAAC;QAChC,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CAAC,OAAO,aAAI,KAAK,OAAA,IAAK,MAAM,EAAG,CAAC;AACzC,CAAC","sourcesContent":["import * as React from \"rehackt\";\nimport type { DocumentNode } from \"graphql\";\nimport type { TypedDocumentNode } from \"@graphql-typed-document-node/core\";\nimport type {\n MutationFunctionOptions,\n MutationHookOptions,\n MutationResult,\n MutationTuple,\n NoInfer,\n} from \"../types/types.js\";\n\nimport type {\n ApolloCache,\n DefaultContext,\n MutationOptions,\n OperationVariables,\n} from \"../../core/index.js\";\nimport { mergeOptions } from \"../../utilities/index.js\";\nimport { equal } from \"@wry/equality\";\nimport { DocumentType, verifyDocumentType } from \"../parser/index.js\";\nimport { ApolloError } from \"../../errors/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\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<\n NoInfer<TData>,\n NoInfer<TVariables>,\n TContext,\n TCache\n >\n): MutationTuple<TData, TVariables, TContext, TCache> {\n const client = useApolloClient(options?.client);\n verifyDocumentType(mutation, DocumentType.Mutation);\n const [result, setResult] = React.useState<Omit<MutationResult, \"reset\">>({\n called: false,\n loading: false,\n client,\n });\n\n const ref = React.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 = React.useCallback(\n (\n executeOptions: MutationFunctionOptions<\n TData,\n TVariables,\n TContext,\n TCache\n > = {}\n ) => {\n const { options, mutation } = ref.current;\n const baseOptions = { ...options, mutation };\n const client = executeOptions.client || ref.current.client;\n\n if (\n !ref.current.result.loading &&\n !baseOptions.ignoreResults &&\n ref.current.isMounted\n ) {\n setResult(\n (ref.current.result = {\n loading: true,\n error: void 0,\n data: void 0,\n called: true,\n client,\n })\n );\n }\n\n const mutationId = ++ref.current.mutationId;\n const clientOptions = mergeOptions(baseOptions, executeOptions);\n\n return client\n .mutate(clientOptions as MutationOptions<TData, OperationVariables>)\n .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 const onError =\n executeOptions.onError || ref.current.options?.onError;\n\n if (error && onError) {\n onError(\n error,\n clientOptions as MutationOptions<TData, OperationVariables>\n );\n }\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 =\n executeOptions.onCompleted || ref.current.options?.onCompleted;\n\n if (!error) {\n onCompleted?.(\n response.data!,\n clientOptions as MutationOptions<TData, OperationVariables>\n );\n }\n\n return response;\n })\n .catch((error) => {\n if (mutationId === ref.current.mutationId && ref.current.isMounted) {\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 =\n executeOptions.onError || ref.current.options?.onError;\n\n if (onError) {\n onError(\n error,\n clientOptions as MutationOptions<TData, OperationVariables>\n );\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 );\n\n const reset = React.useCallback(() => {\n if (ref.current.isMounted) {\n const result = { called: false, loading: false, client };\n Object.assign(ref.current, { mutationId: 0, result });\n setResult(result);\n }\n }, []);\n\n React.useEffect(() => {\n ref.current.isMounted = true;\n\n return () => {\n ref.current.isMounted = false;\n };\n }, []);\n\n return [execute, { reset, ...result }];\n}\n"]}
@@ -8,7 +8,18 @@ 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
+ /**
12
+ * Forces an update using local component state.
13
+ * As this is not batched with `useSyncExternalStore` updates,
14
+ * this is only used as a fallback if the `useSyncExternalStore` "force update"
15
+ * method is not registered at the moment.
16
+ * See https://github.com/facebook/react/issues/25191
17
+ * */
11
18
  forceUpdateState(): void;
19
+ /**
20
+ * Will be overwritten by the `useSyncExternalStore` "force update" method
21
+ * whenever it is available and reset to `forceUpdateState` when it isn't.
22
+ */
12
23
  forceUpdate: () => void;
13
24
  executeQuery(options: QueryHookOptions<TData, TVariables> & {
14
25
  query?: DocumentNode;