@apollo/client 4.0.0-rc.6 → 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 (309) hide show
  1. package/CHANGELOG.md +135 -0
  2. package/__cjs/cache/core/cache.cjs +12 -7
  3. package/__cjs/cache/core/cache.cjs.map +1 -1
  4. package/__cjs/cache/core/cache.d.cts +12 -7
  5. package/__cjs/core/ApolloClient.cjs +2 -2
  6. package/__cjs/core/ApolloClient.cjs.map +1 -1
  7. package/__cjs/core/ApolloClient.d.cts +80 -98
  8. package/__cjs/core/ObservableQuery.d.cts +41 -74
  9. package/__cjs/core/QueryInfo.cjs.map +1 -1
  10. package/__cjs/core/QueryInfo.d.cts +3 -3
  11. package/__cjs/core/QueryManager.cjs +0 -2
  12. package/__cjs/core/QueryManager.cjs.map +1 -1
  13. package/__cjs/core/QueryManager.d.cts +3 -3
  14. package/__cjs/core/index.cjs.map +1 -1
  15. package/__cjs/core/index.d.cts +1 -1
  16. package/__cjs/core/types.d.cts +40 -28
  17. package/__cjs/errors/CombinedGraphQLErrors.cjs +22 -17
  18. package/__cjs/errors/CombinedGraphQLErrors.cjs.map +1 -1
  19. package/__cjs/errors/CombinedGraphQLErrors.d.cts +39 -20
  20. package/__cjs/errors/CombinedProtocolErrors.cjs +12 -6
  21. package/__cjs/errors/CombinedProtocolErrors.cjs.map +1 -1
  22. package/__cjs/errors/CombinedProtocolErrors.d.cts +12 -6
  23. package/__cjs/errors/ServerError.cjs +2 -1
  24. package/__cjs/errors/ServerError.cjs.map +1 -1
  25. package/__cjs/errors/ServerError.d.cts +2 -1
  26. package/__cjs/errors/ServerParseError.cjs +2 -1
  27. package/__cjs/errors/ServerParseError.cjs.map +1 -1
  28. package/__cjs/errors/ServerParseError.d.cts +2 -1
  29. package/__cjs/incremental/handlers/defer20220824.cjs.map +1 -1
  30. package/__cjs/incremental/handlers/defer20220824.d.cts +4 -4
  31. package/__cjs/incremental/handlers/notImplemented.cjs.map +1 -1
  32. package/__cjs/incremental/handlers/notImplemented.d.cts +2 -2
  33. package/__cjs/incremental/types.d.cts +4 -4
  34. package/__cjs/invariantErrorCodes.cjs +14 -10
  35. package/__cjs/link/batch/batchLink.cjs +3 -9
  36. package/__cjs/link/batch/batchLink.cjs.map +1 -1
  37. package/__cjs/link/batch/batchLink.d.cts +2 -3
  38. package/__cjs/link/batch/batching.cjs +1 -1
  39. package/__cjs/link/batch/batching.cjs.map +1 -1
  40. package/__cjs/link/batch/batching.d.cts +7 -7
  41. package/__cjs/link/batch-http/batchHttpLink.cjs +6 -3
  42. package/__cjs/link/batch-http/batchHttpLink.cjs.map +1 -1
  43. package/__cjs/link/batch-http/batchHttpLink.d.cts +1 -2
  44. package/__cjs/link/context/index.cjs.map +1 -1
  45. package/__cjs/link/context/index.d.cts +3 -4
  46. package/__cjs/link/core/ApolloLink.cjs +226 -54
  47. package/__cjs/link/core/ApolloLink.cjs.map +1 -1
  48. package/__cjs/link/core/ApolloLink.d.cts +355 -9
  49. package/__cjs/link/core/concat.cjs +4 -0
  50. package/__cjs/link/core/concat.cjs.map +1 -1
  51. package/__cjs/link/core/concat.d.cts +4 -0
  52. package/__cjs/link/core/deprecated.cjs +3 -0
  53. package/__cjs/link/core/deprecated.cjs.map +1 -0
  54. package/__cjs/link/core/deprecated.d.cts +10 -0
  55. package/__cjs/link/core/empty.cjs +4 -0
  56. package/__cjs/link/core/empty.cjs.map +1 -1
  57. package/__cjs/link/core/empty.d.cts +4 -0
  58. package/__cjs/link/core/from.cjs +4 -0
  59. package/__cjs/link/core/from.cjs.map +1 -1
  60. package/__cjs/link/core/from.d.cts +4 -0
  61. package/__cjs/link/core/split.cjs +4 -0
  62. package/__cjs/link/core/split.cjs.map +1 -1
  63. package/__cjs/link/core/split.d.cts +4 -0
  64. package/__cjs/link/core/types.d.cts +2 -33
  65. package/__cjs/link/error/index.cjs.map +1 -1
  66. package/__cjs/link/error/index.d.cts +4 -5
  67. package/__cjs/link/http/BaseHttpLink.cjs +2 -2
  68. package/__cjs/link/http/BaseHttpLink.cjs.map +1 -1
  69. package/__cjs/link/http/HttpLink.cjs +4 -1
  70. package/__cjs/link/http/HttpLink.cjs.map +1 -1
  71. package/__cjs/link/http/HttpLink.d.cts +1 -2
  72. package/__cjs/link/http/checkFetcher.cjs +1 -1
  73. package/__cjs/link/http/parseAndCheckHttpResponse.cjs +41 -26
  74. package/__cjs/link/http/parseAndCheckHttpResponse.cjs.map +1 -1
  75. package/__cjs/link/http/parseAndCheckHttpResponse.d.cts +2 -2
  76. package/__cjs/link/http/selectHttpOptionsAndBody.cjs.map +1 -1
  77. package/__cjs/link/http/selectHttpOptionsAndBody.d.cts +3 -3
  78. package/__cjs/link/http/selectURI.cjs.map +1 -1
  79. package/__cjs/link/http/selectURI.d.cts +2 -2
  80. package/__cjs/link/http/serializeFetchParameter.cjs +1 -1
  81. package/__cjs/link/index.cjs.map +1 -1
  82. package/__cjs/link/index.d.cts +2 -1
  83. package/__cjs/link/persisted-queries/index.cjs +2 -2
  84. package/__cjs/link/persisted-queries/index.cjs.map +1 -1
  85. package/__cjs/link/persisted-queries/index.d.cts +1 -2
  86. package/__cjs/link/retry/delayFunction.cjs.map +1 -1
  87. package/__cjs/link/retry/delayFunction.d.cts +2 -2
  88. package/__cjs/link/retry/retryFunction.cjs.map +1 -1
  89. package/__cjs/link/retry/retryFunction.d.cts +3 -3
  90. package/__cjs/link/retry/retryLink.cjs +2 -2
  91. package/__cjs/link/retry/retryLink.cjs.map +1 -1
  92. package/__cjs/link/retry/retryLink.d.cts +1 -2
  93. package/__cjs/link/schema/index.cjs.map +1 -1
  94. package/__cjs/link/schema/index.d.cts +2 -3
  95. package/__cjs/link/subscriptions/index.cjs.map +1 -1
  96. package/__cjs/link/subscriptions/index.d.cts +1 -2
  97. package/__cjs/link/utils/createOperation.cjs +12 -4
  98. package/__cjs/link/utils/createOperation.cjs.map +1 -1
  99. package/__cjs/link/utils/createOperation.d.cts +2 -2
  100. package/__cjs/link/utils/index.cjs +1 -5
  101. package/__cjs/link/utils/index.cjs.map +1 -1
  102. package/__cjs/link/utils/index.d.cts +0 -2
  103. package/__cjs/link/ws/index.cjs.map +1 -1
  104. package/__cjs/link/ws/index.d.cts +1 -2
  105. package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
  106. package/__cjs/react/hooks/useBackgroundQuery.d.cts +125 -93
  107. package/__cjs/react/hooks/useFragment.cjs.map +1 -1
  108. package/__cjs/react/hooks/useFragment.d.cts +2 -2
  109. package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
  110. package/__cjs/react/hooks/useLazyQuery.d.cts +70 -108
  111. package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
  112. package/__cjs/react/hooks/useLoadableQuery.d.cts +52 -61
  113. package/__cjs/react/hooks/useMutation.cjs.map +1 -1
  114. package/__cjs/react/hooks/useMutation.d.cts +36 -54
  115. package/__cjs/react/hooks/useQuery.cjs.map +1 -1
  116. package/__cjs/react/hooks/useQuery.d.cts +64 -105
  117. package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
  118. package/__cjs/react/hooks/useQueryRefHandlers.d.cts +17 -8
  119. package/__cjs/react/hooks/useReadQuery.cjs.map +1 -1
  120. package/__cjs/react/hooks/useReadQuery.d.cts +6 -9
  121. package/__cjs/react/hooks/useSubscription.cjs.map +1 -1
  122. package/__cjs/react/hooks/useSubscription.d.cts +32 -24
  123. package/__cjs/react/hooks/useSuspenseFragment.cjs.map +1 -1
  124. package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
  125. package/__cjs/react/hooks/useSuspenseQuery.d.cts +75 -94
  126. package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
  127. package/__cjs/react/internal/cache/QueryReference.d.cts +3 -1
  128. package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
  129. package/__cjs/react/query-preloader/createQueryPreloader.d.cts +29 -20
  130. package/__cjs/react/types/types.documentation.d.cts +5 -5
  131. package/__cjs/testing/core/mocking/mockLink.cjs.map +1 -1
  132. package/__cjs/testing/core/mocking/mockLink.d.cts +5 -6
  133. package/__cjs/testing/core/mocking/mockSubscriptionLink.cjs.map +1 -1
  134. package/__cjs/testing/core/mocking/mockSubscriptionLink.d.cts +3 -4
  135. package/__cjs/utilities/internal/types/DocumentationTypes.d.cts +20 -28
  136. package/__cjs/utilities/internal/types/VariablesOption.d.cts +2 -6
  137. package/__cjs/version.cjs +1 -1
  138. package/cache/core/cache.d.ts +12 -7
  139. package/cache/core/cache.js +12 -7
  140. package/cache/core/cache.js.map +1 -1
  141. package/core/ApolloClient.d.ts +80 -98
  142. package/core/ApolloClient.js +2 -2
  143. package/core/ApolloClient.js.map +1 -1
  144. package/core/ObservableQuery.d.ts +41 -74
  145. package/core/QueryInfo.d.ts +3 -3
  146. package/core/QueryInfo.js.map +1 -1
  147. package/core/QueryManager.d.ts +3 -3
  148. package/core/QueryManager.js +0 -2
  149. package/core/QueryManager.js.map +1 -1
  150. package/core/index.d.ts +1 -1
  151. package/core/index.js.map +1 -1
  152. package/core/types.d.ts +40 -28
  153. package/errors/CombinedGraphQLErrors.d.ts +39 -20
  154. package/errors/CombinedGraphQLErrors.js +22 -17
  155. package/errors/CombinedGraphQLErrors.js.map +1 -1
  156. package/errors/CombinedProtocolErrors.d.ts +12 -6
  157. package/errors/CombinedProtocolErrors.js +12 -6
  158. package/errors/CombinedProtocolErrors.js.map +1 -1
  159. package/errors/ServerError.d.ts +2 -1
  160. package/errors/ServerError.js +2 -1
  161. package/errors/ServerError.js.map +1 -1
  162. package/errors/ServerParseError.d.ts +2 -1
  163. package/errors/ServerParseError.js +2 -1
  164. package/errors/ServerParseError.js.map +1 -1
  165. package/incremental/handlers/defer20220824.d.ts +4 -4
  166. package/incremental/handlers/defer20220824.js.map +1 -1
  167. package/incremental/handlers/notImplemented.d.ts +2 -2
  168. package/incremental/handlers/notImplemented.js.map +1 -1
  169. package/incremental/types.d.ts +4 -4
  170. package/incremental/types.js.map +1 -1
  171. package/invariantErrorCodes.js +14 -10
  172. package/link/batch/batchLink.d.ts +2 -3
  173. package/link/batch/batchLink.js +3 -9
  174. package/link/batch/batchLink.js.map +1 -1
  175. package/link/batch/batching.d.ts +7 -7
  176. package/link/batch/batching.js +2 -2
  177. package/link/batch/batching.js.map +1 -1
  178. package/link/batch-http/batchHttpLink.d.ts +1 -2
  179. package/link/batch-http/batchHttpLink.js +6 -3
  180. package/link/batch-http/batchHttpLink.js.map +1 -1
  181. package/link/context/index.d.ts +3 -4
  182. package/link/context/index.js.map +1 -1
  183. package/link/core/ApolloLink.d.ts +355 -9
  184. package/link/core/ApolloLink.js +227 -56
  185. package/link/core/ApolloLink.js.map +1 -1
  186. package/link/core/concat.d.ts +4 -0
  187. package/link/core/concat.js +4 -0
  188. package/link/core/concat.js.map +1 -1
  189. package/link/core/deprecated.d.ts +10 -0
  190. package/link/core/deprecated.js +2 -0
  191. package/link/core/deprecated.js.map +1 -0
  192. package/link/core/empty.d.ts +4 -0
  193. package/link/core/empty.js +4 -0
  194. package/link/core/empty.js.map +1 -1
  195. package/link/core/from.d.ts +4 -0
  196. package/link/core/from.js +4 -0
  197. package/link/core/from.js.map +1 -1
  198. package/link/core/split.d.ts +4 -0
  199. package/link/core/split.js +4 -0
  200. package/link/core/split.js.map +1 -1
  201. package/link/core/types.d.ts +2 -33
  202. package/link/core/types.js.map +1 -1
  203. package/link/error/index.d.ts +4 -5
  204. package/link/error/index.js.map +1 -1
  205. package/link/http/BaseHttpLink.js +2 -2
  206. package/link/http/BaseHttpLink.js.map +1 -1
  207. package/link/http/HttpLink.d.ts +1 -2
  208. package/link/http/HttpLink.js +4 -1
  209. package/link/http/HttpLink.js.map +1 -1
  210. package/link/http/checkFetcher.js +1 -1
  211. package/link/http/parseAndCheckHttpResponse.d.ts +2 -2
  212. package/link/http/parseAndCheckHttpResponse.js +41 -26
  213. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  214. package/link/http/selectHttpOptionsAndBody.d.ts +3 -3
  215. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  216. package/link/http/selectURI.d.ts +2 -2
  217. package/link/http/selectURI.js.map +1 -1
  218. package/link/http/serializeFetchParameter.js +1 -1
  219. package/link/index.d.ts +2 -1
  220. package/link/index.js.map +1 -1
  221. package/link/persisted-queries/index.d.ts +1 -2
  222. package/link/persisted-queries/index.js +2 -2
  223. package/link/persisted-queries/index.js.map +1 -1
  224. package/link/retry/delayFunction.d.ts +2 -2
  225. package/link/retry/delayFunction.js.map +1 -1
  226. package/link/retry/retryFunction.d.ts +3 -3
  227. package/link/retry/retryFunction.js.map +1 -1
  228. package/link/retry/retryLink.d.ts +1 -2
  229. package/link/retry/retryLink.js +2 -2
  230. package/link/retry/retryLink.js.map +1 -1
  231. package/link/schema/index.d.ts +2 -3
  232. package/link/schema/index.js.map +1 -1
  233. package/link/subscriptions/index.d.ts +1 -2
  234. package/link/subscriptions/index.js.map +1 -1
  235. package/link/utils/createOperation.d.ts +2 -2
  236. package/link/utils/createOperation.js +12 -4
  237. package/link/utils/createOperation.js.map +1 -1
  238. package/link/utils/index.d.ts +0 -2
  239. package/link/utils/index.js +0 -2
  240. package/link/utils/index.js.map +1 -1
  241. package/link/ws/index.d.ts +1 -2
  242. package/link/ws/index.js.map +1 -1
  243. package/package.json +1 -1
  244. package/react/hooks/useBackgroundQuery.d.ts +125 -93
  245. package/react/hooks/useBackgroundQuery.js.map +1 -1
  246. package/react/hooks/useFragment.d.ts +2 -2
  247. package/react/hooks/useFragment.js.map +1 -1
  248. package/react/hooks/useLazyQuery.d.ts +70 -108
  249. package/react/hooks/useLazyQuery.js.map +1 -1
  250. package/react/hooks/useLoadableQuery.d.ts +52 -61
  251. package/react/hooks/useLoadableQuery.js.map +1 -1
  252. package/react/hooks/useMutation.d.ts +36 -54
  253. package/react/hooks/useMutation.js.map +1 -1
  254. package/react/hooks/useQuery.d.ts +64 -105
  255. package/react/hooks/useQuery.js.map +1 -1
  256. package/react/hooks/useQueryRefHandlers.d.ts +17 -8
  257. package/react/hooks/useQueryRefHandlers.js.map +1 -1
  258. package/react/hooks/useReadQuery.d.ts +6 -9
  259. package/react/hooks/useReadQuery.js.map +1 -1
  260. package/react/hooks/useSubscription.d.ts +32 -24
  261. package/react/hooks/useSubscription.js.map +1 -1
  262. package/react/hooks/useSuspenseFragment.js.map +1 -1
  263. package/react/hooks/useSuspenseQuery.d.ts +75 -94
  264. package/react/hooks/useSuspenseQuery.js.map +1 -1
  265. package/react/hooks-compiled/useBackgroundQuery.d.ts +125 -93
  266. package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
  267. package/react/hooks-compiled/useFragment.d.ts +2 -2
  268. package/react/hooks-compiled/useFragment.js.map +1 -1
  269. package/react/hooks-compiled/useLazyQuery.d.ts +70 -108
  270. package/react/hooks-compiled/useLazyQuery.js.map +1 -1
  271. package/react/hooks-compiled/useLoadableQuery.d.ts +52 -61
  272. package/react/hooks-compiled/useLoadableQuery.js.map +1 -1
  273. package/react/hooks-compiled/useMutation.d.ts +36 -54
  274. package/react/hooks-compiled/useMutation.js.map +1 -1
  275. package/react/hooks-compiled/useQuery.d.ts +64 -105
  276. package/react/hooks-compiled/useQuery.js.map +1 -1
  277. package/react/hooks-compiled/useQueryRefHandlers.d.ts +17 -8
  278. package/react/hooks-compiled/useQueryRefHandlers.js.map +1 -1
  279. package/react/hooks-compiled/useReadQuery.d.ts +6 -9
  280. package/react/hooks-compiled/useReadQuery.js.map +1 -1
  281. package/react/hooks-compiled/useSubscription.d.ts +32 -24
  282. package/react/hooks-compiled/useSubscription.js.map +1 -1
  283. package/react/hooks-compiled/useSuspenseFragment.js.map +1 -1
  284. package/react/hooks-compiled/useSuspenseQuery.d.ts +75 -94
  285. package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
  286. package/react/internal/cache/QueryReference.d.ts +3 -1
  287. package/react/internal/cache/QueryReference.js.map +1 -1
  288. package/react/query-preloader/createQueryPreloader.d.ts +29 -20
  289. package/react/query-preloader/createQueryPreloader.js.map +1 -1
  290. package/react/types/types.documentation.d.ts +5 -5
  291. package/testing/core/mocking/mockLink.d.ts +5 -6
  292. package/testing/core/mocking/mockLink.js.map +1 -1
  293. package/testing/core/mocking/mockSubscriptionLink.d.ts +3 -4
  294. package/testing/core/mocking/mockSubscriptionLink.js.map +1 -1
  295. package/utilities/internal/types/DocumentationTypes.d.ts +20 -28
  296. package/utilities/internal/types/VariablesOption.d.ts +2 -6
  297. package/version.js +1 -1
  298. package/__cjs/link/utils/transformOperation.cjs +0 -22
  299. package/__cjs/link/utils/transformOperation.cjs.map +0 -1
  300. package/__cjs/link/utils/transformOperation.d.cts +0 -3
  301. package/__cjs/link/utils/validateOperation.cjs +0 -21
  302. package/__cjs/link/utils/validateOperation.cjs.map +0 -1
  303. package/__cjs/link/utils/validateOperation.d.cts +0 -3
  304. package/link/utils/transformOperation.d.ts +0 -3
  305. package/link/utils/transformOperation.js +0 -19
  306. package/link/utils/transformOperation.js.map +0 -1
  307. package/link/utils/validateOperation.d.ts +0 -3
  308. package/link/utils/validateOperation.js +0 -18
  309. package/link/utils/validateOperation.js.map +0 -1
