@apollo/client 4.0.0-rc.5 → 4.0.0-rc.7

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 (631) hide show
  1. package/CHANGELOG.md +153 -0
  2. package/README.md +40 -40
  3. package/__cjs/cache/core/cache.cjs +14 -13
  4. package/__cjs/cache/core/cache.cjs.map +1 -1
  5. package/__cjs/cache/core/cache.d.cts +77 -71
  6. package/__cjs/cache/core/types/Cache.cjs +0 -4
  7. package/__cjs/cache/core/types/Cache.cjs.map +1 -1
  8. package/__cjs/cache/core/types/Cache.d.cts +200 -15
  9. package/__cjs/cache/{core/types/DataProxy.cjs → deprecated.cjs} +1 -1
  10. package/__cjs/cache/deprecated.cjs.map +1 -0
  11. package/__cjs/cache/deprecated.d.cts +6 -0
  12. package/__cjs/cache/index.cjs.map +1 -1
  13. package/__cjs/cache/index.d.cts +2 -2
  14. package/__cjs/cache/inmemory/entityStore.cjs +25 -28
  15. package/__cjs/cache/inmemory/entityStore.cjs.map +1 -1
  16. package/__cjs/cache/inmemory/entityStore.d.cts +17 -16
  17. package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
  18. package/__cjs/cache/inmemory/inMemoryCache.d.cts +4 -4
  19. package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
  20. package/__cjs/cache/inmemory/policies.cjs +4 -4
  21. package/__cjs/cache/inmemory/policies.cjs.map +1 -1
  22. package/__cjs/cache/inmemory/policies.d.cts +3 -2
  23. package/__cjs/cache/inmemory/readFromStore.cjs +2 -2
  24. package/__cjs/cache/inmemory/writeToStore.cjs +4 -4
  25. package/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
  26. package/__cjs/cache/inmemory/writeToStore.d.cts +1 -1
  27. package/__cjs/core/ApolloClient.cjs +94 -112
  28. package/__cjs/core/ApolloClient.cjs.map +1 -1
  29. package/__cjs/core/ApolloClient.d.cts +758 -182
  30. package/__cjs/core/ObservableQuery.cjs +10 -10
  31. package/__cjs/core/ObservableQuery.cjs.map +1 -1
  32. package/__cjs/core/ObservableQuery.d.cts +131 -112
  33. package/__cjs/core/QueryInfo.cjs.map +1 -1
  34. package/__cjs/core/QueryInfo.d.cts +8 -7
  35. package/__cjs/core/QueryManager.cjs +15 -15
  36. package/__cjs/core/QueryManager.cjs.map +1 -1
  37. package/__cjs/core/QueryManager.d.cts +20 -20
  38. package/__cjs/core/deprecated.cjs +3 -0
  39. package/__cjs/core/deprecated.cjs.map +1 -0
  40. package/__cjs/core/deprecated.d.cts +29 -0
  41. package/__cjs/core/index.cjs.map +1 -1
  42. package/__cjs/core/index.d.cts +10 -6
  43. package/__cjs/core/types.d.cts +69 -157
  44. package/__cjs/core/watchQueryOptions.d.cts +8 -297
  45. package/__cjs/dev/setErrorMessageHandler.cjs.map +1 -1
  46. package/__cjs/dev/setErrorMessageHandler.d.cts +4 -4
  47. package/__cjs/errors/CombinedGraphQLErrors.cjs +64 -11
  48. package/__cjs/errors/CombinedGraphQLErrors.cjs.map +1 -1
  49. package/__cjs/errors/CombinedGraphQLErrors.d.cts +168 -14
  50. package/__cjs/errors/CombinedProtocolErrors.cjs +54 -1
  51. package/__cjs/errors/CombinedProtocolErrors.cjs.map +1 -1
  52. package/__cjs/errors/CombinedProtocolErrors.d.cts +132 -2
  53. package/__cjs/errors/LinkError.cjs +45 -2
  54. package/__cjs/errors/LinkError.cjs.map +1 -1
  55. package/__cjs/errors/LinkError.d.cts +45 -2
  56. package/__cjs/errors/LocalStateError.cjs +35 -5
  57. package/__cjs/errors/LocalStateError.cjs.map +1 -1
  58. package/__cjs/errors/LocalStateError.d.cts +41 -5
  59. package/__cjs/errors/ServerError.cjs +51 -8
  60. package/__cjs/errors/ServerError.cjs.map +1 -1
  61. package/__cjs/errors/ServerError.d.cts +71 -11
  62. package/__cjs/errors/ServerParseError.cjs +46 -8
  63. package/__cjs/errors/ServerParseError.cjs.map +1 -1
  64. package/__cjs/errors/ServerParseError.d.cts +72 -16
  65. package/__cjs/errors/UnconventionalError.cjs +46 -2
  66. package/__cjs/errors/UnconventionalError.cjs.map +1 -1
  67. package/__cjs/errors/UnconventionalError.d.cts +46 -2
  68. package/__cjs/incremental/handlers/defer20220824.cjs.map +1 -1
  69. package/__cjs/incremental/handlers/defer20220824.d.cts +4 -4
  70. package/__cjs/incremental/handlers/notImplemented.cjs +1 -1
  71. package/__cjs/incremental/handlers/notImplemented.cjs.map +1 -1
  72. package/__cjs/incremental/handlers/notImplemented.d.cts +2 -2
  73. package/__cjs/incremental/types.d.cts +4 -4
  74. package/__cjs/invariantErrorCodes.cjs +81 -85
  75. package/__cjs/link/batch/batchLink.cjs +3 -9
  76. package/__cjs/link/batch/batchLink.cjs.map +1 -1
  77. package/__cjs/link/batch/batchLink.d.cts +2 -3
  78. package/__cjs/link/batch/batching.cjs +1 -1
  79. package/__cjs/link/batch/batching.cjs.map +1 -1
  80. package/__cjs/link/batch/batching.d.cts +7 -7
  81. package/__cjs/link/batch-http/batchHttpLink.cjs +8 -5
  82. package/__cjs/link/batch-http/batchHttpLink.cjs.map +1 -1
  83. package/__cjs/link/batch-http/batchHttpLink.d.cts +1 -2
  84. package/__cjs/link/client-awareness/ClientAwarenessLink.cjs.map +1 -1
  85. package/__cjs/link/client-awareness/ClientAwarenessLink.d.cts +4 -4
  86. package/__cjs/link/context/index.cjs +1 -1
  87. package/__cjs/link/context/index.cjs.map +1 -1
  88. package/__cjs/link/context/index.d.cts +4 -5
  89. package/__cjs/link/core/ApolloLink.cjs +227 -55
  90. package/__cjs/link/core/ApolloLink.cjs.map +1 -1
  91. package/__cjs/link/core/ApolloLink.d.cts +355 -9
  92. package/__cjs/link/core/concat.cjs +4 -0
  93. package/__cjs/link/core/concat.cjs.map +1 -1
  94. package/__cjs/link/core/concat.d.cts +4 -0
  95. package/__cjs/link/core/deprecated.cjs +3 -0
  96. package/__cjs/link/core/deprecated.cjs.map +1 -0
  97. package/__cjs/link/core/deprecated.d.cts +10 -0
  98. package/__cjs/link/core/empty.cjs +4 -0
  99. package/__cjs/link/core/empty.cjs.map +1 -1
  100. package/__cjs/link/core/empty.d.cts +4 -0
  101. package/__cjs/link/core/from.cjs +4 -0
  102. package/__cjs/link/core/from.cjs.map +1 -1
  103. package/__cjs/link/core/from.d.cts +4 -0
  104. package/__cjs/link/core/split.cjs +4 -0
  105. package/__cjs/link/core/split.cjs.map +1 -1
  106. package/__cjs/link/core/split.d.cts +4 -0
  107. package/__cjs/link/core/types.d.cts +2 -33
  108. package/__cjs/link/error/index.cjs.map +1 -1
  109. package/__cjs/link/error/index.d.cts +20 -6
  110. package/__cjs/link/http/BaseHttpLink.cjs +2 -2
  111. package/__cjs/link/http/BaseHttpLink.cjs.map +1 -1
  112. package/__cjs/link/http/HttpLink.cjs +4 -1
  113. package/__cjs/link/http/HttpLink.cjs.map +1 -1
  114. package/__cjs/link/http/HttpLink.d.cts +3 -3
  115. package/__cjs/link/http/checkFetcher.cjs +1 -1
  116. package/__cjs/link/http/parseAndCheckHttpResponse.cjs +41 -26
  117. package/__cjs/link/http/parseAndCheckHttpResponse.cjs.map +1 -1
  118. package/__cjs/link/http/parseAndCheckHttpResponse.d.cts +2 -2
  119. package/__cjs/link/http/selectHttpOptionsAndBody.cjs.map +1 -1
  120. package/__cjs/link/http/selectHttpOptionsAndBody.d.cts +3 -3
  121. package/__cjs/link/http/selectURI.cjs.map +1 -1
  122. package/__cjs/link/http/selectURI.d.cts +2 -2
  123. package/__cjs/link/http/serializeFetchParameter.cjs +1 -1
  124. package/__cjs/link/index.cjs.map +1 -1
  125. package/__cjs/link/index.d.cts +2 -1
  126. package/__cjs/link/persisted-queries/index.cjs +2 -2
  127. package/__cjs/link/persisted-queries/index.cjs.map +1 -1
  128. package/__cjs/link/persisted-queries/index.d.cts +11 -12
  129. package/__cjs/link/retry/delayFunction.cjs.map +1 -1
  130. package/__cjs/link/retry/delayFunction.d.cts +3 -3
  131. package/__cjs/link/retry/retryFunction.cjs.map +1 -1
  132. package/__cjs/link/retry/retryFunction.d.cts +4 -4
  133. package/__cjs/link/retry/retryLink.cjs +2 -2
  134. package/__cjs/link/retry/retryLink.cjs.map +1 -1
  135. package/__cjs/link/retry/retryLink.d.cts +1 -2
  136. package/__cjs/link/schema/index.cjs.map +1 -1
  137. package/__cjs/link/schema/index.d.cts +2 -3
  138. package/__cjs/link/subscriptions/index.cjs.map +1 -1
  139. package/__cjs/link/subscriptions/index.d.cts +1 -2
  140. package/__cjs/link/utils/createOperation.cjs +12 -4
  141. package/__cjs/link/utils/createOperation.cjs.map +1 -1
  142. package/__cjs/link/utils/createOperation.d.cts +2 -2
  143. package/__cjs/link/utils/index.cjs +1 -5
  144. package/__cjs/link/utils/index.cjs.map +1 -1
  145. package/__cjs/link/utils/index.d.cts +0 -2
  146. package/__cjs/link/ws/index.cjs.map +1 -1
  147. package/__cjs/link/ws/index.d.cts +1 -2
  148. package/__cjs/local-state/LocalState.cjs +55 -9
  149. package/__cjs/local-state/LocalState.cjs.map +1 -1
  150. package/__cjs/local-state/LocalState.d.cts +94 -0
  151. package/__cjs/masking/GraphQLCodegenDataMasking.d.cts +6 -7
  152. package/__cjs/masking/internal/types.d.cts +70 -70
  153. package/__cjs/masking/maskDefinition.cjs +2 -2
  154. package/__cjs/masking/maskFragment.cjs +2 -2
  155. package/__cjs/masking/maskOperation.cjs +1 -1
  156. package/__cjs/masking/utils.cjs +3 -3
  157. package/__cjs/react/context/ApolloContext.cjs +1 -1
  158. package/__cjs/react/context/ApolloProvider.cjs +1 -1
  159. package/__cjs/react/hooks/internal/useDeepMemo.cjs +0 -3
  160. package/__cjs/react/hooks/internal/useDeepMemo.cjs.map +1 -1
  161. package/__cjs/react/hooks/internal/validateSuspenseHookOptions.cjs.map +1 -1
  162. package/__cjs/react/hooks/internal/validateSuspenseHookOptions.d.cts +2 -2
  163. package/__cjs/react/hooks/internal/wrapHook.cjs +1 -0
  164. package/__cjs/react/hooks/internal/wrapHook.cjs.map +1 -1
  165. package/__cjs/react/hooks/internal/wrapHook.d.cts +8 -7
  166. package/__cjs/react/hooks/useApolloClient.cjs +2 -2
  167. package/__cjs/react/hooks/useApolloClient.cjs.map +1 -1
  168. package/__cjs/react/hooks/useApolloClient.d.cts +2 -2
  169. package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
  170. package/__cjs/react/hooks/useBackgroundQuery.d.cts +850 -90
  171. package/__cjs/react/hooks/useFragment.cjs +7 -0
  172. package/__cjs/react/hooks/useFragment.cjs.map +1 -1
  173. package/__cjs/react/hooks/useFragment.d.cts +53 -2
  174. package/__cjs/react/hooks/useLazyQuery.cjs +0 -38
  175. package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
  176. package/__cjs/react/hooks/useLazyQuery.d.cts +317 -165
  177. package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
  178. package/__cjs/react/hooks/useLoadableQuery.d.cts +153 -175
  179. package/__cjs/react/hooks/useMutation.cjs +6 -7
  180. package/__cjs/react/hooks/useMutation.cjs.map +1 -1
  181. package/__cjs/react/hooks/useMutation.d.cts +87 -65
  182. package/__cjs/react/hooks/useQuery.cjs +1 -35
  183. package/__cjs/react/hooks/useQuery.cjs.map +1 -1
  184. package/__cjs/react/hooks/useQuery.d.cts +207 -103
  185. package/__cjs/react/hooks/useQueryRefHandlers.cjs +2 -1
  186. package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
  187. package/__cjs/react/hooks/useQueryRefHandlers.d.cts +34 -5
  188. package/__cjs/react/hooks/useReactiveVar.cjs +2 -1
  189. package/__cjs/react/hooks/useReactiveVar.cjs.map +1 -1
  190. package/__cjs/react/hooks/useReactiveVar.d.cts +2 -1
  191. package/__cjs/react/hooks/useReadQuery.cjs +29 -0
  192. package/__cjs/react/hooks/useReadQuery.cjs.map +1 -1
  193. package/__cjs/react/hooks/useReadQuery.d.cts +92 -16
  194. package/__cjs/react/hooks/useSubscription.cjs +8 -9
  195. package/__cjs/react/hooks/useSubscription.cjs.map +1 -1
  196. package/__cjs/react/hooks/useSubscription.d.cts +108 -33
  197. package/__cjs/react/hooks/useSuspenseFragment.cjs.map +1 -1
  198. package/__cjs/react/hooks/useSuspenseFragment.d.cts +61 -29
  199. package/__cjs/react/hooks/useSuspenseQuery.cjs +4 -1
  200. package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
  201. package/__cjs/react/hooks/useSuspenseQuery.d.cts +471 -69
  202. package/__cjs/react/index.cjs +1 -3
  203. package/__cjs/react/index.cjs.map +1 -1
  204. package/__cjs/react/index.d.cts +0 -1
  205. package/__cjs/react/index.react-server.cjs +1 -3
  206. package/__cjs/react/index.react-server.cjs.map +1 -1
  207. package/__cjs/react/index.react-server.d.cts +0 -1
  208. package/__cjs/react/internal/cache/FragmentReference.cjs.map +1 -1
  209. package/__cjs/react/internal/cache/FragmentReference.d.cts +2 -3
  210. package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
  211. package/__cjs/react/internal/cache/QueryReference.d.cts +14 -12
  212. package/__cjs/react/internal/cache/SuspenseCache.cjs.map +1 -1
  213. package/__cjs/react/internal/cache/SuspenseCache.d.cts +2 -2
  214. package/__cjs/react/internal/cache/getSuspenseCache.cjs.map +1 -1
  215. package/__cjs/react/internal/cache/getSuspenseCache.d.cts +6 -4
  216. package/__cjs/react/internal/index.cjs +1 -0
  217. package/__cjs/react/internal/index.cjs.map +1 -1
  218. package/__cjs/react/internal/index.d.cts +1 -1
  219. package/__cjs/react/internal/types.d.cts +3 -3
  220. package/__cjs/react/query-preloader/createQueryPreloader.cjs +1 -1
  221. package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
  222. package/__cjs/react/query-preloader/createQueryPreloader.d.cts +60 -51
  223. package/__cjs/react/ssr/prerenderStatic.cjs +5 -4
  224. package/__cjs/react/ssr/prerenderStatic.cjs.map +1 -1
  225. package/__cjs/react/ssr/prerenderStatic.d.cts +11 -9
  226. package/__cjs/react/ssr/useSSRQuery.cjs.map +1 -1
  227. package/__cjs/react/types/deprecated.d.cts +1 -1
  228. package/__cjs/react/types/types.documentation.d.cts +15 -15
  229. package/__cjs/testing/core/mocking/mockLink.cjs.map +1 -1
  230. package/__cjs/testing/core/mocking/mockLink.d.cts +8 -8
  231. package/__cjs/testing/core/mocking/mockSubscriptionLink.cjs.map +1 -1
  232. package/__cjs/testing/core/mocking/mockSubscriptionLink.d.cts +3 -4
  233. package/__cjs/testing/core/types/deprecated.d.cts +3 -2
  234. package/__cjs/testing/react/MockedProvider.cjs.map +1 -1
  235. package/__cjs/testing/react/MockedProvider.d.cts +2 -3
  236. package/__cjs/utilities/HKT.d.cts +8 -7
  237. package/__cjs/utilities/caching/sizes.cjs +3 -3
  238. package/__cjs/utilities/caching/sizes.cjs.map +1 -1
  239. package/__cjs/utilities/caching/sizes.d.cts +4 -6
  240. package/__cjs/utilities/graphql/DocumentTransform.cjs +2 -2
  241. package/__cjs/utilities/graphql/DocumentTransform.cjs.map +1 -1
  242. package/__cjs/utilities/index.cjs +2 -3
  243. package/__cjs/utilities/index.cjs.map +1 -1
  244. package/__cjs/utilities/index.d.cts +1 -2
  245. package/__cjs/utilities/{shared → internal}/canonicalStringify.cjs +5 -7
  246. package/__cjs/utilities/internal/canonicalStringify.cjs.map +1 -0
  247. package/__cjs/utilities/{shared → internal}/canonicalStringify.d.cts +1 -1
  248. package/__cjs/utilities/internal/checkDocument.cjs +2 -2
  249. package/__cjs/utilities/internal/checkDocument.cjs.map +1 -1
  250. package/__cjs/utilities/internal/createFragmentMap.cjs.map +1 -1
  251. package/__cjs/{core → utilities/internal}/equalByQuery.cjs +13 -7
  252. package/__cjs/utilities/internal/equalByQuery.cjs.map +1 -0
  253. package/__cjs/utilities/internal/equalByQuery.d.cts +5 -0
  254. package/__cjs/utilities/internal/getFragmentQueryDocument.cjs +13 -3
  255. package/__cjs/utilities/internal/getFragmentQueryDocument.cjs.map +1 -1
  256. package/__cjs/utilities/internal/getFragmentQueryDocument.d.cts +13 -3
  257. package/__cjs/utilities/internal/getMemoryInternals.cjs.map +1 -1
  258. package/__cjs/utilities/internal/getStoreKeyName.cjs +1 -2
  259. package/__cjs/utilities/internal/getStoreKeyName.cjs.map +1 -1
  260. package/__cjs/utilities/internal/index.cjs +6 -2
  261. package/__cjs/utilities/internal/index.cjs.map +1 -1
  262. package/__cjs/utilities/internal/index.d.cts +2 -0
  263. package/__cjs/utilities/internal/mergeOptions.cjs.map +1 -1
  264. package/__cjs/utilities/internal/mergeOptions.d.cts +2 -2
  265. package/__cjs/utilities/internal/toQueryResult.cjs.map +1 -1
  266. package/__cjs/utilities/internal/toQueryResult.d.cts +2 -2
  267. package/__cjs/utilities/internal/types/DocumentationTypes.d.cts +32 -26
  268. package/__cjs/utilities/internal/types/NoInfer.d.cts +31 -25
  269. package/__cjs/utilities/internal/types/VariablesOption.d.cts +2 -6
  270. package/__cjs/utilities/subscriptions/relay/index.cjs +2 -0
  271. package/__cjs/utilities/subscriptions/relay/index.cjs.map +1 -1
  272. package/__cjs/version.cjs +1 -1
  273. package/cache/core/cache.d.ts +77 -71
  274. package/cache/core/cache.js +15 -14
  275. package/cache/core/cache.js.map +1 -1
  276. package/cache/core/types/Cache.d.ts +200 -15
  277. package/cache/core/types/Cache.js +1 -3
  278. package/cache/core/types/Cache.js.map +1 -1
  279. package/cache/deprecated.d.ts +6 -0
  280. package/cache/deprecated.js +2 -0
  281. package/cache/deprecated.js.map +1 -0
  282. package/cache/index.d.ts +2 -2
  283. package/cache/index.js.map +1 -1
  284. package/cache/inmemory/entityStore.d.ts +17 -16
  285. package/cache/inmemory/entityStore.js +25 -28
  286. package/cache/inmemory/entityStore.js.map +1 -1
  287. package/cache/inmemory/inMemoryCache.d.ts +4 -4
  288. package/cache/inmemory/inMemoryCache.js.map +1 -1
  289. package/cache/inmemory/key-extractor.js +1 -1
  290. package/cache/inmemory/policies.d.ts +3 -2
  291. package/cache/inmemory/policies.js +4 -4
  292. package/cache/inmemory/policies.js.map +1 -1
  293. package/cache/inmemory/readFromStore.js +2 -2
  294. package/cache/inmemory/writeToStore.d.ts +1 -1
  295. package/cache/inmemory/writeToStore.js +4 -4
  296. package/cache/inmemory/writeToStore.js.map +1 -1
  297. package/core/ApolloClient.d.ts +758 -182
  298. package/core/ApolloClient.js +94 -112
  299. package/core/ApolloClient.js.map +1 -1
  300. package/core/ObservableQuery.d.ts +131 -112
  301. package/core/ObservableQuery.js +10 -10
  302. package/core/ObservableQuery.js.map +1 -1
  303. package/core/QueryInfo.d.ts +8 -7
  304. package/core/QueryInfo.js.map +1 -1
  305. package/core/QueryManager.d.ts +20 -20
  306. package/core/QueryManager.js +15 -15
  307. package/core/QueryManager.js.map +1 -1
  308. package/core/deprecated.d.ts +29 -0
  309. package/core/deprecated.js +2 -0
  310. package/core/deprecated.js.map +1 -0
  311. package/core/index.d.ts +10 -6
  312. package/core/index.js.map +1 -1
  313. package/core/types.d.ts +69 -157
  314. package/core/types.js.map +1 -1
  315. package/core/watchQueryOptions.d.ts +9 -298
  316. package/core/watchQueryOptions.js.map +1 -1
  317. package/dev/setErrorMessageHandler.d.ts +4 -4
  318. package/dev/setErrorMessageHandler.js.map +1 -1
  319. package/errors/CombinedGraphQLErrors.d.ts +169 -15
  320. package/errors/CombinedGraphQLErrors.js +65 -12
  321. package/errors/CombinedGraphQLErrors.js.map +1 -1
  322. package/errors/CombinedProtocolErrors.d.ts +133 -3
  323. package/errors/CombinedProtocolErrors.js +55 -2
  324. package/errors/CombinedProtocolErrors.js.map +1 -1
  325. package/errors/LinkError.d.ts +45 -2
  326. package/errors/LinkError.js +45 -2
  327. package/errors/LinkError.js.map +1 -1
  328. package/errors/LocalStateError.d.ts +42 -6
  329. package/errors/LocalStateError.js +36 -6
  330. package/errors/LocalStateError.js.map +1 -1
  331. package/errors/ServerError.d.ts +72 -12
  332. package/errors/ServerError.js +52 -9
  333. package/errors/ServerError.js.map +1 -1
  334. package/errors/ServerParseError.d.ts +73 -17
  335. package/errors/ServerParseError.js +47 -9
  336. package/errors/ServerParseError.js.map +1 -1
  337. package/errors/UnconventionalError.d.ts +46 -2
  338. package/errors/UnconventionalError.js +46 -2
  339. package/errors/UnconventionalError.js.map +1 -1
  340. package/incremental/handlers/defer20220824.d.ts +4 -4
  341. package/incremental/handlers/defer20220824.js.map +1 -1
  342. package/incremental/handlers/notImplemented.d.ts +2 -2
  343. package/incremental/handlers/notImplemented.js +1 -1
  344. package/incremental/handlers/notImplemented.js.map +1 -1
  345. package/incremental/types.d.ts +4 -4
  346. package/incremental/types.js.map +1 -1
  347. package/invariantErrorCodes.js +81 -85
  348. package/link/batch/batchLink.d.ts +2 -3
  349. package/link/batch/batchLink.js +3 -9
  350. package/link/batch/batchLink.js.map +1 -1
  351. package/link/batch/batching.d.ts +7 -7
  352. package/link/batch/batching.js +2 -2
  353. package/link/batch/batching.js.map +1 -1
  354. package/link/batch-http/batchHttpLink.d.ts +1 -2
  355. package/link/batch-http/batchHttpLink.js +7 -4
  356. package/link/batch-http/batchHttpLink.js.map +1 -1
  357. package/link/client-awareness/ClientAwarenessLink.d.ts +4 -4
  358. package/link/client-awareness/ClientAwarenessLink.js.map +1 -1
  359. package/link/context/index.d.ts +4 -5
  360. package/link/context/index.js +1 -1
  361. package/link/context/index.js.map +1 -1
  362. package/link/core/ApolloLink.d.ts +355 -9
  363. package/link/core/ApolloLink.js +228 -57
  364. package/link/core/ApolloLink.js.map +1 -1
  365. package/link/core/concat.d.ts +4 -0
  366. package/link/core/concat.js +4 -0
  367. package/link/core/concat.js.map +1 -1
  368. package/link/core/deprecated.d.ts +10 -0
  369. package/link/core/deprecated.js +2 -0
  370. package/link/core/deprecated.js.map +1 -0
  371. package/link/core/empty.d.ts +4 -0
  372. package/link/core/empty.js +4 -0
  373. package/link/core/empty.js.map +1 -1
  374. package/link/core/from.d.ts +4 -0
  375. package/link/core/from.js +4 -0
  376. package/link/core/from.js.map +1 -1
  377. package/link/core/split.d.ts +4 -0
  378. package/link/core/split.js +4 -0
  379. package/link/core/split.js.map +1 -1
  380. package/link/core/types.d.ts +2 -33
  381. package/link/core/types.js.map +1 -1
  382. package/link/error/index.d.ts +20 -6
  383. package/link/error/index.js.map +1 -1
  384. package/link/http/BaseHttpLink.js +2 -2
  385. package/link/http/BaseHttpLink.js.map +1 -1
  386. package/link/http/HttpLink.d.ts +3 -3
  387. package/link/http/HttpLink.js +4 -1
  388. package/link/http/HttpLink.js.map +1 -1
  389. package/link/http/checkFetcher.js +1 -1
  390. package/link/http/parseAndCheckHttpResponse.d.ts +2 -2
  391. package/link/http/parseAndCheckHttpResponse.js +41 -26
  392. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  393. package/link/http/selectHttpOptionsAndBody.d.ts +3 -3
  394. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  395. package/link/http/selectURI.d.ts +2 -2
  396. package/link/http/selectURI.js.map +1 -1
  397. package/link/http/serializeFetchParameter.js +1 -1
  398. package/link/index.d.ts +2 -1
  399. package/link/index.js.map +1 -1
  400. package/link/persisted-queries/index.d.ts +11 -12
  401. package/link/persisted-queries/index.js +2 -2
  402. package/link/persisted-queries/index.js.map +1 -1
  403. package/link/retry/delayFunction.d.ts +3 -3
  404. package/link/retry/delayFunction.js.map +1 -1
  405. package/link/retry/retryFunction.d.ts +4 -4
  406. package/link/retry/retryFunction.js.map +1 -1
  407. package/link/retry/retryLink.d.ts +1 -2
  408. package/link/retry/retryLink.js +2 -2
  409. package/link/retry/retryLink.js.map +1 -1
  410. package/link/schema/index.d.ts +2 -3
  411. package/link/schema/index.js.map +1 -1
  412. package/link/subscriptions/index.d.ts +1 -2
  413. package/link/subscriptions/index.js.map +1 -1
  414. package/link/utils/createOperation.d.ts +2 -2
  415. package/link/utils/createOperation.js +12 -4
  416. package/link/utils/createOperation.js.map +1 -1
  417. package/link/utils/index.d.ts +0 -2
  418. package/link/utils/index.js +0 -2
  419. package/link/utils/index.js.map +1 -1
  420. package/link/ws/index.d.ts +1 -2
  421. package/link/ws/index.js.map +1 -1
  422. package/local-state/LocalState.d.ts +94 -0
  423. package/local-state/LocalState.js +55 -9
  424. package/local-state/LocalState.js.map +1 -1
  425. package/masking/GraphQLCodegenDataMasking.d.ts +6 -7
  426. package/masking/GraphQLCodegenDataMasking.js.map +1 -1
  427. package/masking/internal/types.d.ts +70 -70
  428. package/masking/internal/types.js.map +1 -1
  429. package/masking/maskDefinition.js +2 -2
  430. package/masking/maskFragment.js +2 -2
  431. package/masking/maskOperation.js +1 -1
  432. package/masking/types.js.map +1 -1
  433. package/masking/utils.js +3 -3
  434. package/package.json +1 -1
  435. package/react/context/ApolloContext.js +1 -1
  436. package/react/context/ApolloProvider.js +1 -1
  437. package/react/hooks/internal/useDeepMemo.js +0 -3
  438. package/react/hooks/internal/useDeepMemo.js.map +1 -1
  439. package/react/hooks/internal/validateSuspenseHookOptions.d.ts +2 -2
  440. package/react/hooks/internal/validateSuspenseHookOptions.js.map +1 -1
  441. package/react/hooks/internal/wrapHook.d.ts +8 -7
  442. package/react/hooks/internal/wrapHook.js +1 -0
  443. package/react/hooks/internal/wrapHook.js.map +1 -1
  444. package/react/hooks/useApolloClient.d.ts +2 -2
  445. package/react/hooks/useApolloClient.js +2 -2
  446. package/react/hooks/useApolloClient.js.map +1 -1
  447. package/react/hooks/useBackgroundQuery.d.ts +850 -90
  448. package/react/hooks/useBackgroundQuery.js.map +1 -1
  449. package/react/hooks/useFragment.d.ts +54 -3
  450. package/react/hooks/useFragment.js +7 -0
  451. package/react/hooks/useFragment.js.map +1 -1
  452. package/react/hooks/useLazyQuery.d.ts +317 -165
  453. package/react/hooks/useLazyQuery.js +0 -38
  454. package/react/hooks/useLazyQuery.js.map +1 -1
  455. package/react/hooks/useLoadableQuery.d.ts +153 -175
  456. package/react/hooks/useLoadableQuery.js.map +1 -1
  457. package/react/hooks/useMutation.d.ts +87 -65
  458. package/react/hooks/useMutation.js +6 -7
  459. package/react/hooks/useMutation.js.map +1 -1
  460. package/react/hooks/useQuery.d.ts +207 -103
  461. package/react/hooks/useQuery.js +1 -35
  462. package/react/hooks/useQuery.js.map +1 -1
  463. package/react/hooks/useQueryRefHandlers.d.ts +34 -5
  464. package/react/hooks/useQueryRefHandlers.js +2 -1
  465. package/react/hooks/useQueryRefHandlers.js.map +1 -1
  466. package/react/hooks/useReactiveVar.d.ts +2 -1
  467. package/react/hooks/useReactiveVar.js +2 -1
  468. package/react/hooks/useReactiveVar.js.map +1 -1
  469. package/react/hooks/useReadQuery.d.ts +93 -17
  470. package/react/hooks/useReadQuery.js +29 -0
  471. package/react/hooks/useReadQuery.js.map +1 -1
  472. package/react/hooks/useSubscription.d.ts +108 -33
  473. package/react/hooks/useSubscription.js +8 -9
  474. package/react/hooks/useSubscription.js.map +1 -1
  475. package/react/hooks/useSuspenseFragment.d.ts +62 -30
  476. package/react/hooks/useSuspenseFragment.js.map +1 -1
  477. package/react/hooks/useSuspenseQuery.d.ts +471 -69
  478. package/react/hooks/useSuspenseQuery.js +4 -1
  479. package/react/hooks/useSuspenseQuery.js.map +1 -1
  480. package/react/hooks-compiled/internal/useDeepMemo.js +0 -3
  481. package/react/hooks-compiled/internal/useDeepMemo.js.map +1 -1
  482. package/react/hooks-compiled/internal/validateSuspenseHookOptions.d.ts +2 -2
  483. package/react/hooks-compiled/internal/validateSuspenseHookOptions.js.map +1 -1
  484. package/react/hooks-compiled/internal/wrapHook.d.ts +8 -7
  485. package/react/hooks-compiled/internal/wrapHook.js +1 -0
  486. package/react/hooks-compiled/internal/wrapHook.js.map +1 -1
  487. package/react/hooks-compiled/useApolloClient.d.ts +2 -2
  488. package/react/hooks-compiled/useApolloClient.js +2 -2
  489. package/react/hooks-compiled/useApolloClient.js.map +1 -1
  490. package/react/hooks-compiled/useBackgroundQuery.d.ts +850 -90
  491. package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
  492. package/react/hooks-compiled/useFragment.d.ts +54 -3
  493. package/react/hooks-compiled/useFragment.js +7 -0
  494. package/react/hooks-compiled/useFragment.js.map +1 -1
  495. package/react/hooks-compiled/useLazyQuery.d.ts +317 -165
  496. package/react/hooks-compiled/useLazyQuery.js +0 -38
  497. package/react/hooks-compiled/useLazyQuery.js.map +1 -1
  498. package/react/hooks-compiled/useLoadableQuery.d.ts +153 -175
  499. package/react/hooks-compiled/useLoadableQuery.js.map +1 -1
  500. package/react/hooks-compiled/useMutation.d.ts +87 -65
  501. package/react/hooks-compiled/useMutation.js +6 -7
  502. package/react/hooks-compiled/useMutation.js.map +1 -1
  503. package/react/hooks-compiled/useQuery.d.ts +207 -103
  504. package/react/hooks-compiled/useQuery.js +1 -35
  505. package/react/hooks-compiled/useQuery.js.map +1 -1
  506. package/react/hooks-compiled/useQueryRefHandlers.d.ts +34 -5
  507. package/react/hooks-compiled/useQueryRefHandlers.js +2 -1
  508. package/react/hooks-compiled/useQueryRefHandlers.js.map +1 -1
  509. package/react/hooks-compiled/useReactiveVar.d.ts +2 -1
  510. package/react/hooks-compiled/useReactiveVar.js +2 -1
  511. package/react/hooks-compiled/useReactiveVar.js.map +1 -1
  512. package/react/hooks-compiled/useReadQuery.d.ts +93 -17
  513. package/react/hooks-compiled/useReadQuery.js +29 -0
  514. package/react/hooks-compiled/useReadQuery.js.map +1 -1
  515. package/react/hooks-compiled/useSubscription.d.ts +108 -33
  516. package/react/hooks-compiled/useSubscription.js +8 -9
  517. package/react/hooks-compiled/useSubscription.js.map +1 -1
  518. package/react/hooks-compiled/useSuspenseFragment.d.ts +62 -30
  519. package/react/hooks-compiled/useSuspenseFragment.js.map +1 -1
  520. package/react/hooks-compiled/useSuspenseQuery.d.ts +471 -69
  521. package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
  522. package/react/index.compiled.d.ts +0 -1
  523. package/react/index.compiled.js +0 -1
  524. package/react/index.compiled.js.map +1 -1
  525. package/react/index.d.ts +0 -1
  526. package/react/index.js +0 -1
  527. package/react/index.js.map +1 -1
  528. package/react/index.react-server.d.ts +0 -1
  529. package/react/index.react-server.js +0 -2
  530. package/react/index.react-server.js.map +1 -1
  531. package/react/internal/cache/FragmentReference.d.ts +2 -3
  532. package/react/internal/cache/FragmentReference.js.map +1 -1
  533. package/react/internal/cache/QueryReference.d.ts +14 -12
  534. package/react/internal/cache/QueryReference.js.map +1 -1
  535. package/react/internal/cache/SuspenseCache.d.ts +2 -2
  536. package/react/internal/cache/SuspenseCache.js.map +1 -1
  537. package/react/internal/cache/getSuspenseCache.d.ts +6 -4
  538. package/react/internal/cache/getSuspenseCache.js.map +1 -1
  539. package/react/internal/index.d.ts +1 -1
  540. package/react/internal/index.js +1 -0
  541. package/react/internal/index.js.map +1 -1
  542. package/react/internal/types.d.ts +3 -3
  543. package/react/internal/types.js.map +1 -1
  544. package/react/query-preloader/createQueryPreloader.d.ts +60 -51
  545. package/react/query-preloader/createQueryPreloader.js +1 -1
  546. package/react/query-preloader/createQueryPreloader.js.map +1 -1
  547. package/react/ssr/prerenderStatic.d.ts +11 -9
  548. package/react/ssr/prerenderStatic.js +5 -4
  549. package/react/ssr/prerenderStatic.js.map +1 -1
  550. package/react/ssr/useSSRQuery.js.map +1 -1
  551. package/react/types/deprecated.d.ts +1 -1
  552. package/react/types/deprecated.js.map +1 -1
  553. package/react/types/types.documentation.d.ts +15 -15
  554. package/react/types/types.documentation.js.map +1 -1
  555. package/testing/core/mocking/mockLink.d.ts +8 -8
  556. package/testing/core/mocking/mockLink.js.map +1 -1
  557. package/testing/core/mocking/mockSubscriptionLink.d.ts +3 -4
  558. package/testing/core/mocking/mockSubscriptionLink.js.map +1 -1
  559. package/testing/core/types/deprecated.d.ts +3 -2
  560. package/testing/core/types/deprecated.js.map +1 -1
  561. package/testing/react/MockedProvider.d.ts +2 -3
  562. package/testing/react/MockedProvider.js.map +1 -1
  563. package/utilities/HKT.d.ts +8 -7
  564. package/utilities/HKT.js.map +1 -1
  565. package/utilities/caching/sizes.d.ts +4 -6
  566. package/utilities/caching/sizes.js +3 -3
  567. package/utilities/caching/sizes.js.map +1 -1
  568. package/utilities/graphql/DocumentTransform.js +1 -1
  569. package/utilities/graphql/DocumentTransform.js.map +1 -1
  570. package/utilities/index.d.ts +1 -2
  571. package/utilities/index.js +1 -2
  572. package/utilities/index.js.map +1 -1
  573. package/utilities/{shared → internal}/canonicalStringify.d.ts +1 -1
  574. package/utilities/{shared → internal}/canonicalStringify.js +4 -6
  575. package/utilities/internal/canonicalStringify.js.map +1 -0
  576. package/utilities/internal/checkDocument.js +1 -1
  577. package/utilities/internal/checkDocument.js.map +1 -1
  578. package/utilities/internal/createFragmentMap.js.map +1 -1
  579. package/utilities/internal/equalByQuery.d.ts +5 -0
  580. package/{core → utilities/internal}/equalByQuery.js +7 -1
  581. package/utilities/internal/equalByQuery.js.map +1 -0
  582. package/utilities/internal/getFragmentQueryDocument.d.ts +13 -3
  583. package/utilities/internal/getFragmentQueryDocument.js +13 -3
  584. package/utilities/internal/getFragmentQueryDocument.js.map +1 -1
  585. package/utilities/internal/getMemoryInternals.js.map +1 -1
  586. package/utilities/internal/getStoreKeyName.js +1 -2
  587. package/utilities/internal/getStoreKeyName.js.map +1 -1
  588. package/utilities/internal/index.d.ts +2 -0
  589. package/utilities/internal/index.js +2 -0
  590. package/utilities/internal/index.js.map +1 -1
  591. package/utilities/internal/mergeOptions.d.ts +2 -2
  592. package/utilities/internal/mergeOptions.js.map +1 -1
  593. package/utilities/internal/toQueryResult.d.ts +2 -2
  594. package/utilities/internal/toQueryResult.js.map +1 -1
  595. package/utilities/internal/types/DocumentationTypes.d.ts +32 -26
  596. package/utilities/internal/types/DocumentationTypes.js.map +1 -1
  597. package/utilities/internal/types/NoInfer.d.ts +31 -25
  598. package/utilities/internal/types/NoInfer.js.map +1 -1
  599. package/utilities/internal/types/VariablesOption.d.ts +2 -6
  600. package/utilities/subscriptions/relay/index.js +2 -0
  601. package/utilities/subscriptions/relay/index.js.map +1 -1
  602. package/version.js +1 -1
  603. package/__cjs/cache/core/types/DataProxy.cjs.map +0 -1
  604. package/__cjs/cache/core/types/DataProxy.d.cts +0 -140
  605. package/__cjs/core/equalByQuery.cjs.map +0 -1
  606. package/__cjs/core/equalByQuery.d.cts +0 -4
  607. package/__cjs/link/utils/transformOperation.cjs +0 -22
  608. package/__cjs/link/utils/transformOperation.cjs.map +0 -1
  609. package/__cjs/link/utils/transformOperation.d.cts +0 -3
  610. package/__cjs/link/utils/validateOperation.cjs +0 -21
  611. package/__cjs/link/utils/validateOperation.cjs.map +0 -1
  612. package/__cjs/link/utils/validateOperation.d.cts +0 -3
  613. package/__cjs/react/context/ApolloConsumer.cjs +0 -16
  614. package/__cjs/react/context/ApolloConsumer.cjs.map +0 -1
  615. package/__cjs/react/context/ApolloConsumer.d.cts +0 -10
  616. package/__cjs/utilities/shared/canonicalStringify.cjs.map +0 -1
  617. package/cache/core/types/DataProxy.d.ts +0 -140
  618. package/cache/core/types/DataProxy.js +0 -2
  619. package/cache/core/types/DataProxy.js.map +0 -1
  620. package/core/equalByQuery.d.ts +0 -4
  621. package/core/equalByQuery.js.map +0 -1
  622. package/link/utils/transformOperation.d.ts +0 -3
  623. package/link/utils/transformOperation.js +0 -19
  624. package/link/utils/transformOperation.js.map +0 -1
  625. package/link/utils/validateOperation.d.ts +0 -3
  626. package/link/utils/validateOperation.js +0 -18
  627. package/link/utils/validateOperation.js.map +0 -1
  628. package/react/context/ApolloConsumer.d.ts +0 -10
  629. package/react/context/ApolloConsumer.js +0 -11
  630. package/react/context/ApolloConsumer.js.map +0 -1
  631. package/utilities/shared/canonicalStringify.js.map +0 -1
