@apollo/client 3.4.17 → 3.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (421) hide show
  1. package/README.md +1 -1
  2. package/{apollo-client.cjs.js → apollo-client.cjs} +1219 -1280
  3. package/apollo-client.cjs.map +1 -0
  4. package/apollo-client.min.cjs +1 -0
  5. package/cache/{cache.cjs.js → cache.cjs} +757 -601
  6. package/cache/cache.cjs.map +1 -0
  7. package/cache/core/cache.d.ts +6 -4
  8. package/cache/core/cache.d.ts.map +1 -1
  9. package/cache/core/cache.js +28 -1
  10. package/cache/core/cache.js.map +1 -1
  11. package/cache/core/types/Cache.d.ts +12 -10
  12. package/cache/core/types/Cache.d.ts.map +1 -1
  13. package/cache/core/types/Cache.js.map +1 -1
  14. package/cache/core/types/DataProxy.d.ts +4 -0
  15. package/cache/core/types/DataProxy.d.ts.map +1 -1
  16. package/cache/core/types/DataProxy.js.map +1 -1
  17. package/cache/core/types/common.d.ts +8 -5
  18. package/cache/core/types/common.d.ts.map +1 -1
  19. package/cache/core/types/common.js +6 -11
  20. package/cache/core/types/common.js.map +1 -1
  21. package/cache/inmemory/helpers.js +1 -1
  22. package/cache/inmemory/helpers.js.map +1 -1
  23. package/cache/inmemory/inMemoryCache.d.ts +4 -4
  24. package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
  25. package/cache/inmemory/inMemoryCache.js +12 -3
  26. package/cache/inmemory/inMemoryCache.js.map +1 -1
  27. package/cache/inmemory/key-extractor.d.ts +9 -0
  28. package/cache/inmemory/key-extractor.d.ts.map +1 -0
  29. package/cache/inmemory/key-extractor.js +118 -0
  30. package/cache/inmemory/key-extractor.js.map +1 -0
  31. package/cache/inmemory/policies.d.ts +7 -3
  32. package/cache/inmemory/policies.d.ts.map +1 -1
  33. package/cache/inmemory/policies.js +47 -118
  34. package/cache/inmemory/policies.js.map +1 -1
  35. package/cache/inmemory/readFromStore.d.ts +2 -2
  36. package/cache/inmemory/readFromStore.d.ts.map +1 -1
  37. package/cache/inmemory/readFromStore.js +54 -42
  38. package/cache/inmemory/readFromStore.js.map +1 -1
  39. package/cache/inmemory/writeToStore.d.ts +8 -3
  40. package/cache/inmemory/writeToStore.d.ts.map +1 -1
  41. package/cache/inmemory/writeToStore.js +166 -95
  42. package/cache/inmemory/writeToStore.js.map +1 -1
  43. package/cache/package.json +2 -1
  44. package/core/ApolloClient.d.ts +0 -1
  45. package/core/ApolloClient.d.ts.map +1 -1
  46. package/core/ApolloClient.js +3 -3
  47. package/core/ApolloClient.js.map +1 -1
  48. package/core/LocalState.js +1 -1
  49. package/core/LocalState.js.map +1 -1
  50. package/core/ObservableQuery.d.ts +2 -2
  51. package/core/ObservableQuery.d.ts.map +1 -1
  52. package/core/ObservableQuery.js +19 -14
  53. package/core/ObservableQuery.js.map +1 -1
  54. package/core/QueryInfo.d.ts +2 -2
  55. package/core/QueryInfo.d.ts.map +1 -1
  56. package/core/QueryInfo.js.map +1 -1
  57. package/core/QueryManager.d.ts +0 -1
  58. package/core/QueryManager.d.ts.map +1 -1
  59. package/core/QueryManager.js +10 -10
  60. package/core/QueryManager.js.map +1 -1
  61. package/core/{core.cjs.js → core.cjs} +38 -34
  62. package/core/core.cjs.map +1 -0
  63. package/core/package.json +2 -1
  64. package/errors/{errors.cjs.js → errors.cjs} +3 -3
  65. package/errors/errors.cjs.map +1 -0
  66. package/errors/index.d.ts +3 -1
  67. package/errors/index.d.ts.map +1 -1
  68. package/errors/index.js +2 -2
  69. package/errors/index.js.map +1 -1
  70. package/errors/package.json +2 -1
  71. package/invariantErrorCodes.js +84 -104
  72. package/link/batch/{batch.cjs.js → batch.cjs} +2 -2
  73. package/link/batch/batch.cjs.map +1 -0
  74. package/link/batch/batchLink.d.ts +0 -1
  75. package/link/batch/batchLink.d.ts.map +1 -1
  76. package/link/batch/batching.d.ts +0 -1
  77. package/link/batch/batching.d.ts.map +1 -1
  78. package/link/batch/batching.js +1 -1
  79. package/link/batch/batching.js.map +1 -1
  80. package/link/batch/package.json +2 -1
  81. package/link/batch-http/{batch-http.cjs.js → batch-http.cjs} +3 -3
  82. package/link/batch-http/batch-http.cjs.map +1 -0
  83. package/link/batch-http/batchHttpLink.d.ts +0 -1
  84. package/link/batch-http/batchHttpLink.d.ts.map +1 -1
  85. package/link/batch-http/batchHttpLink.js +3 -3
  86. package/link/batch-http/batchHttpLink.js.map +1 -1
  87. package/link/batch-http/package.json +2 -1
  88. package/link/context/{context.cjs.js → context.cjs} +1 -1
  89. package/link/context/context.cjs.map +1 -0
  90. package/link/context/index.js.map +1 -1
  91. package/link/context/package.json +2 -1
  92. package/link/core/ApolloLink.d.ts +2 -3
  93. package/link/core/ApolloLink.d.ts.map +1 -1
  94. package/link/core/ApolloLink.js +1 -1
  95. package/link/core/ApolloLink.js.map +1 -1
  96. package/link/core/{core.cjs.js → core.cjs} +2 -2
  97. package/link/core/core.cjs.map +1 -0
  98. package/link/core/package.json +2 -1
  99. package/link/core/types.d.ts +4 -7
  100. package/link/core/types.d.ts.map +1 -1
  101. package/link/core/types.js.map +1 -1
  102. package/link/error/{error.cjs.js → error.cjs} +2 -2
  103. package/link/error/error.cjs.map +1 -0
  104. package/link/error/index.d.ts +5 -7
  105. package/link/error/index.d.ts.map +1 -1
  106. package/link/error/index.js +1 -1
  107. package/link/error/index.js.map +1 -1
  108. package/link/error/package.json +2 -1
  109. package/link/http/checkFetcher.js +1 -1
  110. package/link/http/createHttpLink.d.ts.map +1 -1
  111. package/link/http/createHttpLink.js +3 -3
  112. package/link/http/createHttpLink.js.map +1 -1
  113. package/link/http/{http.cjs.js → http.cjs} +28 -15
  114. package/link/http/http.cjs.map +1 -0
  115. package/link/http/index.d.ts +1 -1
  116. package/link/http/index.d.ts.map +1 -1
  117. package/link/http/index.js +1 -1
  118. package/link/http/index.js.map +1 -1
  119. package/link/http/package.json +2 -1
  120. package/link/http/parseAndCheckHttpResponse.js +3 -3
  121. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  122. package/link/http/rewriteURIForGET.js +1 -1
  123. package/link/http/rewriteURIForGET.js.map +1 -1
  124. package/link/http/selectHttpOptionsAndBody.d.ts +11 -1
  125. package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
  126. package/link/http/selectHttpOptionsAndBody.js +20 -7
  127. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  128. package/link/http/serializeFetchParameter.js +1 -1
  129. package/link/http/serializeFetchParameter.js.map +1 -1
  130. package/link/persisted-queries/index.d.ts.map +1 -1
  131. package/link/persisted-queries/index.js +3 -3
  132. package/link/persisted-queries/index.js.map +1 -1
  133. package/link/persisted-queries/package.json +2 -1
  134. package/link/persisted-queries/{persisted-queries.cjs.js → persisted-queries.cjs} +3 -3
  135. package/link/persisted-queries/persisted-queries.cjs.map +1 -0
  136. package/link/retry/package.json +2 -1
  137. package/link/retry/{retry.cjs.js → retry.cjs} +1 -1
  138. package/link/retry/retry.cjs.map +1 -0
  139. package/link/retry/retryLink.d.ts +0 -1
  140. package/link/retry/retryLink.d.ts.map +1 -1
  141. package/link/retry/retryLink.js.map +1 -1
  142. package/link/schema/index.d.ts +0 -1
  143. package/link/schema/index.d.ts.map +1 -1
  144. package/link/schema/index.js +8 -1
  145. package/link/schema/index.js.map +1 -1
  146. package/link/schema/package.json +2 -1
  147. package/link/schema/{schema.cjs.js → schema.cjs} +9 -2
  148. package/link/schema/schema.cjs.map +1 -0
  149. package/link/utils/fromError.d.ts +0 -1
  150. package/link/utils/fromError.d.ts.map +1 -1
  151. package/link/utils/fromPromise.d.ts +0 -1
  152. package/link/utils/fromPromise.d.ts.map +1 -1
  153. package/link/utils/package.json +2 -1
  154. package/link/utils/toPromise.d.ts +0 -1
  155. package/link/utils/toPromise.d.ts.map +1 -1
  156. package/link/utils/{utils.cjs.js → utils.cjs} +2 -2
  157. package/link/utils/utils.cjs.map +1 -0
  158. package/link/utils/validateOperation.js +1 -1
  159. package/link/utils/validateOperation.js.map +1 -1
  160. package/link/ws/index.d.ts +0 -1
  161. package/link/ws/index.d.ts.map +1 -1
  162. package/link/ws/package.json +2 -1
  163. package/link/ws/{ws.cjs.js → ws.cjs} +1 -1
  164. package/link/ws/ws.cjs.map +1 -0
  165. package/{main.cjs.js → main.cjs} +5 -5
  166. package/main.cjs.map +1 -0
  167. package/package.json +20 -19
  168. package/react/components/Query.js.map +1 -1
  169. package/react/components/{components.cjs.js → components.cjs} +4 -4
  170. package/react/components/components.cjs.map +1 -0
  171. package/react/components/package.json +2 -1
  172. package/react/context/ApolloConsumer.js +1 -1
  173. package/react/context/ApolloProvider.js +1 -1
  174. package/react/context/{context.cjs.js → context.cjs} +6 -6
  175. package/react/context/context.cjs.map +1 -0
  176. package/react/context/index.d.ts +3 -3
  177. package/react/context/index.d.ts.map +1 -1
  178. package/react/context/index.js +3 -3
  179. package/react/context/index.js.map +1 -1
  180. package/react/context/package.json +2 -1
  181. package/react/hoc/hoc-utils.js +1 -1
  182. package/react/hoc/{hoc.cjs.js → hoc.cjs} +12 -12
  183. package/react/hoc/hoc.cjs.map +1 -0
  184. package/react/hoc/mutation-hoc.js +2 -2
  185. package/react/hoc/mutation-hoc.js.map +1 -1
  186. package/react/hoc/package.json +2 -1
  187. package/react/hoc/query-hoc.js +1 -1
  188. package/react/hoc/query-hoc.js.map +1 -1
  189. package/react/hoc/subscription-hoc.js +1 -1
  190. package/react/hoc/subscription-hoc.js.map +1 -1
  191. package/react/hoc/withApollo.js +2 -2
  192. package/react/hoc/withApollo.js.map +1 -1
  193. package/react/hooks/hooks.cjs +502 -0
  194. package/react/hooks/hooks.cjs.map +1 -0
  195. package/react/hooks/package.json +2 -1
  196. package/react/hooks/useApolloClient.d.ts +1 -1
  197. package/react/hooks/useApolloClient.d.ts.map +1 -1
  198. package/react/hooks/useApolloClient.js +7 -5
  199. package/react/hooks/useApolloClient.js.map +1 -1
  200. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  201. package/react/hooks/useLazyQuery.js +56 -2
  202. package/react/hooks/useLazyQuery.js.map +1 -1
  203. package/react/hooks/useMutation.d.ts.map +1 -1
  204. package/react/hooks/useMutation.js +89 -21
  205. package/react/hooks/useMutation.js.map +1 -1
  206. package/react/hooks/useQuery.d.ts +2 -3
  207. package/react/hooks/useQuery.d.ts.map +1 -1
  208. package/react/hooks/useQuery.js +224 -2
  209. package/react/hooks/useQuery.js.map +1 -1
  210. package/react/hooks/useSubscription.d.ts +2 -7
  211. package/react/hooks/useSubscription.d.ts.map +1 -1
  212. package/react/hooks/useSubscription.js +89 -32
  213. package/react/hooks/useSubscription.js.map +1 -1
  214. package/react/package.json +2 -1
  215. package/react/parser/index.d.ts +1 -0
  216. package/react/parser/index.d.ts.map +1 -1
  217. package/react/parser/index.js +16 -9
  218. package/react/parser/index.js.map +1 -1
  219. package/react/parser/package.json +2 -1
  220. package/react/parser/{parser.cjs.js → parser.cjs} +18 -10
  221. package/react/parser/parser.cjs.map +1 -0
  222. package/react/{react.cjs.js → react.cjs} +3 -3
  223. package/react/react.cjs.map +1 -0
  224. package/react/ssr/RenderPromises.d.ts +7 -3
  225. package/react/ssr/RenderPromises.d.ts.map +1 -1
  226. package/react/ssr/RenderPromises.js.map +1 -1
  227. package/react/ssr/package.json +2 -1
  228. package/react/ssr/{ssr.cjs.js → ssr.cjs} +4 -4
  229. package/react/ssr/ssr.cjs.map +1 -0
  230. package/react/types/types.d.ts +7 -18
  231. package/react/types/types.d.ts.map +1 -1
  232. package/react/types/types.js.map +1 -1
  233. package/testing/{testing.cjs.js → core/core.cjs} +10 -104
  234. package/testing/core/core.cjs.map +1 -0
  235. package/{utilities/testing → testing/core}/index.d.ts +0 -1
  236. package/testing/core/index.d.ts.map +1 -0
  237. package/{utilities/testing → testing/core}/index.js +0 -1
  238. package/testing/core/index.js.map +1 -0
  239. package/{utilities/testing → testing/core}/itAsync.d.ts +0 -0
  240. package/testing/core/itAsync.d.ts.map +1 -0
  241. package/{utilities/testing → testing/core}/itAsync.js +0 -0
  242. package/testing/core/itAsync.js.map +1 -0
  243. package/{utilities/testing → testing/core}/mocking/mockClient.d.ts +0 -0
  244. package/testing/core/mocking/mockClient.d.ts.map +1 -0
  245. package/{utilities/testing → testing/core}/mocking/mockClient.js +0 -0
  246. package/testing/core/mocking/mockClient.js.map +1 -0
  247. package/{utilities/testing → testing/core}/mocking/mockFetch.d.ts +0 -0
  248. package/testing/core/mocking/mockFetch.d.ts.map +1 -0
  249. package/{utilities/testing → testing/core}/mocking/mockFetch.js +1 -1
  250. package/testing/core/mocking/mockFetch.js.map +1 -0
  251. package/{utilities/testing → testing/core}/mocking/mockLink.d.ts +0 -1
  252. package/testing/core/mocking/mockLink.d.ts.map +1 -0
  253. package/{utilities/testing → testing/core}/mocking/mockLink.js +5 -5
  254. package/testing/core/mocking/mockLink.js.map +1 -0
  255. package/{utilities/testing → testing/core}/mocking/mockQueryManager.d.ts +1 -1
  256. package/testing/core/mocking/mockQueryManager.d.ts.map +1 -0
  257. package/{utilities/testing → testing/core}/mocking/mockQueryManager.js +1 -1
  258. package/testing/core/mocking/mockQueryManager.js.map +1 -0
  259. package/{utilities/testing → testing/core}/mocking/mockSubscriptionLink.d.ts +1 -4
  260. package/testing/core/mocking/mockSubscriptionLink.d.ts.map +1 -0
  261. package/{utilities/testing → testing/core}/mocking/mockSubscriptionLink.js +1 -1
  262. package/testing/core/mocking/mockSubscriptionLink.js.map +1 -0
  263. package/{utilities/testing → testing/core}/mocking/mockWatchQuery.d.ts +1 -1
  264. package/testing/core/mocking/mockWatchQuery.d.ts.map +1 -0
  265. package/{utilities/testing → testing/core}/mocking/mockWatchQuery.js +0 -0
  266. package/testing/core/mocking/mockWatchQuery.js.map +1 -0
  267. package/{utilities/testing → testing/core}/observableToPromise.d.ts +2 -3
  268. package/testing/core/observableToPromise.d.ts.map +1 -0
  269. package/{utilities/testing → testing/core}/observableToPromise.js +1 -1
  270. package/testing/core/observableToPromise.js.map +1 -0
  271. package/testing/core/package.json +8 -0
  272. package/testing/core/subscribeAndCount.d.ts +4 -0
  273. package/testing/core/subscribeAndCount.d.ts.map +1 -0
  274. package/{utilities/testing → testing/core}/subscribeAndCount.js +1 -1
  275. package/testing/core/subscribeAndCount.js.map +1 -0
  276. package/{utilities/testing → testing/core}/withConsoleSpy.d.ts +0 -0
  277. package/testing/core/withConsoleSpy.d.ts.map +1 -0
  278. package/{utilities/testing → testing/core}/withConsoleSpy.js +0 -0
  279. package/testing/core/withConsoleSpy.js.map +1 -0
  280. package/{utilities/testing → testing/core}/wrap.d.ts +0 -0
  281. package/testing/core/wrap.d.ts.map +1 -0
  282. package/{utilities/testing → testing/core}/wrap.js +0 -0
  283. package/testing/core/wrap.js.map +1 -0
  284. package/testing/index.d.ts +2 -1
  285. package/testing/index.d.ts.map +1 -1
  286. package/testing/index.js +2 -1
  287. package/testing/index.js.map +1 -1
  288. package/testing/package.json +2 -1
  289. package/{utilities/testing/mocking → testing/react}/MockedProvider.d.ts +5 -5
  290. package/testing/react/MockedProvider.d.ts.map +1 -0
  291. package/{utilities/testing/mocking → testing/react}/MockedProvider.js +4 -4
  292. package/testing/react/MockedProvider.js.map +1 -0
  293. package/testing/testing.cjs +58 -0
  294. package/testing/testing.cjs.map +1 -0
  295. package/utilities/common/errorHandling.d.ts +1 -1
  296. package/utilities/common/errorHandling.d.ts.map +1 -1
  297. package/utilities/common/errorHandling.js.map +1 -1
  298. package/utilities/common/makeUniqueId.js +1 -1
  299. package/utilities/common/makeUniqueId.js.map +1 -1
  300. package/utilities/common/mergeDeep.d.ts.map +1 -1
  301. package/utilities/common/mergeDeep.js +6 -1
  302. package/utilities/common/mergeDeep.js.map +1 -1
  303. package/utilities/globals/fix-graphql.js +1 -1
  304. package/utilities/globals/global.d.ts.map +1 -1
  305. package/utilities/globals/global.js +1 -1
  306. package/utilities/globals/global.js.map +1 -1
  307. package/utilities/globals/{globals.cjs.js → globals.cjs} +3 -3
  308. package/utilities/globals/globals.cjs.map +1 -0
  309. package/utilities/globals/index.js +1 -1
  310. package/utilities/globals/package.json +2 -1
  311. package/utilities/graphql/directives.js +5 -5
  312. package/utilities/graphql/directives.js.map +1 -1
  313. package/utilities/graphql/fragments.d.ts.map +1 -1
  314. package/utilities/graphql/fragments.js +4 -4
  315. package/utilities/graphql/fragments.js.map +1 -1
  316. package/utilities/graphql/getFromAST.js +8 -8
  317. package/utilities/graphql/getFromAST.js.map +1 -1
  318. package/utilities/graphql/storeUtils.js +6 -6
  319. package/utilities/graphql/storeUtils.js.map +1 -1
  320. package/utilities/graphql/transform.d.ts.map +1 -1
  321. package/utilities/graphql/transform.js.map +1 -1
  322. package/utilities/observables/Concast.d.ts +0 -1
  323. package/utilities/observables/Concast.d.ts.map +1 -1
  324. package/utilities/observables/asyncMap.d.ts +0 -1
  325. package/utilities/observables/asyncMap.d.ts.map +1 -1
  326. package/utilities/observables/subclassing.d.ts +0 -1
  327. package/utilities/observables/subclassing.d.ts.map +1 -1
  328. package/utilities/package.json +2 -1
  329. package/utilities/{utilities.cjs.js → utilities.cjs} +31 -26
  330. package/utilities/utilities.cjs.map +1 -0
  331. package/version.js +1 -1
  332. package/apollo-client.cjs.js.map +0 -1
  333. package/apollo-client.cjs.min.js +0 -1
  334. package/cache/cache.cjs.js.map +0 -1
  335. package/core/core.cjs.js.map +0 -1
  336. package/errors/errors.cjs.js.map +0 -1
  337. package/link/batch/batch.cjs.js.map +0 -1
  338. package/link/batch-http/batch-http.cjs.js.map +0 -1
  339. package/link/context/context.cjs.js.map +0 -1
  340. package/link/core/core.cjs.js.map +0 -1
  341. package/link/error/error.cjs.js.map +0 -1
  342. package/link/http/http.cjs.js.map +0 -1
  343. package/link/persisted-queries/persisted-queries.cjs.js.map +0 -1
  344. package/link/retry/retry.cjs.js.map +0 -1
  345. package/link/schema/schema.cjs.js.map +0 -1
  346. package/link/utils/utils.cjs.js.map +0 -1
  347. package/link/ws/ws.cjs.js.map +0 -1
  348. package/main.cjs.js.map +0 -1
  349. package/react/components/components.cjs.js.map +0 -1
  350. package/react/context/context.cjs.js.map +0 -1
  351. package/react/data/MutationData.d.ts +0 -29
  352. package/react/data/MutationData.d.ts.map +0 -1
  353. package/react/data/MutationData.js +0 -115
  354. package/react/data/MutationData.js.map +0 -1
  355. package/react/data/OperationData.d.ts +0 -24
  356. package/react/data/OperationData.d.ts.map +0 -1
  357. package/react/data/OperationData.js +0 -53
  358. package/react/data/OperationData.js.map +0 -1
  359. package/react/data/QueryData.d.ts +0 -44
  360. package/react/data/QueryData.d.ts.map +0 -1
  361. package/react/data/QueryData.js +0 -298
  362. package/react/data/QueryData.js.map +0 -1
  363. package/react/data/SubscriptionData.d.ts +0 -28
  364. package/react/data/SubscriptionData.d.ts.map +0 -1
  365. package/react/data/SubscriptionData.js +0 -122
  366. package/react/data/SubscriptionData.js.map +0 -1
  367. package/react/data/data.cjs.js +0 -581
  368. package/react/data/data.cjs.js.map +0 -1
  369. package/react/data/index.d.ts +0 -6
  370. package/react/data/index.d.ts.map +0 -1
  371. package/react/data/index.js +0 -6
  372. package/react/data/index.js.map +0 -1
  373. package/react/data/package.json +0 -7
  374. package/react/hoc/hoc.cjs.js.map +0 -1
  375. package/react/hooks/hooks.cjs.js +0 -195
  376. package/react/hooks/hooks.cjs.js.map +0 -1
  377. package/react/hooks/utils/useAfterFastRefresh.d.ts +0 -3
  378. package/react/hooks/utils/useAfterFastRefresh.d.ts.map +0 -1
  379. package/react/hooks/utils/useAfterFastRefresh.js +0 -19
  380. package/react/hooks/utils/useAfterFastRefresh.js.map +0 -1
  381. package/react/hooks/utils/useBaseQuery.d.ts +0 -7
  382. package/react/hooks/utils/useBaseQuery.d.ts.map +0 -1
  383. package/react/hooks/utils/useBaseQuery.js +0 -55
  384. package/react/hooks/utils/useBaseQuery.js.map +0 -1
  385. package/react/hooks/utils/useDeepMemo.d.ts +0 -2
  386. package/react/hooks/utils/useDeepMemo.d.ts.map +0 -1
  387. package/react/hooks/utils/useDeepMemo.js +0 -10
  388. package/react/hooks/utils/useDeepMemo.js.map +0 -1
  389. package/react/parser/parser.cjs.js.map +0 -1
  390. package/react/react.cjs.js.map +0 -1
  391. package/react/ssr/ssr.cjs.js.map +0 -1
  392. package/testing/testing.cjs.js.map +0 -1
  393. package/utilities/globals/globals.cjs.js.map +0 -1
  394. package/utilities/testing/index.d.ts.map +0 -1
  395. package/utilities/testing/index.js.map +0 -1
  396. package/utilities/testing/itAsync.d.ts.map +0 -1
  397. package/utilities/testing/itAsync.js.map +0 -1
  398. package/utilities/testing/mocking/MockedProvider.d.ts.map +0 -1
  399. package/utilities/testing/mocking/MockedProvider.js.map +0 -1
  400. package/utilities/testing/mocking/mockClient.d.ts.map +0 -1
  401. package/utilities/testing/mocking/mockClient.js.map +0 -1
  402. package/utilities/testing/mocking/mockFetch.d.ts.map +0 -1
  403. package/utilities/testing/mocking/mockFetch.js.map +0 -1
  404. package/utilities/testing/mocking/mockLink.d.ts.map +0 -1
  405. package/utilities/testing/mocking/mockLink.js.map +0 -1
  406. package/utilities/testing/mocking/mockQueryManager.d.ts.map +0 -1
  407. package/utilities/testing/mocking/mockQueryManager.js.map +0 -1
  408. package/utilities/testing/mocking/mockSubscriptionLink.d.ts.map +0 -1
  409. package/utilities/testing/mocking/mockSubscriptionLink.js.map +0 -1
  410. package/utilities/testing/mocking/mockWatchQuery.d.ts.map +0 -1
  411. package/utilities/testing/mocking/mockWatchQuery.js.map +0 -1
  412. package/utilities/testing/observableToPromise.d.ts.map +0 -1
  413. package/utilities/testing/observableToPromise.js.map +0 -1
  414. package/utilities/testing/subscribeAndCount.d.ts +0 -5
  415. package/utilities/testing/subscribeAndCount.d.ts.map +0 -1
  416. package/utilities/testing/subscribeAndCount.js.map +0 -1
  417. package/utilities/testing/withConsoleSpy.d.ts.map +0 -1
  418. package/utilities/testing/withConsoleSpy.js.map +0 -1
  419. package/utilities/testing/wrap.d.ts.map +0 -1
  420. package/utilities/testing/wrap.js.map +0 -1
  421. package/utilities/utilities.cjs.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"useApolloClient.js","sourceRoot":"","sources":["../../../src/react/hooks/useApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,UAAU,eAAe;IACrB,IAAA,MAAM,GAAK,KAAK,CAAC,UAAU,CAAC,gBAAgB,EAAE,CAAC,OAAzC,CAA0C;IACxD,SAAS,CACP,MAAM,EACN,iEAAiE;QAC/D,sDAAsD,CACzD,CAAC;IACF,OAAO,MAAO,CAAC;AACjB,CAAC","sourcesContent":["import { invariant } from '../../utilities/globals';\n\nimport * as React from 'react';\n\nimport { ApolloClient } from '../../core';\nimport { getApolloContext } from '../context';\n\nexport function useApolloClient(): ApolloClient<object> {\n const { client } = React.useContext(getApolloContext());\n invariant(\n client,\n 'No Apollo Client instance can be found. Please ensure that you ' +\n 'have called `ApolloProvider` higher up in your tree.'\n );\n return client!;\n}\n"]}