@@ -1,15 +1,361 @@
1
+ import type { DocumentNode, FormattedExecutionResult, OperationTypeNode } from "graphql";
1
2
  import type { Observable } from "rxjs";
2
- import type { ExecuteContext, FetchResult, GraphQLRequest, NextLink, Operation, RequestHandler } from "./types.js";
3
+ import type { ApolloClient, DefaultContext, OperationVariables } from "@apollo/client";
4
+ import type { AdditionalApolloLinkResultTypes } from "./types.js";
5
+ export declare namespace ApolloLink {
6
+ /**
7
+ * Context provided for link execution, such as the client executing the
8
+ * request. It is separate from the request operation context.
9
+ */
10
+ interface ExecuteContext {
11
+ /**
12
+ * The Apollo Client instance that executed the GraphQL request.
13
+ */
14
+ client: ApolloClient;
15
+ }
16
+ /**
17
+ * A function that when called will execute the next link in the link chain.
18
+ *
19
+ * @example
20
+ *
21
+ * ```ts
22
+ * const link = new ApolloLink((operation, forward) => {
23
+ * // process the request
24
+ *
25
+ * // Call `forward` to execute the next link in the chain
26
+ * return forward(operation);
27
+ * });
28
+ * ```
29
+ *
30
+ * @param operation - The current `ApolloLink.Operation` object for the
31
+ * request.
32
+ */
33
+ type ForwardFunction = (operation: ApolloLink.Operation) => Observable<ApolloLink.Result>;
34
+ /**
35
+ * The input object provided to `ApolloLink.execute` to send a GraphQL request through
36
+ * the link chain.
37
+ */
38
+ interface Request {
39
+ /**
40
+ * The parsed GraphQL document that will be sent with the GraphQL request to
41
+ * the server.
42
+ */
43
+ query: DocumentNode;
44
+ /**
45
+ * The variables provided for the query.
46
+ */
47
+ variables?: OperationVariables;
48
+ /**
49
+ * Context provided to the link chain. Context is not sent to the server and
50
+ * is used to communicate additional metadata from a request to individual
51
+ * links in the link chain.
52
+ */
53
+ context?: DefaultContext;
54
+ /**
55
+ * A map of extensions that will be sent with the GraphQL request to the
56
+ * server.
57
+ */
58
+ extensions?: Record<string, any>;
59
+ }
60
+ /**
61
+ * A request handler is responsible for performing some logic and executing the
62
+ * request, either by [forwarding](https://apollographql.com/docs/react/api/link/introduction#the-request-handler) the operation to the next link in the
63
+ * chain, or sending the operation to the destination that executes it, such as
64
+ * a GraphQL server.
65
+ *
66
+ * @param operation - The `Operation` object that provides information about the
67
+ * currently executed GraphQL request.
68
+ *
69
+ * @param forward - A function that is called to execute the next link in the
70
+ * chain.
71
+ */
72
+ type RequestHandler = (operation: ApolloLink.Operation, forward: ApolloLink.ForwardFunction) => Observable<ApolloLink.Result>;
73
+ type Result<TData = Record<string, any>, TExtensions = Record<string, any>> = FormattedExecutionResult<TData, TExtensions> | AdditionalApolloLinkResultTypes<TData, TExtensions>[keyof AdditionalApolloLinkResultTypes<TData, TExtensions>];
74
+ /**
75
+ * The currently executed operation object provided to an `ApolloLink.RequestHandler`
76
+ * for each link in the link chain.
77
+ */
78
+ interface Operation {
79
+ /**
80
+ * A `DocumentNode` that describes the operation taking place.
81
+ */
82
+ query: DocumentNode;
83
+ /**
84
+ * A map of GraphQL variables being sent with the operation.
85
+ */
86
+ variables: OperationVariables;
87
+ /**
88
+ * The string name of the GraphQL operation. If it is anonymous,
89
+ * `operationName` will be `undefined`.
90
+ */
91
+ operationName: string | undefined;
92
+ /**
93
+ * The type of the GraphQL operation, such as query or mutation.
94
+ */
95
+ operationType: OperationTypeNode;
96
+ /**
97
+ * A map that stores extensions data to be sent to the server.
98
+ */
99
+ extensions: Record<string, any>;
100
+ /**
101
+ * A function that takes either a new context object, or a function which
102
+ * takes in the previous context and returns a new one. See [managing
103
+ * context](https://apollographql.com/docs/react/api/link/introduction#managing-context).
104
+ */
105
+ setContext: {
106
+ (context: Partial<ApolloLink.OperationContext>): void;
107
+ (updateContext: (previousContext: Readonly<ApolloLink.OperationContext>) => Partial<ApolloLink.OperationContext>): void;
108
+ };
109
+ /**
110
+ * A function that gets the current context of the request. This can be used
111
+ * by links to determine which actions to perform. See [managing context](https://apollographql.com/docs/react/api/link/introduction#managing-context)
112
+ */
113
+ getContext: () => Readonly<ApolloLink.OperationContext>;
114
+ /**
115
+ * The Apollo Client instance executing the request.
116
+ */
117
+ readonly client: ApolloClient;
118
+ }
119
+ /**
120
+ * The `context` object that can be read and modified by links using the
121
+ * `operation.getContext()` and `operation.setContext()` methods.
122
+ */
123
+ interface OperationContext extends DefaultContext {
124
+ }
125
+ namespace DocumentationTypes {
126
+ /**
127
+ * A request handler is responsible for performing some logic and executing the
128
+ * request, either by [forwarding](https://apollographql.com/docs/react/api/link/introduction#the-request-handler) the operation to the next link in the
129
+ * chain, or sending the operation to the destination that executes it, such as
130
+ * a GraphQL server.
131
+ *
132
+ * @param operation - The `Operation` object that provides information about the
133
+ * currently executed GraphQL request.
134
+ *
135
+ * @param forward - A function that is called to execute the next link in the
136
+ * chain.
137
+ */
138
+ function RequestHandler(operation: ApolloLink.Operation, forward: ApolloLink.ForwardFunction): Observable<ApolloLink.Result>;
139
+ /**
140
+ * A function that when called will execute the next link in the link chain.
141
+ *
142
+ * @example
143
+ *
144
+ * ```ts
145
+ * const link = new ApolloLink((operation, forward) => {
146
+ * // process the request
147
+ *
148
+ * // Call `forward` to execute the next link in the chain
149
+ * return forward(operation);
150
+ * });
151
+ * ```
152
+ *
153
+ * @param operation - The current `ApolloLink.Operation` object for the
154
+ * request.
155
+ */
156
+ function ForwardFunction(operation: ApolloLink.Operation): Observable<ApolloLink.Result>;
157
+ }
158
+ }
159
+ /**
160
+ * The base class for all links in Apollo Client. A link represents either a
161
+ * self-contained modification to a GraphQL operation or a side effect (such as
162
+ * logging).
163
+ *
164
+ * @remarks
165
+ *
166
+ * Links enable you to customize Apollo Client's request flow by composing
167
+ * together different pieces of functionality into a chain of links. Each
168
+ * link represents a specific capability, such as adding authentication headers,
169
+ * retrying failed requests, batching operations, or sending requests to a
170
+ * GraphQL server.
171
+ *
172
+ * Every link must define a request handler via its constructor or by extending
173
+ * this class and implementing the `request` method.
174
+ *
175
+ * @example
176
+ *
177
+ * ```ts
178
+ * import { ApolloLink } from "@apollo/client";
179
+ *
180
+ * const link = new ApolloLink((operation, forward) => {
181
+ * console.log("Operation:", operation.operationName);
182
+ * return forward(operation);
183
+ * });
184
+ * ```
185
+ */
3
186
  export declare class ApolloLink {
187
+ /**
188
+ * Creates a link that completes immediately and does not emit a result.
189
+ *
190
+ * @example
191
+ *
192
+ * ```ts
193
+ * const link = ApolloLink.empty();
194
+ * ```
195
+ */
4
196
  static empty(): ApolloLink;
5
- static from(links: (ApolloLink | RequestHandler)[]): ApolloLink;
6
- static split(test: (op: Operation) => boolean, left: ApolloLink | RequestHandler, right?: ApolloLink | RequestHandler): ApolloLink;
7
- static execute(link: ApolloLink, operation: GraphQLRequest, context: ExecuteContext): Observable<FetchResult>;
8
- static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink;
9
- constructor(request?: RequestHandler);
10
- split(test: (op: Operation) => boolean, left: ApolloLink | RequestHandler, right?: ApolloLink | RequestHandler): ApolloLink;
11
- concat(next: ApolloLink | RequestHandler): ApolloLink;
12
- request(operation: Operation, forward?: NextLink): Observable<FetchResult> | null;
197
+ /**
198
+ * Composes multiple links into a single composed link that executes each
199
+ * provided link in serial order.
200
+ *
201
+ * @example
202
+ *
203
+ * ```ts
204
+ * import { from, HttpLink, ApolloLink } from "@apollo/client";
205
+ * import { RetryLink } from "@apollo/client/link/retry";
206
+ * import MyAuthLink from "../auth";
207
+ *
208
+ * const link = ApolloLink.from([
209
+ * new RetryLink(),
210
+ * new MyAuthLink(),
211
+ * new HttpLink({ uri: "http://localhost:4000/graphql" }),
212
+ * ]);
213
+ * ```
214
+ *
215
+ * @param links - An array of `ApolloLink` instances or request handlers that
216
+ * are executed in serial order.
217
+ */
218
+ static from(links: ApolloLink[]): ApolloLink;
219
+ /**
220
+ * Creates a link that conditionally routes a request to different links.
221
+ *
222
+ * @example
223
+ *
224
+ * ```ts
225
+ * import { ApolloLink, HttpLink } from "@apollo/client";
226
+ *
227
+ * const link = ApolloLink.split(
228
+ * (operation) => operation.getContext().version === 1,
229
+ * new HttpLink({ uri: "http://localhost:4000/v1/graphql" }),
230
+ * new HttpLink({ uri: "http://localhost:4000/v2/graphql" })
231
+ * );
232
+ * ```
233
+ *
234
+ * @param test - A predicate function that receives the current `operation`
235
+ * and returns a boolean indicating which link to execute. Returning `true`
236
+ * executes the `left` link. Returning `false` executes the `right` link.
237
+ *
238
+ * @param left - The link that executes when the `test` function returns
239
+ * `true`.
240
+ *
241
+ * @param right - The link that executes when the `test` function returns
242
+ * `false`. If the `right` link is not provided, the request is forwarded to
243
+ * the next link in the chain.
244
+ */
245
+ static split(test: (op: ApolloLink.Operation) => boolean, left: ApolloLink, right?: ApolloLink): ApolloLink;
246
+ /**
247
+ * Executes a GraphQL request against a link. The `execute` function begins
248
+ * the request by calling the request handler of the link.
249
+ *
250
+ * @example
251
+ *
252
+ * ```ts
253
+ * const observable = ApolloLink.execute(link, { query, variables }, { client });
254
+ *
255
+ * observable.subscribe({
256
+ * next(value) {
257
+ * console.log("Received", value);
258
+ * },
259
+ * error(error) {
260
+ * console.error("Oops got error", error);
261
+ * },
262
+ * complete() {
263
+ * console.log("Request complete");
264
+ * },
265
+ * });
266
+ * ```
267
+ *
268
+ * @param link - The `ApolloLink` instance to execute the request.
269
+ *
270
+ * @param request - The GraphQL request details, such as the `query` and
271
+ * `variables`.
272
+ *
273
+ * @param context - The execution context for the request, such as the
274
+ * `client` making the request.
275
+ */
276
+ static execute(link: ApolloLink, request: ApolloLink.Request, context: ApolloLink.ExecuteContext): Observable<ApolloLink.Result>;
277
+ /**
278
+ * Combines multiple links into a single composed link.
279
+ *
280
+ * @example
281
+ *
282
+ * ```ts
283
+ * const link = ApolloLink.concat(firstLink, secondLink, thirdLink);
284
+ * ```
285
+ *
286
+ * @param links - The links to concatenate into a single link. Each link will
287
+ * execute in serial order.
288
+ *
289
+ * @deprecated Use `ApolloLink.from` instead. `ApolloLink.concat` will be
290
+ * removed in a future major version.
291
+ */
292
+ static concat(...links: ApolloLink[]): ApolloLink;
293
+ constructor(request?: ApolloLink.RequestHandler);
294
+ /**
295
+ * Concatenates a link that conditionally routes a request to different links.
296
+ *
297
+ * @example
298
+ *
299
+ * ```ts
300
+ * import { ApolloLink, HttpLink } from "@apollo/client";
301
+ *
302
+ * const previousLink = new ApolloLink((operation, forward) => {
303
+ * // Handle the request
304
+ *
305
+ * return forward(operation);
306
+ * });
307
+ *
308
+ * const link = previousLink.split(
309
+ * (operation) => operation.getContext().version === 1,
310
+ * new HttpLink({ uri: "http://localhost:4000/v1/graphql" }),
311
+ * new HttpLink({ uri: "http://localhost:4000/v2/graphql" })
312
+ * );
313
+ * ```
314
+ *
315
+ * @param test - A predicate function that receives the current `operation`
316
+ * and returns a boolean indicating which link to execute. Returning `true`
317
+ * executes the `left` link. Returning `false` executes the `right` link.
318
+ *
319
+ * @param left - The link that executes when the `test` function returns
320
+ * `true`.
321
+ *
322
+ * @param right - The link that executes when the `test` function returns
323
+ * `false`. If the `right` link is not provided, the request is forwarded to
324
+ * the next link in the chain.
325
+ */
326
+ split(test: (op: ApolloLink.Operation) => boolean, left: ApolloLink, right?: ApolloLink): ApolloLink;
327
+ /**
328
+ * Combines the link with other links into a single composed link.
329
+ *
330
+ * @example
331
+ *
332
+ * ```ts
333
+ * import { ApolloLink, HttpLink } from "@apollo/client";
334
+ *
335
+ * const previousLink = new ApolloLink((operation, forward) => {
336
+ * // Handle the request
337
+ *
338
+ * return forward(operation);
339
+ * });
340
+ *
341
+ * const link = previousLink.concat(
342
+ * link1,
343
+ * link2,
344
+ * new HttpLink({ uri: "http://localhost:4000/graphql" })
345
+ * );
346
+ * ```
347
+ */
348
+ concat(...links: ApolloLink[]): ApolloLink;
349
+ private combine;
350
+ /**
351
+ * Runs the request handler for the provided operation.
352
+ *
353
+ * > [!NOTE]
354
+ * > This is called by the `ApolloLink.execute` function for you and should
355
+ * > not be called directly. Prefer using `ApolloLink.execute` to make the
356
+ * > request instead.
357
+ */
358
+ request(operation: ApolloLink.Operation, forward: ApolloLink.ForwardFunction): Observable<ApolloLink.Result>;
13
359
  /**
14
360
  * @internal
15
361
  * Used to iterate through all links that are concatenations or `split` links.
@@ -1,79 +1,250 @@
1
- import { __DEV__ } from "@apollo/client/utilities/environment";
2
1
  import { EMPTY } from "rxjs";
3
- import { createOperation, transformOperation, validateOperation, } from "@apollo/client/link/utils";
2
+ import { createOperation } from "@apollo/client/link/utils";
3
+ import { __DEV__ } from "@apollo/client/utilities/environment";
4
4
  import { invariant, newInvariantError, } from "@apollo/client/utilities/invariant";
5
- function passthrough(op, forward) {
6
- return (forward ? forward(op) : EMPTY);
7
- }
8
- function toLink(handler) {
9
- return typeof handler === "function" ? new ApolloLink(handler) : handler;
10
- }
11
- function isTerminating(link) {
12
- return link.request.length <= 1;
13
- }
5
+ /**
6
+ * The base class for all links in Apollo Client. A link represents either a
7
+ * self-contained modification to a GraphQL operation or a side effect (such as
8
+ * logging).
9
+ *
10
+ * @remarks
11
+ *
12
+ * Links enable you to customize Apollo Client's request flow by composing
13
+ * together different pieces of functionality into a chain of links. Each
14
+ * link represents a specific capability, such as adding authentication headers,
15
+ * retrying failed requests, batching operations, or sending requests to a
16
+ * GraphQL server.
17
+ *
18
+ * Every link must define a request handler via its constructor or by extending
19
+ * this class and implementing the `request` method.
20
+ *
21
+ * @example
22
+ *
23
+ * ```ts
24
+ * import { ApolloLink } from "@apollo/client";
25
+ *
26
+ * const link = new ApolloLink((operation, forward) => {
27
+ * console.log("Operation:", operation.operationName);
28
+ * return forward(operation);
29
+ * });
30
+ * ```
31
+ */
14
32
  export class ApolloLink {
33
+ /**
34
+ * Creates a link that completes immediately and does not emit a result.
35
+ *
36
+ * @example
37
+ *
38
+ * ```ts
39
+ * const link = ApolloLink.empty();
40
+ * ```
41
+ */
15
42
  static empty() {
16
43
  return new ApolloLink(() => EMPTY);
17
44
  }
45
+ /**
46
+ * Composes multiple links into a single composed link that executes each
47
+ * provided link in serial order.
48
+ *
49
+ * @example
50
+ *
51
+ * ```ts
52
+ * import { from, HttpLink, ApolloLink } from "@apollo/client";
53
+ * import { RetryLink } from "@apollo/client/link/retry";
54
+ * import MyAuthLink from "../auth";
55
+ *
56
+ * const link = ApolloLink.from([
57
+ * new RetryLink(),
58
+ * new MyAuthLink(),
59
+ * new HttpLink({ uri: "http://localhost:4000/graphql" }),
60
+ * ]);
61
+ * ```
62
+ *
63
+ * @param links - An array of `ApolloLink` instances or request handlers that
64
+ * are executed in serial order.
65
+ */
18
66
  static from(links) {
19
67
  if (links.length === 0)
20
68
  return ApolloLink.empty();
21
- return links.map(toLink).reduce((x, y) => x.concat(y));
69
+ const [first, ...rest] = links;
70
+ return first.concat(...rest);
22
71
  }
23
- static split(test, left, right) {
24
- const leftLink = toLink(left);
25
- const rightLink = toLink(right || new ApolloLink(passthrough));
26
- let ret;
27
- if (isTerminating(leftLink) && isTerminating(rightLink)) {
28
- ret = new ApolloLink((operation) => {
29
- return test(operation) ?
30
- leftLink.request(operation) || EMPTY
31
- : rightLink.request(operation) || EMPTY;
32
- });
33
- }
34
- else {
35
- ret = new ApolloLink((operation, forward) => {
36
- return test(operation) ?
37
- leftLink.request(operation, forward) || EMPTY
38
- : rightLink.request(operation, forward) || EMPTY;
39
- });
40
- }
41
- return Object.assign(ret, { left: leftLink, right: rightLink });
72
+ /**
73
+ * Creates a link that conditionally routes a request to different links.
74
+ *
75
+ * @example
76
+ *
77
+ * ```ts
78
+ * import { ApolloLink, HttpLink } from "@apollo/client";
79
+ *
80
+ * const link = ApolloLink.split(
81
+ * (operation) => operation.getContext().version === 1,
82
+ * new HttpLink({ uri: "http://localhost:4000/v1/graphql" }),
83
+ * new HttpLink({ uri: "http://localhost:4000/v2/graphql" })
84
+ * );
85
+ * ```
86
+ *
87
+ * @param test - A predicate function that receives the current `operation`
88
+ * and returns a boolean indicating which link to execute. Returning `true`
89
+ * executes the `left` link. Returning `false` executes the `right` link.
90
+ *
91
+ * @param left - The link that executes when the `test` function returns
92
+ * `true`.
93
+ *
94
+ * @param right - The link that executes when the `test` function returns
95
+ * `false`. If the `right` link is not provided, the request is forwarded to
96
+ * the next link in the chain.
97
+ */
98
+ static split(test, left, right = new ApolloLink((op, forward) => forward(op))) {
99
+ const link = new ApolloLink((operation, forward) => {
100
+ const result = test(operation);
101
+ if (__DEV__) {
102
+ if (typeof result !== "boolean") {
103
+ __DEV__ && invariant.warn(61, result);
104
+ }
105
+ }
106
+ return result ?
107
+ left.request(operation, forward)
108
+ : right.request(operation, forward);
109
+ });
110
+ return Object.assign(link, { left, right });
42
111
  }
43
- static execute(link, operation, context) {
44
- return (link.request(createOperation(operation.context, transformOperation(validateOperation(operation)), context)) || EMPTY);
112
+ /**
113
+ * Executes a GraphQL request against a link. The `execute` function begins
114
+ * the request by calling the request handler of the link.
115
+ *
116
+ * @example
117
+ *
118
+ * ```ts
119
+ * const observable = ApolloLink.execute(link, { query, variables }, { client });
120
+ *
121
+ * observable.subscribe({
122
+ * next(value) {
123
+ * console.log("Received", value);
124
+ * },
125
+ * error(error) {
126
+ * console.error("Oops got error", error);
127
+ * },
128
+ * complete() {
129
+ * console.log("Request complete");
130
+ * },
131
+ * });
132
+ * ```
133
+ *
134
+ * @param link - The `ApolloLink` instance to execute the request.
135
+ *
136
+ * @param request - The GraphQL request details, such as the `query` and
137
+ * `variables`.
138
+ *
139
+ * @param context - The execution context for the request, such as the
140
+ * `client` making the request.
141
+ */
142
+ static execute(link, request, context) {
143
+ return link.request(createOperation(request, context), () => {
144
+ if (__DEV__) {
145
+ __DEV__ && invariant.warn(62);
146
+ }
147
+ return EMPTY;
148
+ });
45
149
  }
46
- static concat(first, second) {
47
- const firstLink = toLink(first);
48
- if (isTerminating(firstLink)) {
49
- __DEV__ && invariant.warn(62, firstLink);
50
- return firstLink;
51
- }
52
- const nextLink = toLink(second);
53
- let ret;
54
- if (isTerminating(nextLink)) {
55
- ret = new ApolloLink((operation) => firstLink.request(operation, (op) => nextLink.request(op) || EMPTY) ||
56
- EMPTY);
57
- }
58
- else {
59
- ret = new ApolloLink((operation, forward) => {
60
- return (firstLink.request(operation, (op) => {
61
- return nextLink.request(op, forward) || EMPTY;
62
- }) || EMPTY);
63
- });
64
- }
65
- return Object.assign(ret, { left: firstLink, right: nextLink });
150
+ /**
151
+ * Combines multiple links into a single composed link.
152
+ *
153
+ * @example
154
+ *
155
+ * ```ts
156
+ * const link = ApolloLink.concat(firstLink, secondLink, thirdLink);
157
+ * ```
158
+ *
159
+ * @param links - The links to concatenate into a single link. Each link will
160
+ * execute in serial order.
161
+ *
162
+ * @deprecated Use `ApolloLink.from` instead. `ApolloLink.concat` will be
163
+ * removed in a future major version.
164
+ */
165
+ static concat(...links) {
166
+ return ApolloLink.from(links);
66
167
  }
67
168
  constructor(request) {
68
169
  if (request)
69
170
  this.request = request;
70
171
  }
172
+ /**
173
+ * Concatenates a link that conditionally routes a request to different links.
174
+ *
175
+ * @example
176
+ *
177
+ * ```ts
178
+ * import { ApolloLink, HttpLink } from "@apollo/client";
179
+ *
180
+ * const previousLink = new ApolloLink((operation, forward) => {
181
+ * // Handle the request
182
+ *
183
+ * return forward(operation);
184
+ * });
185
+ *
186
+ * const link = previousLink.split(
187
+ * (operation) => operation.getContext().version === 1,
188
+ * new HttpLink({ uri: "http://localhost:4000/v1/graphql" }),
189
+ * new HttpLink({ uri: "http://localhost:4000/v2/graphql" })
190
+ * );
191
+ * ```
192
+ *
193
+ * @param test - A predicate function that receives the current `operation`
194
+ * and returns a boolean indicating which link to execute. Returning `true`
195
+ * executes the `left` link. Returning `false` executes the `right` link.
196
+ *
197
+ * @param left - The link that executes when the `test` function returns
198
+ * `true`.
199
+ *
200
+ * @param right - The link that executes when the `test` function returns
201
+ * `false`. If the `right` link is not provided, the request is forwarded to
202
+ * the next link in the chain.
203
+ */
71
204
  split(test, left, right) {
72
- return this.concat(ApolloLink.split(test, left, right || new ApolloLink(passthrough)));
205
+ return this.concat(ApolloLink.split(test, left, right));
73
206
  }
74
- concat(next) {
75
- return ApolloLink.concat(this, next);
207
+ /**
208
+ * Combines the link with other links into a single composed link.
209
+ *
210
+ * @example
211
+ *
212
+ * ```ts
213
+ * import { ApolloLink, HttpLink } from "@apollo/client";
214
+ *
215
+ * const previousLink = new ApolloLink((operation, forward) => {
216
+ * // Handle the request
217
+ *
218
+ * return forward(operation);
219
+ * });
220
+ *
221
+ * const link = previousLink.concat(
222
+ * link1,
223
+ * link2,
224
+ * new HttpLink({ uri: "http://localhost:4000/graphql" })
225
+ * );
226
+ * ```
227
+ */
228
+ concat(...links) {
229
+ if (links.length === 0) {
230
+ return this;
231
+ }
232
+ return links.reduce(this.combine.bind(this), this);
76
233
  }
234
+ combine(left, right) {
235
+ const link = new ApolloLink((operation, forward) => {
236
+ return left.request(operation, (op) => right.request(op, forward));
237
+ });
238
+ return Object.assign(link, { left, right });
239
+ }
240
+ /**
241
+ * Runs the request handler for the provided operation.
242
+ *
243
+ * > [!NOTE]
244
+ * > This is called by the `ApolloLink.execute` function for you and should
245
+ * > not be called directly. Prefer using `ApolloLink.execute` to make the
246
+ * > request instead.
247
+ */
77
248
  request(operation, forward) {
78
249
  throw newInvariantError(63);
79
250
  }