@@ -1,9 +1,9 @@
1
1
  import { Observable } from "rxjs";
2
- import type { FetchResult, NextLink, Operation } from "@apollo/client/link";
3
- export type BatchHandler = (operations: Operation[], forward?: (NextLink | undefined)[]) => Observable<FetchResult[]> | null;
2
+ import type { ApolloLink } from "@apollo/client/link";
3
+ export type BatchHandler = (operations: ApolloLink.Operation[], forward: ApolloLink.ForwardFunction[]) => Observable<ApolloLink.Result[]>;
4
4
  export interface BatchableRequest {
5
- operation: Operation;
6
- forward?: NextLink;
5
+ operation: ApolloLink.Operation;
6
+ forward: ApolloLink.ForwardFunction;
7
7
  }
8
8
  export declare class OperationBatcher {
9
9
  private batchesByKey;
@@ -18,10 +18,10 @@ export declare class OperationBatcher {
18
18
  batchInterval?: number;
19
19
  batchMax?: number;
20
20
  batchHandler: BatchHandler;
21
- batchKey?: (operation: Operation) => string;
21
+ batchKey?: (operation: ApolloLink.Operation) => string;
22
22
  });
23
- enqueueRequest(request: BatchableRequest): Observable<FetchResult>;
24
- consumeQueue(key?: string): (Observable<FetchResult> | undefined)[] | undefined;
23
+ enqueueRequest(request: BatchableRequest): Observable<ApolloLink.Result>;
24
+ consumeQueue(key?: string): (Observable<ApolloLink.Result> | undefined)[] | undefined;
25
25
  private scheduleQueueConsumption;