1
+ {"version":3,"file":"useApolloClient.js","sourceRoot":"","sources":["../../../src/react/hooks/useApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAEnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,UAAU,eAAe,CAC7B,QAA+B;IAE/B,IAAM,OAAO,GAAG,UAAU,CAAC,gBAAgB,EAAE,CAAC,CAAC;IAC/C,IAAM,MAAM,GAAG,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC;IAC1C,SAAS,CACP,CAAC,CAAC,MAAM,EACR,oEAAoE;QACpE,yEAAyE;QACzE,uCAAuC,CACxC,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { invariant } from '../../utilities/globals';\nimport { useContext } from 'react';\nimport { ApolloClient } from '../../core';\nimport { getApolloContext } from '../context';\n\nexport function useApolloClient(\n override?: ApolloClient<object>,\n): ApolloClient<object> {\n const context = useContext(getApolloContext());\n const client = override || context.client;\n invariant(\n !!client,\n 'Could not find \"client\" in the context or passed in as an option. ' +\n 'Wrap the root component in an <ApolloProvider>, or pass an ApolloClient' +\n 'ApolloClient instance in via options.',\n );\n\n return client;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"useLazyQuery.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useLazyQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAEtE,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAElE,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEhD,wBAAgB,YAAY,CAAC,KAAK,GAAG,GAAG,EAAE,UAAU,GAAG,kBAAkB,EACvE,KAAK,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,EAC1D,OAAO,CAAC,EAAE,oBAAoB,CAAC,KAAK,EAAE,UAAU,CAAC,iCAMlD"}
1
+ {"version":3,"file":"useLazyQuery.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useLazyQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAGtE,OAAO,EACL,oBAAoB,EAGpB,UAAU,EACX,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAYhD,wBAAgB,YAAY,CAAC,KAAK,GAAG,GAAG,EAAE,UAAU,GAAG,kBAAkB,EACvE,KAAK,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,EAC1D,OAAO,CAAC,EAAE,oBAAoB,CAAC,KAAK,EAAE,UAAU,CAAC,GAChD,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,CAwE/B"}
@@ -1,5 +1,59 @@
1
- import { useBaseQuery } from "./utils/useBaseQuery.js";
1
+ import { __assign, __spreadArray } from "tslib";
2
+ import { useCallback, useEffect, useState } from 'react';
3
+ import { useQuery } from "./useQuery.js";
4
+ var EAGER_METHODS = [
5
+ 'refetch',
6
+ 'fetchMore',
7
+ 'updateQuery',
8
+ 'startPolling',
9
+ 'subscribeToMore',
10
+ ];
2
11
  export function useLazyQuery(query, options) {
3
- return useBaseQuery(query, options, true);
12
+ var _a = useState({
13
+ called: false,
14
+ resolves: [],
15
+ }), execution = _a[0], setExecution = _a[1];
16
+ var execute = useCallback(function (executeOptions) {
17
+ var resolve;
18
+ var promise = new Promise(function (resolve1) { return (resolve = resolve1); });
19
+ setExecution(function (execution) {
20
+ if (execution.called) {
21
+ result && result.refetch(executeOptions === null || executeOptions === void 0 ? void 0 : executeOptions.variables);
22
+ }
23
+ return {
24
+ called: true,
25
+ resolves: __spreadArray(__spreadArray([], execution.resolves, true), [resolve], false),
26
+ options: executeOptions,
27
+ };
28
+ });
29
+ return promise;
30
+ }, []);
31
+ var result = useQuery(query, __assign(__assign(__assign({}, options), execution.options), { fetchPolicy: execution.called ? options === null || options === void 0 ? void 0 : options.fetchPolicy : 'standby', skip: undefined }));
32
+ useEffect(function () {
33
+ var resolves = execution.resolves;
34
+ if (!result.loading && resolves.length) {
35
+ setExecution(function (execution) { return (__assign(__assign({}, execution), { resolves: [] })); });
36
+ resolves.forEach(function (resolve) { return resolve(result); });
37
+ }
38
+ }, [result, execution]);
39
+ if (!execution.called) {
40
+ result = __assign(__assign({}, result), { loading: false, data: void 0, error: void 0, called: false });
41
+ var _loop_1 = function (key) {
42
+ var method = result[key];
43
+ result[key] = function () {
44
+ var args = [];
45
+ for (var _i = 0; _i < arguments.length; _i++) {
46
+ args[_i] = arguments[_i];
47
+ }
48
+ setExecution(function (execution) { return (__assign(__assign({}, execution), { called: true })); });
49
+ return method.apply(void 0, args);
50
+ };
51
+ };
52
+ for (var _i = 0, EAGER_METHODS_1 = EAGER_METHODS; _i < EAGER_METHODS_1.length; _i++) {
53
+ var key = EAGER_METHODS_1[_i];
54
+ _loop_1(key);
55
+ }
56
+ }
57
+ return [execute, result];
4
58
  }
5
59
  //# sourceMappingURL=useLazyQuery.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useLazyQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useLazyQuery.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGpD,MAAM,UAAU,YAAY,CAC1B,KAA0D,EAC1D,OAAiD;IAEjD,OAAO,YAAY,CAAoB,KAAK,EAAE,OAAO,EAAE,IAAI,CAG1D,CAAC;AACJ,CAAC","sourcesContent":["import { DocumentNode } from 'graphql';\nimport { TypedDocumentNode } from '@graphql-typed-document-node/core';\n\nimport { LazyQueryHookOptions, QueryTuple } from '../types/types';\nimport { useBaseQuery } from './utils/useBaseQuery';\nimport { OperationVariables } from '../../core';\n\nexport function useLazyQuery<TData = any, TVariables = OperationVariables>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: LazyQueryHookOptions<TData, TVariables>\n) {\n return useBaseQuery<TData, TVariables>(query, options, true) as QueryTuple<\n TData,\n TVariables\n >;\n}\n"]}
1
+ {"version":3,"file":"useLazyQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useLazyQuery.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAQzD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAKtC,IAAM,aAAa,GAAG;IACpB,SAAS;IACT,WAAW;IACX,aAAa;IACb,cAAc;IACd,iBAAiB;CACT,CAAC;AAEX,MAAM,UAAU,YAAY,CAC1B,KAA0D,E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C,OAAO,CAAC,UAAC,OAAO,IAAK,OAAA,OAAO,CAAC,MAAM,CAAC,EAAf,CAAe,CAAC,CAAC;SAChD;IACH,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;IAExB,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE;QACrB,MAAM,yBACD,MAAM,KACT,OAAO,EAAE,KAAK,EACd,IAAI,EAAE,KAAK,CAAqB,EAChC,KAAK,EAAE,KAAK,CAAC,EAEb,MAAM,EAAE,KAAY,GACrB,CAAC;gCAGS,GAAG;YACZ,IAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YAC3B,MAAM,CAAC,GAAG,CAAC,GAAG;gBAAC,cAAY;qBAAZ,UAAY,EAAZ,qBAAY,EAAZ,IAAY;oBAAZ,yBAAY;;gBACzB,YAAY,CAAC,UAAC,SAAS,IAAK,OAAA,uBAAM,SAAS,KAAE,MAAM,EAAE,IAAI,IAAG,EAAhC,CAAgC,CAAC,CAAC;gBAC9D,OAAQ,MAAc,eAAI,IAAI,EAAE;YAClC,CAAC,CAAC;;QALJ,KAAkB,UAAa,EAAb,+BAAa,EAAb,2BAAa,EAAb,IAAa;YAA1B,IAAM,GAAG,sBAAA;oBAAH,GAAG;SAMb;KACF;IAGD,OAAO,CAAC,OAAO,EAAE,MAA4C,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import { DocumentNode } from 'graphql';\nimport { TypedDocumentNode } from '@graphql-typed-document-node/core';\nimport { useCallback, useEffect, useState } from 'react';\n\nimport {\n LazyQueryHookOptions,\n LazyQueryResult,\n QueryLazyOptions,\n QueryTuple,\n} from '../types/types';\nimport { useQuery } from './useQuery';\nimport { OperationVariables } from '../../core';\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 'fetchMore',\n 'updateQuery',\n 'startPolling',\n 'subscribeToMore',\n] as const;\n\nexport function useLazyQuery<TData = any, TVariables = OperationVariables>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: LazyQueryHookOptions<TData, TVariables>\n): QueryTuple<TData, TVariables> {\n const [execution, setExecution] = useState<\n {\n called: boolean,\n options?: QueryLazyOptions<TVariables>,\n resolves: Array<(result: LazyQueryResult<TData, TVariables>) => void>,\n }\n >({\n called: false,\n resolves: [],\n });\n\n const execute = useCallback<\n QueryTuple<TData, TVariables>[0]\n >((executeOptions?: QueryLazyOptions<TVariables>) => {\n let resolve!: (result: LazyQueryResult<TData, TVariables>) => void;\n const promise = new Promise<LazyQueryResult<TData, TVariables>>(\n (resolve1) => (resolve = resolve1),\n );\n setExecution((execution) => {\n if (execution.called) {\n result && result.refetch(executeOptions?.variables);\n }\n\n return {\n called: true,\n resolves: [...execution.resolves, resolve],\n options: executeOptions,\n };\n });\n\n return promise;\n }, []);\n\n let result = useQuery<TData, TVariables>(query, {\n ...options,\n ...execution.options,\n // We don’t set skip to execution.called, because we need useQuery to call\n // addQueryPromise, so that ssr calls waits for execute to be called.\n fetchPolicy: execution.called ? options?.fetchPolicy : 'standby',\n skip: undefined,\n });\n useEffect(() => {\n const { resolves } = execution;\n if (!result.loading && resolves.length) {\n setExecution((execution) => ({ ...execution, resolves: [] }));\n resolves.forEach((resolve) => resolve(result));\n }\n }, [result, execution]);\n\n if (!execution.called) {\n result = {\n ...result,\n loading: false,\n data: void 0 as unknown as TData,\n error: void 0,\n // TODO: fix the type of result\n called: false as any,\n };\n\n\n for (const key of EAGER_METHODS) {\n const method = result[key];\n result[key] = (...args: any) => {\n setExecution((execution) => ({ ...execution, called: true }));\n return (method as any)(...args);\n };\n }\n }\n\n // TODO: fix the type of result\n return [execute, result as LazyQueryResult<TData, TVariables>];\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"useMutation.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useMutation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO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KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,CAAC,CAmHpD"}
@@ -1,27 +1,95 @@
1
1
  import { __assign } from "tslib";
2
- import { useContext, useState, useRef, useEffect } from 'react';
3
- import { MutationData } from "../data/index.js";
4
- import { getApolloContext } from "../context/index.js";
2
+ import { useCallback, useEffect, useRef, useState } from 'react';
3
+ import { mergeOptions, } from "../../core/index.js";
4
+ import { equal } from '@wry/equality';
5
+ import { DocumentType, verifyDocumentType } from "../parser/index.js";
6
+ import { ApolloError } from "../../errors/index.js";
7
+ import { useApolloClient } from "./useApolloClient.js";
5
8
  export function useMutation(mutation, options) {
6
- var context = useContext(getApolloContext());
7
- var _a = useState({ called: false, loading: false }), result = _a[0], setResult = _a[1];
8
- var updatedOptions = options ? __assign(__assign({}, options), { mutation: mutation }) : { mutation: mutation };
9
- var mutationDataRef = useRef();
10
- function getMutationDataRef() {
11
- if (!mutationDataRef.current) {
12
- mutationDataRef.current = new MutationData({
13
- options: updatedOptions,
14
- context: context,
15
- result: result,
16
- setResult: setResult
9
+ var client = useApolloClient(options === null || options === void 0 ? void 0 : options.client);
10
+ verifyDocumentType(mutation, DocumentType.Mutation);
11
+ var _a = useState({
12
+ called: false,
13
+ loading: false,
14
+ client: client,
15
+ }), result = _a[0], setResult = _a[1];
16
+ var ref = useRef({
17
+ result: result,
18
+ mutationId: 0,
19
+ isMounted: true,
20
+ client: client,
21
+ mutation: mutation,
22
+ options: options,
23
+ });
24
+ {
25
+ Object.assign(ref.current, { client: client, options: options, mutation: mutation });
26
+ }
27
+ var execute = useCallback(function (executeOptions) {
28
+ if (executeOptions === void 0) { executeOptions = {}; }
29
+ var _a = ref.current, client = _a.client, options = _a.options, mutation = _a.mutation;
30
+ var baseOptions = __assign(__assign({}, options), { mutation: mutation });
31
+ if (!ref.current.result.loading && !baseOptions.ignoreResults) {
32
+ setResult(ref.current.result = {
33
+ loading: true,
34
+ error: void 0,
35
+ data: void 0,
36
+ called: true,
37
+ client: client,
17
38
  });
18
39
  }
19
- return mutationDataRef.current;
20
- }
21
- var mutationData = getMutationDataRef();
22
- mutationData.setOptions(updatedOptions);
23
- mutationData.context = context;
24
- useEffect(function () { return mutationData.afterExecute(); });
25
- return mutationData.execute(result);
40
+ var mutationId = ++ref.current.mutationId;
41
+ var clientOptions = mergeOptions(baseOptions, executeOptions);
42
+ return client.mutate(clientOptions).then(function (response) {
43
+ var _a, _b;
44
+ var data = response.data, errors = response.errors;
45
+ var error = errors && errors.length > 0
46
+ ? new ApolloError({ graphQLErrors: errors })
47
+ : void 0;
48
+ if (mutationId === ref.current.mutationId &&
49
+ !clientOptions.ignoreResults) {
50
+ var result_1 = {
51
+ called: true,
52
+ loading: false,
53
+ data: data,
54
+ error: error,
55
+ client: client,
56
+ };
57
+ if (ref.current.isMounted && !equal(ref.current.result, result_1)) {
58
+ setResult(ref.current.result = result_1);
59
+ }
60
+ }
61
+ (_a = baseOptions.onCompleted) === null || _a === void 0 ? void 0 : _a.call(baseOptions, response.data);
62
+ (_b = executeOptions.onCompleted) === null || _b === void 0 ? void 0 : _b.call(executeOptions, response.data);
63
+ return response;
64
+ }).catch(function (error) {
65
+ var _a, _b;
66
+ if (mutationId === ref.current.mutationId &&
67
+ ref.current.isMounted) {
68
+ var result_2 = {
69
+ loading: false,
70
+ error: error,
71
+ data: void 0,
72
+ called: true,
73
+ client: client,
74
+ };
75
+ if (!equal(ref.current.result, result_2)) {
76
+ setResult(ref.current.result = result_2);
77
+ }
78
+ }
79
+ if (baseOptions.onError || clientOptions.onError) {
80
+ (_a = baseOptions.onError) === null || _a === void 0 ? void 0 : _a.call(baseOptions, error);
81
+ (_b = executeOptions.onError) === null || _b === void 0 ? void 0 : _b.call(executeOptions, error);
82
+ return { data: void 0, errors: error };
83
+ }
84
+ throw error;
85
+ });
86
+ }, []);
87
+ var reset = useCallback(function () {
88
+ setResult({ called: false, loading: false, client: client });
89
+ }, []);
90
+ useEffect(function () { return function () {
91
+ ref.current.isMounted = false;
92
+ }; }, []);
93
+ return [execute, __assign({ reset: reset }, result)];
26
94
  }
27
95
  //# sourceMappingURL=useMutation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useMutation.js","sourceRoot":"","sources":["../../../src/react/hooks/useMutation.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKhE,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,UAAU,WAAW,CAMzB,QAA6D,EAC7D,OAA0D;IAE1D,IAAM,OAAO,GAAG,UAAU,CAAC,gBAAgB,EAAE,CAAC,CAAC;IACzC,IAAA,KAAsB,QAAQ,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,EAAhE,MAAM,QAAA,EAAE,SAAS,QAA+C,CAAC;IACxE,IAAM,cAAc,GAAG,OAAO,CAAC,CAAC,uBAAM,OAAO,KAAE,QAAQ,UAAA,IAAG,CAAC,CAAC,EAAE,QAAQ,UAAA,EAAE,CAAC;IAEzE,IAAM,eAAe,GAAG,MAAM,EAA6C,CAAC;IAC5E,SAAS,kBAAkB;QACzB,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE;YAC5B,eAAe,CAAC,OAAO,GAAG,IAAI,YAAY,CAA8B;gBACtE,OAAO,EAAE,cAAc;gBACvB,OAAO,SAAA;gBACP,MAAM,QAAA;gBACN,SAAS,WAAA;aACV,CAAC,CAAC;SACJ;QACD,OAAO,eAAe,CAAC,OAAO,CAAC;IACjC,CAAC;IAED,IAAM,YAAY,GAAG,kBAAkB,EAAE,CAAC;IAC1C,YAAY,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;IACxC,YAAY,CAAC,OAAO,GAAG,OAAO,CAAC;IAE/B,SAAS,CAAC,cAAM,OAAA,YAAY,CAAC,YAAY,EAAE,EAA3B,CAA2B,CAAC,CAAC;IAE7C,OAAO,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;AACtC,CAAC","sourcesContent":["import { useContext, useState, useRef, useEffect } from 'react';\nimport { DocumentNode } from 'graphql';\nimport { TypedDocumentNode } from '@graphql-typed-document-node/core';\n\nimport { MutationHookOptions, MutationTuple } from '../types/types';\nimport { MutationData } from '../data';\nimport { ApolloCache, DefaultContext, OperationVariables } from '../../core';\nimport { getApolloContext } from '../context';\n\nexport function useMutation<\n TData = any,\n TVariables = OperationVariables,\n TContext = DefaultContext,\n TCache extends ApolloCache<any> = ApolloCache<any>,\n>(\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: MutationHookOptions<TData, TVariables, TContext>\n): MutationTuple<TData, TVariables, TContext, TCache> {\n const context = useContext(getApolloContext());\n const [result, setResult] = useState({ called: false, loading: false });\n const updatedOptions = options ? { ...options, mutation } : { mutation };\n\n const mutationDataRef = useRef<MutationData<TData, TVariables, TContext>>();\n function getMutationDataRef() {\n if (!mutationDataRef.current) {\n mutationDataRef.current = new MutationData<TData, TVariables, TContext>({\n options: updatedOptions,\n context,\n result,\n setResult\n });\n }\n return mutationDataRef.current;\n }\n\n const mutationData = getMutationDataRef();\n mutationData.setOptions(updatedOptions);\n mutationData.context = context;\n\n useEffect(() => mutationData.afterExecute());\n\n return mutationData.execute(result);\n}\n"]}
1
+ {"version":3,"file":"useMutation.js","sourceRoot":"","sources":["../../../src/react/hooks/useMutation.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAUjE,OAAO,EAGL,YAAY,GAEb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,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AAU;gBACrC,GAAG,CAAC,OAAO,CAAC,SAAS,EACrB;gBACA,IAAM,QAAM,GAAG;oBACb,OAAO,EAAE,KAAK;oBACd,KAAK,OAAA;oBACL,IAAI,EAAE,KAAK,CAAC;oBACZ,MAAM,EAAE,IAAI;oBACZ,MAAM,QAAA;iBACP,CAAC;gBAEF,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,QAAM,CAAC,EAAE;oBACtC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,GAAG,QAAM,CAAC,CAAC;iBACxC;aACF;YAED,IAAI,WAAW,CAAC,OAAO,IAAI,aAAa,CAAC,OAAO,EAAE;gBAChD,MAAA,WAAW,CAAC,OAAO,+CAAnB,WAAW,EAAW,KAAK,CAAC,CAAC;gBAC7B,MAAA,cAAc,CAAC,OAAO,+CAAtB,cAAc,EAAW,KAAK,CAAC,CAAC;gBAEhC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;aACxC;YAED,MAAM,KAAK,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,IAAM,KAAK,GAAG,WAAW,CAAC;QACxB,SAAS,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,QAAA,EAAE,CAAC,CAAC;IACvD,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,SAAS,CAAC,cAAM,OAAA;QACd,GAAG,CAAC,OAAO,CAAC,SAAS,GAAG,KAAK,CAAC;IAChC,CAAC,EAFe,CAEf,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CAAC,OAAO,aAAI,KAAK,OAAA,IAAK,MAAM,EAAG,CAAC;AACzC,CAAC","sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\nimport { DocumentNode } from 'graphql';\nimport { TypedDocumentNode } from '@graphql-typed-document-node/core';\nimport {\n MutationFunctionOptions,\n MutationHookOptions,\n MutationResult,\n MutationTuple,\n} from '../types/types';\n\nimport {\n ApolloCache,\n DefaultContext,\n mergeOptions,\n OperationVariables,\n} from '../../core';\nimport { equal } from '@wry/equality';\nimport { DocumentType, verifyDocumentType } from '../parser';\nimport { ApolloError } from '../../errors';\nimport { useApolloClient } from './useApolloClient';\n\nexport function useMutation<\n TData = any,\n TVariables = OperationVariables,\n TContext = DefaultContext,\n TCache extends ApolloCache<any> = ApolloCache<any>,\n>(\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: MutationHookOptions<TData, TVariables, TContext>,\n): MutationTuple<TData, TVariables, TContext, TCache> {\n const client = useApolloClient(options?.client);\n verifyDocumentType(mutation, DocumentType.Mutation);\n const [result, setResult] = useState<Omit<MutationResult, 'reset'>>({\n called: false,\n loading: false,\n client,\n });\n\n const ref = useRef({\n result,\n mutationId: 0,\n isMounted: true,\n client,\n mutation,\n options,\n });\n\n // TODO: Trying to assign these in a useEffect or useLayoutEffect breaks\n // higher-order components.\n {\n Object.assign(ref.current, { client, options, mutation });\n }\n\n const execute = useCallback((\n executeOptions: MutationFunctionOptions<\n TData,\n TVariables,\n TContext,\n TCache\n > = {}\n ) => {\n const {client, options, mutation} = ref.current;\n const baseOptions = { ...options, mutation };\n if (!ref.current.result.loading && !baseOptions.ignoreResults) {\n setResult(ref.current.result = {\n loading: true,\n error: void 0,\n data: void 0,\n called: true,\n client,\n });\n }\n\n const mutationId = ++ref.current.mutationId;\n const clientOptions = mergeOptions(\n baseOptions,\n executeOptions as any,\n );\n\n return client.mutate(clientOptions).then((response) => {\n const { data, errors } = response;\n const error =\n errors && errors.length > 0\n ? new ApolloError({ graphQLErrors: errors })\n : void 0;\n\n if (\n mutationId === ref.current.mutationId &&\n !clientOptions.ignoreResults\n ) {\n const result = {\n called: true,\n loading: false,\n data,\n error,\n client,\n };\n\n if (ref.current.isMounted && !equal(ref.current.result, result)) {\n setResult(ref.current.result = result);\n }\n }\n\n baseOptions.onCompleted?.(response.data!);\n executeOptions.onCompleted?.(response.data!);\n return response;\n }).catch((error) => {\n if (\n mutationId === ref.current.mutationId &&\n ref.current.isMounted\n ) {\n const result = {\n loading: false,\n error,\n data: void 0,\n called: true,\n client,\n };\n\n if (!equal(ref.current.result, result)) {\n setResult(ref.current.result = result);\n }\n }\n\n if (baseOptions.onError || clientOptions.onError) {\n baseOptions.onError?.(error);\n executeOptions.onError?.(error);\n // TODO(brian): why are we returning this here???\n return { data: void 0, errors: error };\n }\n\n throw error;\n });\n }, []);\n\n const reset = useCallback(() => {\n setResult({ called: false, loading: false, client });\n }, []);\n\n useEffect(() => () => {\n ref.current.isMounted = false;\n }, []);\n\n return [execute, { reset, ...result }];\n}\n"]}
@@ -1,6 +1,5 @@
1
- import { DocumentNode } from 'graphql';
2
- import { TypedDocumentNode } from '@graphql-typed-document-node/core';
3
- import { QueryHookOptions, QueryResult } from '../types/types';
4
1
  import { OperationVariables } from '../../core';
2
+ import { DocumentNode, TypedDocumentNode } from '../../core';
3
+ import { QueryHookOptions, QueryResult } from '../types/types';
5
4
  export declare function useQuery<TData = any, TVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: QueryHookOptions<TData, TVariables>): QueryResult<TData, TVariables>;
6
5
  //# sourceMappingURL=useQuery.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useQuery.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAEtE,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEhD,wBAAgB,QAAQ,CAAC,KAAK,GAAG,GAAG,EAAE,UAAU,GAAG,kBAAkB,EACnE,KAAK,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,EAC1D,OAAO,CAAC,EAAE,gBAAgB,CAAC,KAAK,EAAE,UAAU,CAAC,kCAM9C"}
1
+ {"version":3,"file":"useQuery.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useQuery.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAGhD,OAAO,EAIL,YAAY,EACZ,iBAAiB,EAElB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,gBAAgB,EAChB,WAAW,EACZ,MAAM,gBAAgB,CAAC;AAKxB,wBAAgB,QAAQ,CACtB,KAAK,GAAG,GAAG,EACX,UAAU,GAAG,kBAAkB,EAE/B,KAAK,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,EAC1D,OAAO,CAAC,EAAE,gBAAgB,CAAC,KAAK,EAAE,UAAU,CAAC,GAC5C,WAAW,CAAC,KAAK,EAAE,UAAU,CAAC,CAuShC"}
@@ -1,5 +1,227 @@
1
- import { useBaseQuery } from "./utils/useBaseQuery.js";
1
+ import { __assign, __rest } from "tslib";
2
+ import { useContext, useEffect, useMemo, useRef, useState } from 'react';
3
+ import { equal } from '@wry/equality';
4
+ import { getApolloContext } from "../context/index.js";
5
+ import { ApolloError } from "../../errors/index.js";
6
+ import { NetworkStatus, } from "../../core/index.js";
7
+ import { DocumentType, verifyDocumentType } from "../parser/index.js";
8
+ import { useApolloClient } from "./useApolloClient.js";
2
9
  export function useQuery(query, options) {
3
- return useBaseQuery(query, options, false);
10
+ var _a;
11
+ var context = useContext(getApolloContext());
12
+ var client = useApolloClient(options === null || options === void 0 ? void 0 : options.client);
13
+ verifyDocumentType(query, DocumentType.Query);
14
+ var _b = useState(function () {
15
+ var watchQueryOptions = createWatchQueryOptions(query, options);
16
+ var obsQuery = null;
17
+ if (context.renderPromises) {
18
+ obsQuery = context.renderPromises.getSSRObservable(watchQueryOptions);
19
+ }
20
+ if (!obsQuery) {
21
+ obsQuery = client.watchQuery(watchQueryOptions);
22
+ if (context.renderPromises) {
23
+ context.renderPromises.registerSSRObservable(obsQuery, watchQueryOptions);
24
+ }
25
+ }
26
+ if (context.renderPromises &&
27
+ (options === null || options === void 0 ? void 0 : options.ssr) !== false &&
28
+ !(options === null || options === void 0 ? void 0 : options.skip) &&
29
+ obsQuery.getCurrentResult().loading) {
30
+ context.renderPromises.addQueryPromise({
31
+ getOptions: function () { return createWatchQueryOptions(query, options); },
32
+ fetchData: function () { return new Promise(function (resolve) {
33
+ var sub = obsQuery.subscribe({
34
+ next: function (result) {
35
+ if (!result.loading) {
36
+ resolve();
37
+ sub.unsubscribe();
38
+ }
39
+ },
40
+ error: function () {
41
+ resolve();
42
+ sub.unsubscribe();
43
+ },
44
+ complete: function () {
45
+ resolve();
46
+ },
47
+ });
48
+ }); },
49
+ }, function () { return null; });
50
+ }
51
+ return obsQuery;
52
+ }), obsQuery = _b[0], setObsQuery = _b[1];
53
+ var _c = useState(function () {
54
+ var _a, _b;
55
+ var result = obsQuery.getCurrentResult();
56
+ if (!result.loading && options) {
57
+ if (result.error) {
58
+ (_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, result.error);
59
+ }
60
+ else if (result.data) {
61
+ (_b = options.onCompleted) === null || _b === void 0 ? void 0 : _b.call(options, result.data);
62
+ }
63
+ }
64
+ return result;
65
+ }), result = _c[0], setResult = _c[1];
66
+ var ref = useRef({
67
+ client: client,
68
+ query: query,
69
+ options: options,
70
+ result: result,
71
+ previousData: void 0,
72
+ watchQueryOptions: createWatchQueryOptions(query, options),
73
+ });
74
+ useEffect(function () {
75
+ var _a, _b;
76
+ var watchQueryOptions = createWatchQueryOptions(query, options);
77
+ var nextResult;
78
+ if (ref.current.client !== client || !equal(ref.current.query, query)) {
79
+ var obsQuery_1 = client.watchQuery(watchQueryOptions);
80
+ setObsQuery(obsQuery_1);
81
+ nextResult = obsQuery_1.getCurrentResult();
82
+ }
83
+ else if (!equal(ref.current.watchQueryOptions, watchQueryOptions)) {
84
+ obsQuery.setOptions(watchQueryOptions).catch(function () { });
85
+ nextResult = obsQuery.getCurrentResult();
86
+ ref.current.watchQueryOptions = watchQueryOptions;
87
+ }
88
+ if (nextResult) {
89
+ var previousResult = ref.current.result;
90
+ if (previousResult.data) {
91
+ ref.current.previousData = previousResult.data;
92
+ }
93
+ setResult(ref.current.result = nextResult);
94
+ if (!nextResult.loading && options) {
95
+ if (!result.loading) {
96
+ if (result.error) {
97
+ (_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, result.error);
98
+ }
99
+ else if (result.data) {
100
+ (_b = options.onCompleted) === null || _b === void 0 ? void 0 : _b.call(options, result.data);
101
+ }
102
+ }
103
+ }
104
+ }
105
+ Object.assign(ref.current, { client: client, query: query });
106
+ }, [obsQuery, client, query, options]);
107
+ useEffect(function () {
108
+ if (context.renderPromises) {
109
+ return;
110
+ }
111
+ var subscription = obsQuery.subscribe(onNext, onError);
112
+ function onNext() {
113
+ var _a, _b;
114
+ var previousResult = ref.current.result;
115
+ var result = obsQuery.getCurrentResult();
116
+ if (previousResult &&
117
+ previousResult.loading === result.loading &&
118
+ previousResult.networkStatus === result.networkStatus &&
119
+ equal(previousResult.data, result.data)) {
120
+ return;
121
+ }
122
+ if (previousResult.data) {
123
+ ref.current.previousData = previousResult.data;
124
+ }
125
+ setResult(ref.current.result = result);
126
+ if (!result.loading) {
127
+ (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onCompleted) === null || _b === void 0 ? void 0 : _b.call(_a, result.data);
128
+ }
129
+ }
130
+ function onError(error) {
131
+ var _a, _b;
132
+ var last = obsQuery["last"];
133
+ subscription.unsubscribe();
134
+ try {
135
+ obsQuery.resetLastResults();
136
+ subscription = obsQuery.subscribe(onNext, onError);
137
+ }
138
+ finally {
139
+ obsQuery["last"] = last;
140
+ }
141
+ if (!error.hasOwnProperty('graphQLErrors')) {
142
+ throw error;
143
+ }
144
+ var previousResult = ref.current.result;
145
+ if ((previousResult && previousResult.loading) ||
146
+ !equal(error, previousResult.error)) {
147
+ setResult(ref.current.result = {
148
+ data: previousResult.data,
149
+ error: error,
150
+ loading: false,
151
+ networkStatus: NetworkStatus.error,
152
+ });
153
+ (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
154
+ }
155
+ }
156
+ return function () { return subscription.unsubscribe(); };
157
+ }, [obsQuery, context.renderPromises, client.disableNetworkFetches]);
158
+ var partial;
159
+ (_a = result, partial = _a.partial, result = __rest(_a, ["partial"]));
160
+ {
161
+ if (partial &&
162
+ (options === null || options === void 0 ? void 0 : options.partialRefetch) &&
163
+ !result.loading &&
164
+ (!result.data || Object.keys(result.data).length === 0) &&
165
+ obsQuery.options.fetchPolicy !== 'cache-only') {
166
+ result = __assign(__assign({}, result), { loading: true, networkStatus: NetworkStatus.refetch });
167
+ obsQuery.refetch();
168
+ }
169
+ if (context.renderPromises &&
170
+ (options === null || options === void 0 ? void 0 : options.ssr) !== false &&
171
+ !(options === null || options === void 0 ? void 0 : options.skip) &&
172
+ result.loading) {
173
+ obsQuery.setOptions(createWatchQueryOptions(query, options)).catch(function () { });
174
+ }
175
+ Object.assign(ref.current, { options: options });
176
+ }
177
+ if ((context.renderPromises || client.disableNetworkFetches) &&
178
+ (options === null || options === void 0 ? void 0 : options.ssr) === false) {
179
+ result = ref.current.result = {
180
+ loading: true,
181
+ data: void 0,
182
+ error: void 0,
183
+ networkStatus: NetworkStatus.loading,
184
+ };
185
+ }
186
+ else if ((options === null || options === void 0 ? void 0 : options.skip) || (options === null || options === void 0 ? void 0 : options.fetchPolicy) === 'standby') {
187
+ result = {
188
+ loading: false,
189
+ data: void 0,
190
+ error: void 0,
191
+ networkStatus: NetworkStatus.ready,
192
+ };
193
+ }
194
+ if (result.errors && result.errors.length) {
195
+ result = __assign(__assign({}, result), { error: result.error || new ApolloError({ graphQLErrors: result.errors }) });
196
+ }
197
+ var obsQueryFields = useMemo(function () { return ({
198
+ refetch: obsQuery.refetch.bind(obsQuery),
199
+ fetchMore: obsQuery.fetchMore.bind(obsQuery),
200
+ updateQuery: obsQuery.updateQuery.bind(obsQuery),
201
+ startPolling: obsQuery.startPolling.bind(obsQuery),
202
+ stopPolling: obsQuery.stopPolling.bind(obsQuery),
203
+ subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
204
+ }); }, [obsQuery]);
205
+ return __assign(__assign(__assign({}, obsQueryFields), { variables: createWatchQueryOptions(query, options).variables, client: client, called: true, previousData: ref.current.previousData }), result);
206
+ }
207
+ function createWatchQueryOptions(query, options) {
208
+ var _a;
209
+ if (options === void 0) { options = {}; }
210
+ var skip = options.skip, ssr = options.ssr, onCompleted = options.onCompleted, onError = options.onError, displayName = options.displayName, watchQueryOptions = __rest(options, ["skip", "ssr", "onCompleted", "onError", "displayName"]);
211
+ if (skip) {
212
+ watchQueryOptions.fetchPolicy = 'standby';
213
+ }
214
+ else if (((_a = watchQueryOptions.context) === null || _a === void 0 ? void 0 : _a.renderPromises) &&
215
+ (watchQueryOptions.fetchPolicy === 'network-only' ||
216
+ watchQueryOptions.fetchPolicy === 'cache-and-network')) {
217
+ watchQueryOptions.fetchPolicy = 'cache-first';
218
+ }
219
+ else if (!watchQueryOptions.fetchPolicy) {
220
+ watchQueryOptions.fetchPolicy = 'cache-first';
221
+ }
222
+ if (!watchQueryOptions.variables) {
223
+ watchQueryOptions.variables = {};
224
+ }
225
+ return __assign({ query: query }, watchQueryOptions);
4
226
  }
5
227
  //# sourceMappingURL=useQuery.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useQuery.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGpD,MAAM,UAAU,QAAQ,CACtB,KAA0D,EAC1D,OAA6C;IAE7C,OAAO,YAAY,CAAoB,KAAK,EAAE,OAAO,EAAE,KAAK,CAG3D,CAAC;AACJ,CAAC","sourcesContent":["import { DocumentNode } from 'graphql';\nimport { TypedDocumentNode } from '@graphql-typed-document-node/core';\n\nimport { QueryHookOptions, QueryResult } from '../types/types';\nimport { useBaseQuery } from './utils/useBaseQuery';\nimport { OperationVariables } from '../../core';\n\nexport function useQuery<TData = any, TVariables = OperationVariables>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: QueryHookOptions<TData, TVariables>\n) {\n return useBaseQuery<TData, TVariables>(query, options, false) as QueryResult<\n TData,\n TVariables\n >;\n}\n"]}
1
+ {"version":3,"file":"useQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useQuery.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACzE,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAEL,aAAa,GAKd,MAAM,YAAY,CAAC;AAMpB,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,UAAU,QAAQ,CAItB,KAA0D,EAC1D,OAA6C;;IAE7C,IAAM,OAAO,GAAG,UAAU,CAAC,gBAAgB,EAAE,CAAC,CAAC;IAC/C,IAAM,MAAM,GAAG,eAAe,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,CAAC,CAAC;IAChD,kBAAkB,CAAC,KAAK,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC;IACxC,IAAA,KAA0B,QAAQ,CAAC;QACvC,IAAM,iBAAiB,GAAG,uBAAuB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAIlE,IAA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,CAAC,SAAS,EAAE;QAChC,iBAAiB,CAAC,SAAS,GAAG,EAAgB,CAAC;KAChD;IAED,kBAAS,KAAK,OAAA,IAAK,iBAAiB,EAAG;AACzC,CAAC","sourcesContent":["import { useContext, useEffect, useMemo, useRef, useState } from 'react';\nimport { equal } from '@wry/equality';\nimport { OperationVariables } from '../../core';\nimport { getApolloContext } from '../context';\nimport { ApolloError } from '../../errors';\nimport {\n ApolloQueryResult,\n NetworkStatus,\n ObservableQuery,\n DocumentNode,\n TypedDocumentNode,\n WatchQueryOptions,\n} from '../../core';\nimport {\n QueryHookOptions,\n QueryResult,\n} from '../types/types';\n\nimport { DocumentType, verifyDocumentType } from '../parser';\nimport { useApolloClient } from './useApolloClient';\n\nexport function useQuery<\n TData = any,\n TVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: QueryHookOptions<TData, TVariables>,\n): QueryResult<TData, TVariables> {\n const context = useContext(getApolloContext());\n const client = useApolloClient(options?.client);\n verifyDocumentType(query, DocumentType.Query);\n const [obsQuery, setObsQuery] = useState(() => {\n const watchQueryOptions = createWatchQueryOptions(query, options);\n // See if there is an existing observable that was used to fetch the same\n // data and if so, use it instead since it will contain the proper queryId\n // to fetch the result set. This is used during SSR.\n let obsQuery: ObservableQuery<TData, TVariables> | null = null;\n if (context.renderPromises) {\n obsQuery = context.renderPromises.getSSRObservable(watchQueryOptions);\n }\n\n if (!obsQuery) {\n // Is it safe (StrictMode/memory-wise) to call client.watchQuery here?\n obsQuery = client.watchQuery(watchQueryOptions);\n if (context.renderPromises) {\n context.renderPromises.registerSSRObservable(\n obsQuery,\n watchQueryOptions,\n );\n }\n }\n\n if (\n context.renderPromises &&\n options?.ssr !== false &&\n !options?.skip &&\n obsQuery.getCurrentResult().loading\n ) {\n // TODO: This is a legacy API which could probably be cleaned up\n context.renderPromises.addQueryPromise(\n {\n // The only options which seem to actually be used by the\n // RenderPromises class are query and variables.\n getOptions: () => createWatchQueryOptions(query, options),\n fetchData: () => new Promise<void>((resolve) => {\n const sub = obsQuery!.subscribe({\n next(result) {\n if (!result.loading) {\n resolve()\n sub.unsubscribe();\n }\n },\n error() {\n resolve();\n sub.unsubscribe();\n },\n complete() {\n resolve();\n },\n });\n }),\n },\n // This callback never seemed to do anything\n () => null,\n );\n }\n\n return obsQuery;\n });\n\n let [result, setResult] = useState(() => {\n const result = obsQuery.getCurrentResult();\n if (!result.loading && options) {\n if (result.error) {\n options.onError?.(result.error);\n } else if (result.data) {\n options.onCompleted?.(result.data);\n }\n }\n\n return result;\n });\n\n const ref = useRef({\n client,\n query,\n options,\n result,\n previousData: void 0 as TData | undefined,\n watchQueryOptions: createWatchQueryOptions(query, options),\n });\n\n // An effect to recreate the obsQuery whenever the client or query changes.\n // This effect is also responsible for checking and updating the obsQuery\n // options whenever they change.\n useEffect(() => {\n const watchQueryOptions = createWatchQueryOptions(query, options);\n let nextResult: ApolloQueryResult<TData> | undefined;\n if (ref.current.client !== client || !equal(ref.current.query, query)) {\n const obsQuery = client.watchQuery(watchQueryOptions);\n setObsQuery(obsQuery);\n nextResult = obsQuery.getCurrentResult();\n } else if (!equal(ref.current.watchQueryOptions, watchQueryOptions)) {\n obsQuery.setOptions(watchQueryOptions).catch(() => {});\n nextResult = obsQuery.getCurrentResult();\n ref.current.watchQueryOptions = watchQueryOptions;\n }\n\n if (nextResult) {\n const previousResult = ref.current.result;\n if (previousResult.data) {\n ref.current.previousData = previousResult.data;\n }\n\n setResult(ref.current.result = nextResult);\n if (!nextResult.loading && options) {\n if (!result.loading) {\n if (result.error) {\n options.onError?.(result.error);\n } else if (result.data) {\n options.onCompleted?.(result.data);\n }\n }\n }\n }\n\n Object.assign(ref.current, { client, query });\n }, [obsQuery, client, query, options]);\n\n // An effect to subscribe to the current observable query\n useEffect(() => {\n if (context.renderPromises) {\n return;\n }\n\n let subscription = obsQuery.subscribe(onNext, onError);\n // We use `getCurrentResult()` instead of the callback argument because\n // the values differ slightly. Specifically, loading results will have\n // an empty object for data instead of `undefined` for some reason.\n function onNext() {\n const previousResult = ref.current.result;\n const result = obsQuery.getCurrentResult();\n // Make sure we're not attempting to re-render similar results\n if (\n previousResult &&\n previousResult.loading === result.loading &&\n previousResult.networkStatus === result.networkStatus &&\n equal(previousResult.data, result.data)\n ) {\n return;\n }\n\n if (previousResult.data) {\n ref.current.previousData = previousResult.data;\n }\n\n setResult(ref.current.result = result);\n if (!result.loading) {\n ref.current.options?.onCompleted?.(result.data);\n }\n }\n\n function onError(error: Error) {\n const last = obsQuery[\"last\"];\n subscription.unsubscribe();\n // Unfortunately, if `lastError` is set in the current\n // `observableQuery` when the subscription is re-created,\n // the subscription will immediately receive the error, which will\n // cause it to terminate again. To avoid this, we first clear\n // the last error/result from the `observableQuery` before re-starting\n // the subscription, and restore it afterwards (so the subscription\n // has a chance to stay open).\n try {\n obsQuery.resetLastResults();\n subscription = obsQuery.subscribe(onNext, onError);\n } finally {\n obsQuery[\"last\"] = last;\n }\n\n if (!error.hasOwnProperty('graphQLErrors')) {\n // The error is not a GraphQL error\n throw error;\n }\n\n const previousResult = ref.current.result;\n if (\n (previousResult && previousResult.loading) ||\n !equal(error, previousResult.error)\n ) {\n setResult(ref.current.result = {\n data: previousResult.data,\n error: error as ApolloError,\n loading: false,\n networkStatus: NetworkStatus.error,\n });\n ref.current.options?.onError?.(error as ApolloError);\n }\n }\n\n return () => subscription.unsubscribe();\n }, [obsQuery, context.renderPromises, client.disableNetworkFetches]);\n\n let partial: boolean | undefined;\n ({ partial, ...result } = result);\n\n {\n // BAD BOY CODE BLOCK WHERE WE PUT SIDE-EFFECTS IN THE RENDER FUNCTION\n //\n // TODO: This code should be removed when the partialRefetch option is\n // removed. I was unable to get this hook to behave reasonably in certain\n // edge cases when this block was put in an effect.\n if (\n partial &&\n options?.partialRefetch &&\n !result.loading &&\n (!result.data || Object.keys(result.data).length === 0) &&\n obsQuery.options.fetchPolicy !== 'cache-only'\n ) {\n result = {\n ...result,\n loading: true,\n networkStatus: NetworkStatus.refetch,\n };\n\n obsQuery.refetch();\n }\n\n // TODO: This is a hack to make sure useLazyQuery executions update the\n // obsevable query options for ssr.\n if (\n context.renderPromises &&\n options?.ssr !== false &&\n !options?.skip &&\n result.loading\n ) {\n obsQuery.setOptions(createWatchQueryOptions(query, options)).catch(() => {});\n }\n\n // We assign options during rendering as a guard to make sure that\n // callbacks like onCompleted and onError are not stale.\n Object.assign(ref.current, { options });\n }\n\n if (\n (context.renderPromises || client.disableNetworkFetches) &&\n options?.ssr === false\n ) {\n // If SSR has been explicitly disabled, and this function has been called\n // on the server side, return the default loading state.\n result = ref.current.result = {\n loading: true,\n data: void 0 as unknown as TData,\n error: void 0,\n networkStatus: NetworkStatus.loading,\n };\n } else if (options?.skip || options?.fetchPolicy === 'standby') {\n // When skipping a query (ie. we're not querying for data but still want to\n // render children), make sure the `data` is cleared out and `loading` is\n // set to `false` (since we aren't loading anything).\n //\n // NOTE: We no longer think this is the correct behavior. Skipping should\n // not automatically set `data` to `undefined`, but instead leave the\n // previous data in place. In other words, skipping should not mandate that\n // previously received data is all of a sudden removed. Unfortunately,\n // changing this is breaking, so we'll have to wait until Apollo Client 4.0\n // to address this.\n result = {\n loading: false,\n data: void 0 as unknown as TData,\n error: void 0,\n networkStatus: NetworkStatus.ready,\n };\n }\n\n if (result.errors && result.errors.length) {\n // Until a set naming convention for networkError and graphQLErrors is\n // decided upon, we map errors (graphQLErrors) to the error options.\n // TODO: Is it possible for both result.error and result.errors to be\n // defined here?\n result = {\n ...result,\n error: result.error || new ApolloError({ graphQLErrors: result.errors }),\n };\n }\n\n const obsQueryFields = useMemo(() => ({\n refetch: obsQuery.refetch.bind(obsQuery),\n fetchMore: obsQuery.fetchMore.bind(obsQuery),\n updateQuery: obsQuery.updateQuery.bind(obsQuery),\n startPolling: obsQuery.startPolling.bind(obsQuery),\n stopPolling: obsQuery.stopPolling.bind(obsQuery),\n subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),\n }), [obsQuery]);\n\n return {\n ...obsQueryFields,\n variables: createWatchQueryOptions(query, options).variables,\n client,\n called: true,\n previousData: ref.current.previousData,\n ...result,\n };\n}\n\n/**\n * A function to massage options before passing them the ObservableQuery.\n */\nfunction createWatchQueryOptions<TData, TVariables>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: QueryHookOptions<TData, TVariables> = {},\n): WatchQueryOptions<TVariables, TData> {\n // TODO: For some reason, we pass context, which is the React Apollo Context,\n // into observable queries, and test for that.\n // removing hook specific options\n const {\n skip,\n ssr,\n onCompleted,\n onError,\n displayName,\n ...watchQueryOptions\n } = options;\n\n if (skip) {\n watchQueryOptions.fetchPolicy = 'standby';\n } else if (\n watchQueryOptions.context?.renderPromises &&\n (\n watchQueryOptions.fetchPolicy === 'network-only' ||\n watchQueryOptions.fetchPolicy === 'cache-and-network'\n )\n ) {\n // this behavior was added to react-apollo without explanation in this PR\n // https://github.com/apollographql/react-apollo/pull/1579\n watchQueryOptions.fetchPolicy = 'cache-first';\n } else if (!watchQueryOptions.fetchPolicy) {\n // cache-first is the default policy, but we explicitly assign it here so\n // the cache policies computed based on options can be cleared\n watchQueryOptions.fetchPolicy = 'cache-first';\n }\n\n if (!watchQueryOptions.variables) {\n watchQueryOptions.variables = {} as TVariables;\n }\n\n return { query, ...watchQueryOptions };\n}\n"]}
@@ -1,12 +1,7 @@
1
1
  import '../../utilities/globals';
2
2
  import { DocumentNode } from 'graphql';
3
3
  import { TypedDocumentNode } from '@graphql-typed-document-node/core';
4
- import { SubscriptionHookOptions } from '../types/types';
4
+ import { SubscriptionHookOptions, SubscriptionResult } from '../types/types';
5
5
  import { OperationVariables } from '../../core';
6
- export declare function useSubscription<TData = any, TVariables = OperationVariables>(subscription: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: SubscriptionHookOptions<TData, TVariables>): {
7
- variables: TVariables | undefined;
8
- loading: boolean;
9
- data?: TData | undefined;
10
- error?: import("../../errors").ApolloError | undefined;
11
- };
6
+ export declare function useSubscription<TData = any, TVariables = OperationVariables>(subscription: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: SubscriptionHookOptions<TData, TVariables>): SubscriptionResult<TData, any>;
12
7
  //# sourceMappingURL=useSubscription.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSubscription.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useSubscription.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AAGjC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAEtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAEzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAIhD,wBAAgB,eAAe,CAAC,KAAK,GAAG,GAAG,EAAE,UAAU,GAAG,kBAAkB,EAC1E,YAAY,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,EACjE,OAAO,CAAC,EAAE,uBAAuB,CAAC,KAAK,EAAE,UAAU,CAAC;;;;;EA2CrD"}
1
+ {"version":3,"file":"useSubscription.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useSubscription.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AAEjC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAItE,OAAO,EACL,uBAAuB,EACvB,kBAAkB,EACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAGhD,wBAAgB,eAAe,CAAC,KAAK,GAAG,GAAG,EAAE,UAAU,GAAG,kBAAkB,EAC1E,YAAY,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,EACjE,OAAO,CAAC,EAAE,uBAAuB,CAAC,KAAK,EAAE,UAAU,CAAC,kCA0GrD"}