26
26
  }
27
27
  //# sourceMappingURL=batching.d.ts.map
@@ -1,4 +1,4 @@
1
- import { EMPTY, Observable } from "rxjs";
1
+ import { Observable } from "rxjs";
2
2
  // QueryBatcher doesn't fire requests immediately. Requests that were enqueued within
3
3
  // a certain amount of time (configurable through `batchInterval`) will be batched together
4
4
  // into one query.
@@ -103,7 +103,7 @@ export class OperationBatcher {
103
103
  errors.push(request.error);
104
104
  completes.push(request.complete);
105
105
  });
106
- const batchedObservable = this.batchHandler(operations, forwards) || EMPTY;
106
+ const batchedObservable = this.batchHandler(operations, forwards);
107
107
  const onError = (error) => {
108
108
  //each callback list in batch
109
109
  errors.forEach((rejecters) => {
@@ -1 +1 @@
1
- {"version":3,"file":"batching.js","sourceRoot":"","sources":["../../../src/link/batch/batching.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AA4BzC,qFAAqF;AACrF,2FAA2F;AAC3F,kBAAkB;AAClB,MAAM,OAAO,gBAAgB;IAC3B,oEAAoE;IAC5D,YAAY,GAAG,IAAI,GAAG,EAAwB,CAAC;IAE/C,wBAAwB,GAAG,IAAI,GAAG,EAGvC,CAAC;IACI,aAAa,CAAW;IACxB,aAAa,CAAU;IACvB,QAAQ,CAAS;IAEzB,oEAAoE;IAC5D,YAAY,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AE;gBACb,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;oBAC7B,IAAI,QAAQ,EAAE,CAAC;wBACb,4BAA4B;wBAC5B,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;oBAC/B,CAAC;gBACH,CAAC,CAAC,CAAC;YACL,CAAC;SACF,CAAC,CAAC;QAEH,OAAO,WAAW,CAAC;IACrB,CAAC;IAEO,wBAAwB,CAAC,GAAW;QAC1C,YAAY,CAAC,IAAI,CAAC,wBAAwB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QACrD,IAAI,CAAC,wBAAwB,CAAC,GAAG,CAC/B,GAAG,EACH,UAAU,CAAC,GAAG,EAAE;YACd,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;YACvB,IAAI,CAAC,wBAAwB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC5C,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,CACvB,CAAC;IACJ,CAAC;CACF","sourcesContent":["import type { Subscription } from \"rxjs\";\nimport { EMPTY, Observable } from \"rxjs\";\n\nimport type { FetchResult, NextLink, Operation } from \"@apollo/client/link\";\n\nexport type BatchHandler = (\n operations: Operation[],\n forward?: (NextLink | undefined)[]\n) => Observable<FetchResult[]> | null;\n\nexport interface BatchableRequest {\n operation: Operation;\n forward?: NextLink;\n}\n\ntype QueuedRequest = BatchableRequest & {\n observable?: Observable<FetchResult>;\n next: Array<(result: FetchResult) => void>;\n error: Array<(error: Error) => void>;\n complete: Array<() => void>;\n subscribers: Set<object>;\n};\n\n// Batches are primarily a Set<QueuedRequest>, but may have other optional\n// properties, such as batch.subscription.\ntype RequestBatch = Set<QueuedRequest> & {\n subscription?: Subscription;\n};\n\n// QueryBatcher doesn't fire requests immediately. Requests that were enqueued within\n// a certain amount of time (configurable through `batchInterval`) will be batched together\n// into one query.\nexport class OperationBatcher {\n // Queue on which the QueryBatcher will operate on a per-tick basis.\n private batchesByKey = new Map<string, RequestBatch>();\n\n private scheduledBatchTimerByKey = new Map<\n string,\n ReturnType<typeof setTimeout>\n >();\n private batchDebounce?: boolean;\n private batchInterval?: number;\n private batchMax: number;\n\n //This function is called to the queries in the queue to the server.\n private batchHandler: BatchHandler;\n private batchKey: (operation: Operation) => string;\n\n constructor({\n batchDebounce,\n batchInterval,\n batchMax,\n batchHandler,\n batchKey,\n }: {\n batchDebounce?: boolean;\n batchInterval?: number;\n batchMax?: number;\n batchHandler: BatchHandler;\n batchKey?: (operation: Operation) => string;\n }) {\n this.batchDebounce = batchDebounce;\n this.batchInterval = batchInterval;\n this.batchMax = batchMax || 0;\n this.batchHandler = batchHandler;\n this.batchKey = batchKey || (() => \"\");\n }\n\n public enqueueRequest(request: BatchableRequest): Observable<FetchResult> {\n const requestCopy: QueuedRequest = {\n ...request,\n next: [],\n error: [],\n complete: [],\n subscribers: new Set(),\n };\n\n const key = this.batchKey(request.operation);\n\n if (!requestCopy.observable) {\n requestCopy.observable = new Observable<FetchResult>((observer) => {\n let batch = this.batchesByKey.get(key)!;\n if (!batch) this.batchesByKey.set(key, (batch = new Set()));\n\n // These booleans seem to me (@benjamn) like they might always be the\n // same (and thus we could do with only one of them), but I'm not 100%\n // sure about that.\n const isFirstEnqueuedRequest = batch.size === 0;\n const isFirstSubscriber = requestCopy.subscribers.size === 0;\n requestCopy.subscribers.add(observer);\n if (isFirstSubscriber) {\n batch.add(requestCopy);\n }\n\n // called for each subscriber, so need to save all listeners (next, error, complete)\n if (observer.next) {\n requestCopy.next.push(observer.next.bind(observer));\n }\n\n if (observer.error) {\n requestCopy.error.push(observer.error.bind(observer));\n }\n\n if (observer.complete) {\n requestCopy.complete.push(observer.complete.bind(observer));\n }\n\n // The first enqueued request triggers the queue consumption after `batchInterval` milliseconds.\n if (isFirstEnqueuedRequest || this.batchDebounce) {\n this.scheduleQueueConsumption(key);\n }\n\n // When amount of requests reaches `batchMax`, trigger the queue consumption without waiting on the `batchInterval`.\n if (batch.size === this.batchMax) {\n this.consumeQueue(key);\n }\n\n return () => {\n // If this is last subscriber for this request, remove request from queue\n if (\n requestCopy.subscribers.delete(observer) &&\n requestCopy.subscribers.size < 1\n ) {\n // If this is last request from queue, remove queue entirely\n if (batch.delete(requestCopy) && batch.size < 1) {\n this.consumeQueue(key);\n // If queue was in flight, cancel it\n batch.subscription?.unsubscribe();\n }\n }\n };\n });\n }\n\n return requestCopy.observable;\n }\n\n // Consumes the queue.\n // Returns a list of promises (one for each query).\n public consumeQueue(\n key: string = \"\"\n ): (Observable<FetchResult> | undefined)[] | undefined {\n const batch = this.batchesByKey.get(key);\n // Delete this batch and process it below.\n this.batchesByKey.delete(key);\n if (!batch || !batch.size) {\n // No requests to be processed.\n return;\n }\n\n const operations: QueuedRequest[\"operation\"][] = [];\n const forwards: QueuedRequest[\"forward\"][] = [];\n const observables: QueuedRequest[\"observable\"][] = [];\n const nexts: QueuedRequest[\"next\"][] = [];\n const errors: QueuedRequest[\"error\"][] = [];\n const completes: QueuedRequest[\"complete\"][] = [];\n\n // Even though batch is a Set, it preserves the order of first insertion\n // when iterating (per ECMAScript specification), so these requests will be\n // handled in the order they were enqueued (minus any deleted ones).\n batch.forEach((request) => {\n operations.push(request.operation);\n forwards.push(request.forward);\n observables.push(request.observable);\n nexts.push(request.next);\n errors.push(request.error);\n completes.push(request.complete);\n });\n\n const batchedObservable = this.batchHandler(operations, forwards) || EMPTY;\n\n const onError = (error: Error) => {\n //each callback list in batch\n errors.forEach((rejecters) => {\n if (rejecters) {\n //each subscriber to request\n rejecters.forEach((e) => e(error));\n }\n });\n };\n\n batch.subscription = batchedObservable.subscribe({\n next: (results) => {\n if (!Array.isArray(results)) {\n results = [results];\n }\n\n if (nexts.length !== results.length) {\n const error = new Error(\n `server returned results with length ${results.length}, expected length of ${nexts.length}`\n );\n (error as any).result = results;\n\n return onError(error);\n }\n\n results.forEach((result, index) => {\n if (nexts[index]) {\n nexts[index].forEach((next) => next(result));\n }\n });\n },\n error: onError,\n complete: () => {\n completes.forEach((complete) => {\n if (complete) {\n //each subscriber to request\n complete.forEach((c) => c());\n }\n });\n },\n });\n\n return observables;\n }\n\n private scheduleQueueConsumption(key: string): void {\n clearTimeout(this.scheduledBatchTimerByKey.get(key));\n this.scheduledBatchTimerByKey.set(\n key,\n setTimeout(() => {\n this.consumeQueue(key);\n this.scheduledBatchTimerByKey.delete(key);\n }, this.batchInterval)\n );\n }\n}\n"]}
1
+ {"version":3,"file":"batching.js","sourceRoot":"","sources":["../../../src/link/batch/batching.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AA4BlC,qFAAqF;AACrF,2FAA2F;AAC3F,kBAAkB;AAClB,MAAM,OAAO,gBAAgB;IAC3B,oEAAoE;IAC5D,YAAY,GAAG,IAAI,GAAG,EAAwB,CAAC;IAE/C,wBAAwB,GAAG,IAAI,GAAG,EAGvC,CAAC;IACI,aAAa,CAAW;IACxB,aAAa,CAAU;IACvB,QAAQ,CAAS;IAEzB,oEAAoE;IAC5D,YAAY,CAAe;IAC3B,QAAQ,CAA8C;IAE9D,YAAY,EACV,aAAa,EACb,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,QAAQ,GAOT;QACC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,QAAQ,GAAG,QAAQ,IAAI,CAAC,CAAC;QAC9B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,QAAQ,GAAG,QAAQ,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;IACzC,CAAC;IAEM,cAAc,CACnB,OAAyB;QAEzB,MAAM,WAAW,GAAkB;YACjC,GAAG,OAAO;YACV,IAAI,EAAE,EAAE;YACR,KAAK,EAAE,EAAE;YACT,QAAQ,EAAE,EAAE;YACZ,WAAW,EAAE,IAA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CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC5C,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,CACvB,CAAC;IACJ,CAAC;CACF","sourcesContent":["import type { Subscription } from \"rxjs\";\nimport { Observable } from \"rxjs\";\n\nimport type { ApolloLink } from \"@apollo/client/link\";\n\nexport type BatchHandler = (\n operations: ApolloLink.Operation[],\n forward: ApolloLink.ForwardFunction[]\n) => Observable<ApolloLink.Result[]>;\n\nexport interface BatchableRequest {\n operation: ApolloLink.Operation;\n forward: ApolloLink.ForwardFunction;\n}\n\ntype QueuedRequest = BatchableRequest & {\n observable?: Observable<ApolloLink.Result>;\n next: Array<(result: ApolloLink.Result) => void>;\n error: Array<(error: Error) => void>;\n complete: Array<() => void>;\n subscribers: Set<object>;\n};\n\n// Batches are primarily a Set<QueuedRequest>, but may have other optional\n// properties, such as batch.subscription.\ntype RequestBatch = Set<QueuedRequest> & {\n subscription?: Subscription;\n};\n\n// QueryBatcher doesn't fire requests immediately. Requests that were enqueued within\n// a certain amount of time (configurable through `batchInterval`) will be batched together\n// into one query.\nexport class OperationBatcher {\n // Queue on which the QueryBatcher will operate on a per-tick basis.\n private batchesByKey = new Map<string, RequestBatch>();\n\n private scheduledBatchTimerByKey = new Map<\n string,\n ReturnType<typeof setTimeout>\n >();\n private batchDebounce?: boolean;\n private batchInterval?: number;\n private batchMax: number;\n\n //This function is called to the queries in the queue to the server.\n private batchHandler: BatchHandler;\n private batchKey: (operation: ApolloLink.Operation) => string;\n\n constructor({\n batchDebounce,\n batchInterval,\n batchMax,\n batchHandler,\n batchKey,\n }: {\n batchDebounce?: boolean;\n batchInterval?: number;\n batchMax?: number;\n batchHandler: BatchHandler;\n batchKey?: (operation: ApolloLink.Operation) => string;\n }) {\n this.batchDebounce = batchDebounce;\n this.batchInterval = batchInterval;\n this.batchMax = batchMax || 0;\n this.batchHandler = batchHandler;\n this.batchKey = batchKey || (() => \"\");\n }\n\n public enqueueRequest(\n request: BatchableRequest\n ): Observable<ApolloLink.Result> {\n const requestCopy: QueuedRequest = {\n ...request,\n next: [],\n error: [],\n complete: [],\n subscribers: new Set(),\n };\n\n const key = this.batchKey(request.operation);\n\n if (!requestCopy.observable) {\n requestCopy.observable = new Observable<ApolloLink.Result>((observer) => {\n let batch = this.batchesByKey.get(key)!;\n if (!batch) this.batchesByKey.set(key, (batch = new Set()));\n\n // These booleans seem to me (@benjamn) like they might always be the\n // same (and thus we could do with only one of them), but I'm not 100%\n // sure about that.\n const isFirstEnqueuedRequest = batch.size === 0;\n const isFirstSubscriber = requestCopy.subscribers.size === 0;\n requestCopy.subscribers.add(observer);\n if (isFirstSubscriber) {\n batch.add(requestCopy);\n }\n\n // called for each subscriber, so need to save all listeners (next, error, complete)\n if (observer.next) {\n requestCopy.next.push(observer.next.bind(observer));\n }\n\n if (observer.error) {\n requestCopy.error.push(observer.error.bind(observer));\n }\n\n if (observer.complete) {\n requestCopy.complete.push(observer.complete.bind(observer));\n }\n\n // The first enqueued request triggers the queue consumption after `batchInterval` milliseconds.\n if (isFirstEnqueuedRequest || this.batchDebounce) {\n this.scheduleQueueConsumption(key);\n }\n\n // When amount of requests reaches `batchMax`, trigger the queue consumption without waiting on the `batchInterval`.\n if (batch.size === this.batchMax) {\n this.consumeQueue(key);\n }\n\n return () => {\n // If this is last subscriber for this request, remove request from queue\n if (\n requestCopy.subscribers.delete(observer) &&\n requestCopy.subscribers.size < 1\n ) {\n // If this is last request from queue, remove queue entirely\n if (batch.delete(requestCopy) && batch.size < 1) {\n this.consumeQueue(key);\n // If queue was in flight, cancel it\n batch.subscription?.unsubscribe();\n }\n }\n };\n });\n }\n\n return requestCopy.observable;\n }\n\n // Consumes the queue.\n // Returns a list of promises (one for each query).\n public consumeQueue(\n key: string = \"\"\n ): (Observable<ApolloLink.Result> | undefined)[] | undefined {\n const batch = this.batchesByKey.get(key);\n // Delete this batch and process it below.\n this.batchesByKey.delete(key);\n if (!batch || !batch.size) {\n // No requests to be processed.\n return;\n }\n\n const operations: QueuedRequest[\"operation\"][] = [];\n const forwards: QueuedRequest[\"forward\"][] = [];\n const observables: QueuedRequest[\"observable\"][] = [];\n const nexts: QueuedRequest[\"next\"][] = [];\n const errors: QueuedRequest[\"error\"][] = [];\n const completes: QueuedRequest[\"complete\"][] = [];\n\n // Even though batch is a Set, it preserves the order of first insertion\n // when iterating (per ECMAScript specification), so these requests will be\n // handled in the order they were enqueued (minus any deleted ones).\n batch.forEach((request) => {\n operations.push(request.operation);\n forwards.push(request.forward);\n observables.push(request.observable);\n nexts.push(request.next);\n errors.push(request.error);\n completes.push(request.complete);\n });\n\n const batchedObservable = this.batchHandler(operations, forwards);\n\n const onError = (error: Error) => {\n //each callback list in batch\n errors.forEach((rejecters) => {\n if (rejecters) {\n //each subscriber to request\n rejecters.forEach((e) => e(error));\n }\n });\n };\n\n batch.subscription = batchedObservable.subscribe({\n next: (results) => {\n if (!Array.isArray(results)) {\n results = [results];\n }\n\n if (nexts.length !== results.length) {\n const error = new Error(\n `server returned results with length ${results.length}, expected length of ${nexts.length}`\n );\n (error as any).result = results;\n\n return onError(error);\n }\n\n results.forEach((result, index) => {\n if (nexts[index]) {\n nexts[index].forEach((next) => next(result));\n }\n });\n },\n error: onError,\n complete: () => {\n completes.forEach((complete) => {\n if (complete) {\n //each subscriber to request\n complete.forEach((c) => c());\n }\n });\n },\n });\n\n return observables;\n }\n\n private scheduleQueueConsumption(key: string): void {\n clearTimeout(this.scheduledBatchTimerByKey.get(key));\n this.scheduledBatchTimerByKey.set(\n key,\n setTimeout(() => {\n this.consumeQueue(key);\n this.scheduledBatchTimerByKey.delete(key);\n }, this.batchInterval)\n );\n }\n}\n"]}
@@ -1,5 +1,4 @@
1
1
  import { Observable } from "rxjs";
2
- import type { FetchResult, Operation } from "@apollo/client/link";
3
2
  import { ApolloLink } from "@apollo/client/link";
4
3
  import { BatchLink } from "@apollo/client/link/batch";
5
4
  import { ClientAwarenessLink } from "@apollo/client/link/client-awareness";
@@ -21,6 +20,6 @@ export declare class BaseBatchHttpLink extends ApolloLink {
21
20
  private batchMax;
22
21
  private batcher;
23
22
  constructor(fetchParams?: BatchHttpLink.Options);
24
- request(operation: Operation): Observable<FetchResult> | null;
23
+ request(operation: ApolloLink.Operation, forward: ApolloLink.ForwardFunction): Observable<ApolloLink.Result>;
25
24
  }
26
25
  //# sourceMappingURL=batchHttpLink.d.ts.map
@@ -3,10 +3,10 @@ import { ApolloLink } from "@apollo/client/link";
3
3
  import { BatchLink } from "@apollo/client/link/batch";
4
4
  import { ClientAwarenessLink } from "@apollo/client/link/client-awareness";
5
5
  import { checkFetcher, defaultPrinter, fallbackHttpConfig, parseAndCheckHttpResponse, selectHttpOptionsAndBodyInternal, selectURI, serializeFetchParameter, } from "@apollo/client/link/http";
6
+ import { filterOperationVariables } from "@apollo/client/link/utils";
6
7
  import { __DEV__ } from "@apollo/client/utilities/environment";
7
8
  import { compact } from "@apollo/client/utilities/internal";
8
9
  import { maybe } from "@apollo/client/utilities/internal/globals";
9
- import { filterOperationVariables } from "../utils/filterOperationVariables.js";
10
10
  const backupFetch = maybe(() => fetch);
11
11
  /**
12
12
  * Transforms Operation for into HTTP results.
@@ -14,7 +14,10 @@ const backupFetch = maybe(() => fetch);
14
14
  */
15
15
  export class BatchHttpLink extends ApolloLink {
16
16
  constructor(options = {}) {
17
- const { left, right, request } = ApolloLink.concat(new ClientAwarenessLink(options), new BaseBatchHttpLink(options));
17
+ const { left, right, request } = ApolloLink.from([
18
+ new ClientAwarenessLink(options),
19
+ new BaseBatchHttpLink(options),
20
+ ]);
18
21
  super(request);
19
22
  Object.assign(this, { left, right });
20
23
  }
@@ -132,8 +135,8 @@ export class BaseBatchHttpLink extends ApolloLink {
132
135
  batchHandler,
133
136
  });
134
137
  }
135
- request(operation) {
136
- return this.batcher.request(operation);
138
+ request(operation, forward) {
139
+ return this.batcher.request(operation, forward);
137
140
  }
138
141
  }
139
142
  //# sourceMappingURL=batchHttpLink.js.map
@@ -1 +1 @@
1
- {"version":3,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Y;wBAC7B,WAAW,EAAE,OAAO,CAAC,WAAW;wBAChC,OAAO,EAAE,OAAO,CAAC,OAAO;qBACzB,CAAC;oBAEF,4CAA4C;oBAC5C,OAAO,SAAS,CAAC,SAAS,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;gBACnE,CAAC,CAAC,CAAC;QAEL,IAAI,CAAC,OAAO,GAAG,IAAI,SAAS,CAAC;YAC3B,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,QAAQ;YACR,YAAY;SACb,CAAC,CAAC;IACL,CAAC;IAEM,OAAO,CAAC,SAAoB;QACjC,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACzC,CAAC;CACF","sourcesContent":["import { Observable, throwError } from \"rxjs\";\n\nimport type { FetchResult, Operation } from \"@apollo/client/link\";\nimport { ApolloLink } from \"@apollo/client/link\";\nimport type { BatchHandler } from \"@apollo/client/link/batch\";\nimport { BatchLink } from \"@apollo/client/link/batch\";\nimport { ClientAwarenessLink } from \"@apollo/client/link/client-awareness\";\nimport type { HttpLink } from \"@apollo/client/link/http\";\nimport {\n checkFetcher,\n defaultPrinter,\n fallbackHttpConfig,\n parseAndCheckHttpResponse,\n selectHttpOptionsAndBodyInternal,\n selectURI,\n serializeFetchParameter,\n} from \"@apollo/client/link/http\";\nimport { __DEV__ } from \"@apollo/client/utilities/environment\";\nimport { compact } from \"@apollo/client/utilities/internal\";\nimport { maybe } from \"@apollo/client/utilities/internal/globals\";\n\nimport { filterOperationVariables } from \"../utils/filterOperationVariables.js\";\n\nexport namespace BatchHttpLink {\n export type Options = Pick<\n BatchLink.Options,\n \"batchMax\" | \"batchDebounce\" | \"batchInterval\" | \"batchKey\"\n > &\n Omit<HttpLink.Options, \"useGETForQueries\">;\n\n export type ContextOptions = HttpLink.ContextOptions;\n}\n\nconst backupFetch = maybe(() => fetch);\n\n/**\n * Transforms Operation for into HTTP results.\n * context can include the headers property, which will be passed to the fetch function\n */\nexport class BatchHttpLink extends ApolloLink {\n constructor(\n options: BatchHttpLink.Options & ClientAwarenessLink.Options = {}\n ) {\n const { left, right, request } = ApolloLink.concat(\n new ClientAwarenessLink(options),\n new BaseBatchHttpLink(options)\n );\n super(request);\n Object.assign(this, { left, right });\n }\n}\nexport class BaseBatchHttpLink extends ApolloLink {\n private batchDebounce?: boolean;\n private batchInterval: number;\n private batchMax: number;\n private batcher: ApolloLink;\n\n constructor(fetchParams?: BatchHttpLink.Options) {\n super();\n\n let {\n uri = \"/graphql\",\n // use default global fetch if nothing is passed in\n fetch: preferredFetch,\n print = defaultPrinter,\n includeExtensions,\n preserveHeaderCase,\n batchInterval,\n batchDebounce,\n batchMax,\n batchKey,\n includeUnusedVariables = false,\n ...requestOptions\n } = fetchParams || ({} as BatchHttpLink.Options);\n\n if (__DEV__) {\n // Make sure at least one of preferredFetch, window.fetch, or backupFetch\n // is defined, so requests won't fail at runtime.\n checkFetcher(preferredFetch || backupFetch);\n }\n\n const linkConfig = {\n http: compact({ includeExtensions, preserveHeaderCase }),\n options: requestOptions.fetchOptions,\n credentials: requestOptions.credentials,\n headers: requestOptions.headers,\n };\n\n this.batchDebounce = batchDebounce;\n this.batchInterval = batchInterval || 10;\n this.batchMax = batchMax || 10;\n\n const batchHandler: BatchHandler = (operations) => {\n const chosenURI = selectURI(operations[0], uri);\n\n const context = operations[0].getContext();\n\n const contextConfig = {\n http: context.http,\n options: context.fetchOptions,\n credentials: context.credentials,\n headers: context.headers,\n };\n\n //uses fallback, link, and then context to build options\n const optsAndBody = operations.map((operation) => {\n const result = selectHttpOptionsAndBodyInternal(\n operation,\n print,\n fallbackHttpConfig,\n linkConfig,\n contextConfig\n );\n\n if (result.body.variables && !includeUnusedVariables) {\n result.body.variables = filterOperationVariables(\n result.body.variables,\n operation.query\n );\n }\n\n return result;\n });\n\n const loadedBody = optsAndBody.map(({ body }) => body);\n const options = optsAndBody[0].options;\n\n // There's no spec for using GET with batches.\n if (options.method === \"GET\") {\n return throwError(\n () =>\n new Error(\"apollo-link-batch-http does not support GET requests\")\n );\n }\n\n try {\n (options as any).body = serializeFetchParameter(loadedBody, \"Payload\");\n } catch (parseError) {\n return throwError(() => parseError);\n }\n\n let controller: AbortController | undefined;\n if (!options.signal && typeof AbortController !== \"undefined\") {\n controller = new AbortController();\n options.signal = controller.signal;\n }\n\n return new Observable((observer) => {\n // Prefer BatchHttpLink.Options.fetch (preferredFetch) if provided, and\n // otherwise fall back to the *current* global window.fetch function\n // (see issue #7832), or (if all else fails) the backupFetch function we\n // saved when this module was first evaluated. This last option protects\n // against the removal of window.fetch, which is unlikely but not\n // impossible.\n const currentFetch =\n preferredFetch || maybe(() => fetch) || backupFetch;\n\n currentFetch!(chosenURI, options)\n .then((response) => {\n // Make the raw response available in the context.\n operations.forEach((operation) =>\n operation.setContext({ response })\n );\n return response;\n })\n .then(parseAndCheckHttpResponse(operations))\n .then((result) => {\n controller = undefined;\n // we have data and can send it to back up the link chain\n observer.next(result);\n observer.complete();\n return result;\n })\n .catch((err) => {\n controller = undefined;\n observer.error(err);\n });\n\n return () => {\n // XXX support canceling this request\n // https://developers.google.com/web/updates/2017/09/abortable-fetch\n if (controller) controller.abort();\n };\n });\n };\n\n batchKey =\n batchKey ||\n ((operation: Operation) => {\n const context = operation.getContext();\n\n const contextConfig = {\n http: context.http,\n options: context.fetchOptions,\n credentials: context.credentials,\n headers: context.headers,\n };\n\n //may throw error if config not serializable\n return selectURI(operation, uri) + JSON.stringify(contextConfig);\n });\n\n this.batcher = new BatchLink({\n batchDebounce: this.batchDebounce,\n batchInterval: this.batchInterval,\n batchMax: this.batchMax,\n batchKey,\n batchHandler,\n });\n }\n\n public request(operation: Operation): Observable<FetchResult> | null {\n return this.batcher.request(operation);\n }\n}\n"]}
1
+ {"version":3,"file":"batchHttpLink.js","sourceRoot":"","sources":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AAE,OAAO,CAAC,WAAW;wBAChC,OAAO,EAAE,OAAO,CAAC,OAAO;qBACzB,CAAC;oBAEF,4CAA4C;oBAC5C,OAAO,SAAS,CAAC,SAAS,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;gBACnE,CAAC,CAAC,CAAC;QAEL,IAAI,CAAC,OAAO,GAAG,IAAI,SAAS,CAAC;YAC3B,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,QAAQ;YACR,YAAY;SACb,CAAC,CAAC;IACL,CAAC;IAEM,OAAO,CACZ,SAA+B,EAC/B,OAAmC;QAEnC,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC;CACF","sourcesContent":["import { Observable, throwError } from \"rxjs\";\n\nimport { ApolloLink } from \"@apollo/client/link\";\nimport type { BatchHandler } from \"@apollo/client/link/batch\";\nimport { BatchLink } from \"@apollo/client/link/batch\";\nimport { ClientAwarenessLink } from \"@apollo/client/link/client-awareness\";\nimport type { HttpLink } from \"@apollo/client/link/http\";\nimport {\n checkFetcher,\n defaultPrinter,\n fallbackHttpConfig,\n parseAndCheckHttpResponse,\n selectHttpOptionsAndBodyInternal,\n selectURI,\n serializeFetchParameter,\n} from \"@apollo/client/link/http\";\nimport { filterOperationVariables } from \"@apollo/client/link/utils\";\nimport { __DEV__ } from \"@apollo/client/utilities/environment\";\nimport { compact } from \"@apollo/client/utilities/internal\";\nimport { maybe } from \"@apollo/client/utilities/internal/globals\";\n\nexport declare namespace BatchHttpLink {\n export type Options = Pick<\n BatchLink.Options,\n \"batchMax\" | \"batchDebounce\" | \"batchInterval\" | \"batchKey\"\n > &\n Omit<HttpLink.Options, \"useGETForQueries\">;\n\n export type ContextOptions = HttpLink.ContextOptions;\n}\n\nconst backupFetch = maybe(() => fetch);\n\n/**\n * Transforms Operation for into HTTP results.\n * context can include the headers property, which will be passed to the fetch function\n */\nexport class BatchHttpLink extends ApolloLink {\n constructor(\n options: BatchHttpLink.Options & ClientAwarenessLink.Options = {}\n ) {\n const { left, right, request } = ApolloLink.from([\n new ClientAwarenessLink(options),\n new BaseBatchHttpLink(options),\n ]);\n super(request);\n Object.assign(this, { left, right });\n }\n}\nexport class BaseBatchHttpLink extends ApolloLink {\n private batchDebounce?: boolean;\n private batchInterval: number;\n private batchMax: number;\n private batcher: ApolloLink;\n\n constructor(fetchParams?: BatchHttpLink.Options) {\n super();\n\n let {\n uri = \"/graphql\",\n // use default global fetch if nothing is passed in\n fetch: preferredFetch,\n print = defaultPrinter,\n includeExtensions,\n preserveHeaderCase,\n batchInterval,\n batchDebounce,\n batchMax,\n batchKey,\n includeUnusedVariables = false,\n ...requestOptions\n } = fetchParams || ({} as BatchHttpLink.Options);\n\n if (__DEV__) {\n // Make sure at least one of preferredFetch, window.fetch, or backupFetch\n // is defined, so requests won't fail at runtime.\n checkFetcher(preferredFetch || backupFetch);\n }\n\n const linkConfig = {\n http: compact({ includeExtensions, preserveHeaderCase }),\n options: requestOptions.fetchOptions,\n credentials: requestOptions.credentials,\n headers: requestOptions.headers,\n };\n\n this.batchDebounce = batchDebounce;\n this.batchInterval = batchInterval || 10;\n this.batchMax = batchMax || 10;\n\n const batchHandler: BatchHandler = (operations) => {\n const chosenURI = selectURI(operations[0], uri);\n\n const context = operations[0].getContext();\n\n const contextConfig = {\n http: context.http,\n options: context.fetchOptions,\n credentials: context.credentials,\n headers: context.headers,\n };\n\n //uses fallback, link, and then context to build options\n const optsAndBody = operations.map((operation) => {\n const result = selectHttpOptionsAndBodyInternal(\n operation,\n print,\n fallbackHttpConfig,\n linkConfig,\n contextConfig\n );\n\n if (result.body.variables && !includeUnusedVariables) {\n result.body.variables = filterOperationVariables(\n result.body.variables,\n operation.query\n );\n }\n\n return result;\n });\n\n const loadedBody = optsAndBody.map(({ body }) => body);\n const options = optsAndBody[0].options;\n\n // There's no spec for using GET with batches.\n if (options.method === \"GET\") {\n return throwError(\n () =>\n new Error(\"apollo-link-batch-http does not support GET requests\")\n );\n }\n\n try {\n (options as any).body = serializeFetchParameter(loadedBody, \"Payload\");\n } catch (parseError) {\n return throwError(() => parseError);\n }\n\n let controller: AbortController | undefined;\n if (!options.signal && typeof AbortController !== \"undefined\") {\n controller = new AbortController();\n options.signal = controller.signal;\n }\n\n return new Observable((observer) => {\n // Prefer BatchHttpLink.Options.fetch (preferredFetch) if provided, and\n // otherwise fall back to the *current* global window.fetch function\n // (see issue #7832), or (if all else fails) the backupFetch function we\n // saved when this module was first evaluated. This last option protects\n // against the removal of window.fetch, which is unlikely but not\n // impossible.\n const currentFetch =\n preferredFetch || maybe(() => fetch) || backupFetch;\n\n currentFetch!(chosenURI, options)\n .then((response) => {\n // Make the raw response available in the context.\n operations.forEach((operation) =>\n operation.setContext({ response })\n );\n return response;\n })\n .then(parseAndCheckHttpResponse(operations))\n .then((result) => {\n controller = undefined;\n // we have data and can send it to back up the link chain\n observer.next(result);\n observer.complete();\n return result;\n })\n .catch((err) => {\n controller = undefined;\n observer.error(err);\n });\n\n return () => {\n // XXX support canceling this request\n // https://developers.google.com/web/updates/2017/09/abortable-fetch\n if (controller) controller.abort();\n };\n });\n };\n\n batchKey =\n batchKey ||\n ((operation: ApolloLink.Operation) => {\n const context = operation.getContext();\n\n const contextConfig = {\n http: context.http,\n options: context.fetchOptions,\n credentials: context.credentials,\n headers: context.headers,\n };\n\n //may throw error if config not serializable\n return selectURI(operation, uri) + JSON.stringify(contextConfig);\n });\n\n this.batcher = new BatchLink({\n batchDebounce: this.batchDebounce,\n batchInterval: this.batchInterval,\n batchMax: this.batchMax,\n batchKey,\n batchHandler,\n });\n }\n\n public request(\n operation: ApolloLink.Operation,\n forward: ApolloLink.ForwardFunction\n ): Observable<ApolloLink.Result> {\n return this.batcher.request(operation, forward);\n }\n}\n"]}
@@ -21,8 +21,8 @@ export declare namespace ClientAwarenessLink {
21
21
  * If `name` and `version` are not provided, this option will be ignored.
22
22
  * (These options can either be set as part of the Apollo Client constructor call or when manually constructing a `HttpLink`, `BatchHttpLink` or `ClientAwarenessLink`.)
23
23
  *
24
- * * If set to `"headers"`, `name` and `version` will be sent in the request headers as `apollographql-client-name` and `apollographql-client-version`, respectively.
25
- * * If set to `false`, `name` and `version` will not be included in outgoing requests.
24
+ * - If set to `"headers"`, `name` and `version` will be sent in the request headers as `apollographql-client-name` and `apollographql-client-version`, respectively.
25
+ * - If set to `false`, `name` and `version` will not be included in outgoing requests.
26
26
  *
27
27
  * @defaultValue "headers"
28
28
  */
@@ -32,8 +32,8 @@ export declare namespace ClientAwarenessLink {
32
32
  /**
33
33
  * Determines how the the version information of Apollo Client is sent in outgoing requests.
34
34
  *
35
- * * If set to `"extensions"`, library `name` and `version` will be sent in an object in the request extensions as `clientLibrary`.
36
- * * If set to `false`, library name and version will not be included in outgoing requests.
35
+ * - If set to `"extensions"`, library `name` and `version` will be sent in an object in the request extensions as `clientLibrary`.
36
+ * - If set to `false`, library name and version will not be included in outgoing requests.
37
37
  *
38
38
  * @defaultValue "extensions"
39
39
  */
@@ -1 +1 @@
1
- {"version":3,"file":"ClientAwarenessLink.js","sourceRoot":"","sources":["../../../src/link/client-awareness/ClientAwarenessLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AA6D5D,MAAM,OAAO,mBAAoB,SAAQ,UAAU;IACjD,YAAY,qBAAkD,EAAE;QAC9D,KAAK,CAAC,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE;YAC3B,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC;YAEhC,MAAM,aAAa,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC,aAAa,CAAC;YAC3D,MAAM,OAAO,GAAG,SAAS,CAAC,UAAU,EAAE,CAAC;YACvC,CAAC;gBACC,MAAM,EACJ,IAAI,EACJ,OAAO,EACP,SAAS,GAAG,SAAS,GACtB,GAAG,OAAO,CACT,EAAE,EACF,aAAa,CAAC,eAAe,EAC7B,kBAAkB,CAAC,eAAe,EAClC,OAAO,CAAC,eAAe,CACxB,CAAC;gBAEF,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;oBAC5B,SAAS,CAAC,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE;wBAC/C,OAAO;4BACL,OAAO,EAAE,OAAO;4BACd,8EAA8E;4BAC9E;gCACE,2BAA2B,EAAE,IAAI;gCACjC,8BAA8B,EAAE,OAAO;6BACxC,EACD,OAAO,CACR;yBACF,CAAC;oBACJ,CAAC,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;YACD,CAAC;gBACC,MAAM,EAAE,SAAS,GAAG,YAAY,EAAE,GAAG,OAAO,CAC1C,EAAE,EACF,aAAa,CAAC,uBAAuB,EACrC,kBAAkB,CAAC,uBAAuB,CAC3C,CAAC;gBACF,IAAI,SAAS,KAAK,YAAY,EAAE,CAAC;oBAC/B,SAAS,CAAC,UAAU,GAAG,OAAO;oBAC5B,+EAA+E;oBAC/E;wBACE,aAAa,EAAE;4BACb,IAAI,EAAE,gBAAgB;4BACtB,OAAO,EAAE,MAAM,CAAC,OAAO;yBACxB;qBACF,EACD,SAAS,CAAC,UAAU,CACrB,CAAC;gBACJ,CAAC;YACH,CAAC;YAED,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { ApolloLink } from \"@apollo/client/link\";\nimport { compact } from \"@apollo/client/utilities/internal\";\n\nexport declare namespace ClientAwarenessLink {\n export interface ClientAwarenessOptions {\n /**\n * A custom name (e.g., `iOS`) that identifies this particular client among your set of clients. Apollo Server and Apollo Studio use this property as part of the [client awareness](https://www.apollographql.com/docs/apollo-server/monitoring/metrics#identifying-distinct-clients) feature.\n *\n * This option can either be set as part of the Apollo Client constructor call or when manually constructing a `HttpLink`, `BatchHttpLink` or `ClientAwarenessLink`.\n */\n name?: string;\n /**\n * A custom version that identifies the current version of this particular client (e.g., `1.2`). Apollo Server and Apollo Studio use this property as part of the [client awareness](https://www.apollographql.com/docs/apollo-server/monitoring/metrics#identifying-distinct-clients) feature.\n *\n * This is **not** the version of Apollo Client that you are using, but rather any version string that helps you differentiate between versions of your client.\n *\n * This option can either be set as part of the Apollo Client constructor call or when manually constructing a `HttpLink`, `BatchHttpLink` or `ClientAwarenessLink`.\n */\n version?: string;\n /**\n * Determines how `name` and `version` are sent in outgoing requests.\n *\n * If `name` and `version` are not provided, this option will be ignored.\n * (These options can either be set as part of the Apollo Client constructor call or when manually constructing a `HttpLink`, `BatchHttpLink` or `ClientAwarenessLink`.)\n *\n * * If set to `\"headers\"`, `name` and `version` will be sent in the request headers as `apollographql-client-name` and `apollographql-client-version`, respectively.\n * * If set to `false`, `name` and `version` will not be included in outgoing requests.\n *\n * @defaultValue \"headers\"\n */\n transport?: \"headers\" | false;\n }\n export interface EnhancedClientAwarenessOptions {\n /**\n * Determines how the the version information of Apollo Client is sent in outgoing requests.\n *\n * * If set to `\"extensions\"`, library `name` and `version` will be sent in an object in the request extensions as `clientLibrary`.\n * * If set to `false`, library name and version will not be included in outgoing requests.\n *\n * @defaultValue \"extensions\"\n */\n transport?: \"extensions\" | false;\n }\n\n export interface Options {\n /**\n * Configures the \"client awareness\" feature.\n * This feature allows you to identify distinct applications in Apollo Studio\n * and Apollo Server logs (and other monitoring or analytics tools) by adding\n * information about the your application to outgoing requests.\n */\n clientAwareness?: ClientAwarenessOptions;\n /**\n * Configures the \"enhanced client awareness\" feature.\n * This feature allows you to identify the version of the Apollo Client library\n * used in your application in Apollo Studio (and other monitoring or analytics tools)\n * by adding information about the Apollo Client library to outgoing requests.\n */\n enhancedClientAwareness?: EnhancedClientAwarenessOptions;\n }\n}\n\nexport class ClientAwarenessLink extends ApolloLink {\n constructor(constructorOptions: ClientAwarenessLink.Options = {}) {\n super((operation, forward) => {\n const client = operation.client;\n\n const clientOptions = client[\"queryManager\"].clientOptions;\n const context = operation.getContext();\n {\n const {\n name,\n version,\n transport = \"headers\",\n } = compact(\n {},\n clientOptions.clientAwareness,\n constructorOptions.clientAwareness,\n context.clientAwareness\n );\n\n if (transport === \"headers\") {\n operation.setContext(({ headers, extensions }) => {\n return {\n headers: compact(\n // setting these first so that they can be overridden by user-provided headers\n {\n \"apollographql-client-name\": name,\n \"apollographql-client-version\": version,\n },\n headers\n ),\n };\n });\n }\n }\n {\n const { transport = \"extensions\" } = compact(\n {},\n clientOptions.enhancedClientAwareness,\n constructorOptions.enhancedClientAwareness\n );\n if (transport === \"extensions\") {\n operation.extensions = compact(\n // setting these first so that it can be overridden by user-provided extensions\n {\n clientLibrary: {\n name: \"@apollo/client\",\n version: client.version,\n },\n },\n operation.extensions\n );\n }\n }\n\n return forward(operation);\n });\n }\n}\n"]}
1
+ {"version":3,"file":"ClientAwarenessLink.js","sourceRoot":"","sources":["../../../src/link/client-awareness/ClientAwarenessLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AA6D5D,MAAM,OAAO,mBAAoB,SAAQ,UAAU;IACjD,YAAY,qBAAkD,EAAE;QAC9D,KAAK,CAAC,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE;YAC3B,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC;YAEhC,MAAM,aAAa,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC,aAAa,CAAC;YAC3D,MAAM,OAAO,GAAG,SAAS,CAAC,UAAU,EAAE,CAAC;YACvC,CAAC;gBACC,MAAM,EACJ,IAAI,EACJ,OAAO,EACP,SAAS,GAAG,SAAS,GACtB,GAAG,OAAO,CACT,EAAE,EACF,aAAa,CAAC,eAAe,EAC7B,kBAAkB,CAAC,eAAe,EAClC,OAAO,CAAC,eAAe,CACxB,CAAC;gBAEF,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;oBAC5B,SAAS,CAAC,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE;wBAC/C,OAAO;4BACL,OAAO,EAAE,OAAO;4BACd,8EAA8E;4BAC9E;gCACE,2BAA2B,EAAE,IAAI;gCACjC,8BAA8B,EAAE,OAAO;6BACxC,EACD,OAAO,CACR;yBACF,CAAC;oBACJ,CAAC,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;YACD,CAAC;gBACC,MAAM,EAAE,SAAS,GAAG,YAAY,EAAE,GAAG,OAAO,CAC1C,EAAE,EACF,aAAa,CAAC,uBAAuB,EACrC,kBAAkB,CAAC,uBAAuB,CAC3C,CAAC;gBACF,IAAI,SAAS,KAAK,YAAY,EAAE,CAAC;oBAC/B,SAAS,CAAC,UAAU,GAAG,OAAO;oBAC5B,+EAA+E;oBAC/E;wBACE,aAAa,EAAE;4BACb,IAAI,EAAE,gBAAgB;4BACtB,OAAO,EAAE,MAAM,CAAC,OAAO;yBACxB;qBACF,EACD,SAAS,CAAC,UAAU,CACrB,CAAC;gBACJ,CAAC;YACH,CAAC;YAED,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { ApolloLink } from \"@apollo/client/link\";\nimport { compact } from \"@apollo/client/utilities/internal\";\n\nexport declare namespace ClientAwarenessLink {\n export interface ClientAwarenessOptions {\n /**\n * A custom name (e.g., `iOS`) that identifies this particular client among your set of clients. Apollo Server and Apollo Studio use this property as part of the [client awareness](https://www.apollographql.com/docs/apollo-server/monitoring/metrics#identifying-distinct-clients) feature.\n *\n * This option can either be set as part of the Apollo Client constructor call or when manually constructing a `HttpLink`, `BatchHttpLink` or `ClientAwarenessLink`.\n */\n name?: string;\n /**\n * A custom version that identifies the current version of this particular client (e.g., `1.2`). Apollo Server and Apollo Studio use this property as part of the [client awareness](https://www.apollographql.com/docs/apollo-server/monitoring/metrics#identifying-distinct-clients) feature.\n *\n * This is **not** the version of Apollo Client that you are using, but rather any version string that helps you differentiate between versions of your client.\n *\n * This option can either be set as part of the Apollo Client constructor call or when manually constructing a `HttpLink`, `BatchHttpLink` or `ClientAwarenessLink`.\n */\n version?: string;\n /**\n * Determines how `name` and `version` are sent in outgoing requests.\n *\n * If `name` and `version` are not provided, this option will be ignored.\n * (These options can either be set as part of the Apollo Client constructor call or when manually constructing a `HttpLink`, `BatchHttpLink` or `ClientAwarenessLink`.)\n *\n * - If set to `\"headers\"`, `name` and `version` will be sent in the request headers as `apollographql-client-name` and `apollographql-client-version`, respectively.\n * - If set to `false`, `name` and `version` will not be included in outgoing requests.\n *\n * @defaultValue \"headers\"\n */\n transport?: \"headers\" | false;\n }\n export interface EnhancedClientAwarenessOptions {\n /**\n * Determines how the the version information of Apollo Client is sent in outgoing requests.\n *\n * - If set to `\"extensions\"`, library `name` and `version` will be sent in an object in the request extensions as `clientLibrary`.\n * - If set to `false`, library name and version will not be included in outgoing requests.\n *\n * @defaultValue \"extensions\"\n */\n transport?: \"extensions\" | false;\n }\n\n export interface Options {\n /**\n * Configures the \"client awareness\" feature.\n * This feature allows you to identify distinct applications in Apollo Studio\n * and Apollo Server logs (and other monitoring or analytics tools) by adding\n * information about the your application to outgoing requests.\n */\n clientAwareness?: ClientAwarenessOptions;\n /**\n * Configures the \"enhanced client awareness\" feature.\n * This feature allows you to identify the version of the Apollo Client library\n * used in your application in Apollo Studio (and other monitoring or analytics tools)\n * by adding information about the Apollo Client library to outgoing requests.\n */\n enhancedClientAwareness?: EnhancedClientAwarenessOptions;\n }\n}\n\nexport class ClientAwarenessLink extends ApolloLink {\n constructor(constructorOptions: ClientAwarenessLink.Options = {}) {\n super((operation, forward) => {\n const client = operation.client;\n\n const clientOptions = client[\"queryManager\"].clientOptions;\n const context = operation.getContext();\n {\n const {\n name,\n version,\n transport = \"headers\",\n } = compact(\n {},\n clientOptions.clientAwareness,\n constructorOptions.clientAwareness,\n context.clientAwareness\n );\n\n if (transport === \"headers\") {\n operation.setContext(({ headers, extensions }) => {\n return {\n headers: compact(\n // setting these first so that they can be overridden by user-provided headers\n {\n \"apollographql-client-name\": name,\n \"apollographql-client-version\": version,\n },\n headers\n ),\n };\n });\n }\n }\n {\n const { transport = \"extensions\" } = compact(\n {},\n clientOptions.enhancedClientAwareness,\n constructorOptions.enhancedClientAwareness\n );\n if (transport === \"extensions\") {\n operation.extensions = compact(\n // setting these first so that it can be overridden by user-provided extensions\n {\n clientLibrary: {\n name: \"@apollo/client\",\n version: client.version,\n },\n },\n operation.extensions\n );\n }\n }\n\n return forward(operation);\n });\n }\n}\n"]}
@@ -1,9 +1,8 @@
1
- import type { Operation, OperationContext } from "@apollo/client/link";
2
1
  import { ApolloLink } from "@apollo/client/link";
3
2
  export declare namespace SetContextLink {
4
- type ContextSetter = (prevContext: OperationContext, operation: SetContextOperation) => Promise<Partial<OperationContext>> | Partial<OperationContext>;
5
- type LegacyContextSetter = (operation: SetContextOperation, prevContext: OperationContext) => Promise<Partial<OperationContext>> | Partial<OperationContext>;
6
- type SetContextOperation = Omit<Operation, "getContext" | "setContext">;
3
+ type ContextSetter = (prevContext: ApolloLink.OperationContext, operation: SetContextOperation) => Promise<Partial<ApolloLink.OperationContext>> | Partial<ApolloLink.OperationContext>;
4
+ type LegacyContextSetter = (operation: SetContextOperation, prevContext: ApolloLink.OperationContext) => Promise<Partial<ApolloLink.OperationContext>> | Partial<ApolloLink.OperationContext>;
5
+ type SetContextOperation = Omit<ApolloLink.Operation, "getContext" | "setContext">;
7
6
  }
8
7
  /**
9
8
  * @deprecated
@@ -14,7 +13,7 @@ export declare namespace SetContextLink {
14
13
  * ```ts
15
14
  * new SetContextLink((prevContext, operation) => {
16
15
  * // ...
17
- * })
16
+ * });
18
17
  * ```
19
18
  */
20
19
  export declare function setContext(setter: SetContextLink.LegacyContextSetter): SetContextLink;
@@ -9,7 +9,7 @@ import { ApolloLink } from "@apollo/client/link";
9
9
  * ```ts
10
10
  * new SetContextLink((prevContext, operation) => {
11
11
  * // ...
12
- * })
12
+ * });
13
13
  * ```
14
14
  */
15
15
  export function setContext(setter) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/link/context/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAGlC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAmBjD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,UAAU,CAAC,MAA0C;IACnE,OAAO,IAAI,cAAc,CAAC,CAAC,WAAW,EAAE,SAAS,EAAE,EAAE,CACnD,MAAM,CAAC,SAAS,EAAE,WAAW,CAAC,CAC/B,CAAC;AACJ,CAAC;AACD,MAAM,OAAO,cAAe,SAAQ,UAAU;IAC5C,YAAY,MAAoC;QAC9C,KAAK,CAAC,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE;YAC3B,MAAM,EAAE,GAAG,OAAO,EAAE,GAAG,SAA+C,CAAC;YAEvE,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,QAAQ,EAAE;gBACvC,UAAU,EAAE,KAAK;gBACjB,KAAK,EAAE,SAAS,CAAC,MAAM;aACxB,CAAC,CAAC;YAEH,OAAO,IAAI,UAAU,CAAC,CAAC,QAAQ,EAAE,EAAE;gBACjC,IAAI,MAAM,GAAG,KAAK,CAAC;gBACnB,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC;qBACrB,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,EAAE,EAAE,GAAG,CAAC,CAAC;qBAClD,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC;qBAC1B,IAAI,CAAC,GAAG,EAAE;oBACT,IAAI,CAAC,MAAM,EAAE,CAAC;wBACZ,OAAO,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;oBACzC,CAAC;gBACH,CAAC,CAAC;qBACD,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;gBAExC,OAAO,GAAG,EAAE;oBACV,MAAM,GAAG,IAAI,CAAC;gBAChB,CAAC,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { Observable } from \"rxjs\";\n\nimport type { Operation, OperationContext } from \"@apollo/client/link\";\nimport { ApolloLink } from \"@apollo/client/link\";\n\nexport declare namespace SetContextLink {\n export type ContextSetter = (\n prevContext: OperationContext,\n operation: SetContextOperation\n ) => Promise<Partial<OperationContext>> | Partial<OperationContext>;\n\n export type LegacyContextSetter = (\n operation: SetContextOperation,\n prevContext: OperationContext\n ) => Promise<Partial<OperationContext>> | Partial<OperationContext>;\n\n export type SetContextOperation = Omit<\n Operation,\n \"getContext\" | \"setContext\"\n >;\n}\n\n/**\n * @deprecated\n * Use `SetContextLink` from `@apollo/client/link/context` instead. Note you\n * will need to flip the arguments when using `SetContextLink` as `prevContext`\n * is the first argument.\n *\n * ```ts\n * new SetContextLink((prevContext, operation) => {\n * // ...\n * })\n * ```\n */\nexport function setContext(setter: SetContextLink.LegacyContextSetter) {\n return new SetContextLink((prevContext, operation) =>\n setter(operation, prevContext)\n );\n}\nexport class SetContextLink extends ApolloLink {\n constructor(setter: SetContextLink.ContextSetter) {\n super((operation, forward) => {\n const { ...request } = operation as SetContextLink.SetContextOperation;\n\n Object.defineProperty(request, \"client\", {\n enumerable: false,\n value: operation.client,\n });\n\n return new Observable((observer) => {\n let closed = false;\n Promise.resolve(request)\n .then((req) => setter(operation.getContext(), req))\n .then(operation.setContext)\n .then(() => {\n if (!closed) {\n forward(operation).subscribe(observer);\n }\n })\n .catch(observer.error.bind(observer));\n\n return () => {\n closed = true;\n };\n });\n });\n }\n}\n"]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E;oBACV,MAAM,GAAG,IAAI,CAAC;gBAChB,CAAC,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { Observable } from \"rxjs\";\n\nimport { ApolloLink } from \"@apollo/client/link\";\n\nexport declare namespace SetContextLink {\n export type ContextSetter = (\n prevContext: ApolloLink.OperationContext,\n operation: SetContextOperation\n ) =>\n | Promise<Partial<ApolloLink.OperationContext>>\n | Partial<ApolloLink.OperationContext>;\n\n export type LegacyContextSetter = (\n operation: SetContextOperation,\n prevContext: ApolloLink.OperationContext\n ) =>\n | Promise<Partial<ApolloLink.OperationContext>>\n | Partial<ApolloLink.OperationContext>;\n\n export type SetContextOperation = Omit<\n ApolloLink.Operation,\n \"getContext\" | \"setContext\"\n >;\n}\n\n/**\n * @deprecated\n * Use `SetContextLink` from `@apollo/client/link/context` instead. Note you\n * will need to flip the arguments when using `SetContextLink` as `prevContext`\n * is the first argument.\n *\n * ```ts\n * new SetContextLink((prevContext, operation) => {\n * // ...\n * });\n * ```\n */\nexport function setContext(setter: SetContextLink.LegacyContextSetter) {\n return new SetContextLink((prevContext, operation) =>\n setter(operation, prevContext)\n );\n}\nexport class SetContextLink extends ApolloLink {\n constructor(setter: SetContextLink.ContextSetter) {\n super((operation, forward) => {\n const { ...request } = operation as SetContextLink.SetContextOperation;\n\n Object.defineProperty(request, \"client\", {\n enumerable: false,\n value: operation.client,\n });\n\n return new Observable((observer) => {\n let closed = false;\n Promise.resolve(request)\n .then((req) => setter(operation.getContext(), req))\n .then(operation.setContext)\n .then(() => {\n if (!closed) {\n forward(operation).subscribe(observer);\n }\n })\n .catch(observer.error.bind(observer));\n\n return () => {\n closed = true;\n };\n });\n });\n }\n}\n"]}