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

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 (176) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/__cjs/cache/inmemory/writeToStore.cjs +1 -1
  3. package/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
  4. package/__cjs/core/ObservableQuery.cjs +1 -1
  5. package/__cjs/core/ObservableQuery.cjs.map +1 -1
  6. package/__cjs/core/QueryInfo.cjs +2 -6
  7. package/__cjs/core/QueryInfo.cjs.map +1 -1
  8. package/__cjs/core/index.cjs +1 -2
  9. package/__cjs/core/index.cjs.map +1 -1
  10. package/__cjs/core/index.d.cts +1 -2
  11. package/__cjs/invariantErrorCodes.cjs +9 -9
  12. package/__cjs/link/batch/batchLink.cjs +31 -5
  13. package/__cjs/link/batch/batchLink.cjs.map +1 -1
  14. package/__cjs/link/batch/batchLink.d.cts +102 -26
  15. package/__cjs/link/batch/batching.cjs.map +1 -1
  16. package/__cjs/link/batch/batching.d.cts +2 -2
  17. package/__cjs/link/batch/index.cjs +1 -2
  18. package/__cjs/link/batch/index.cjs.map +1 -1
  19. package/__cjs/link/batch/index.d.cts +1 -2
  20. package/__cjs/link/batch-http/BaseBatchHttpLink.cjs +156 -0
  21. package/__cjs/link/batch-http/BaseBatchHttpLink.cjs.map +1 -0
  22. package/__cjs/link/batch-http/BaseBatchHttpLink.d.cts +68 -0
  23. package/__cjs/link/batch-http/batchHttpLink.cjs +25 -130
  24. package/__cjs/link/batch-http/batchHttpLink.cjs.map +1 -1
  25. package/__cjs/link/batch-http/batchHttpLink.d.cts +40 -16
  26. package/__cjs/link/batch-http/index.cjs +2 -1
  27. package/__cjs/link/batch-http/index.cjs.map +1 -1
  28. package/__cjs/link/batch-http/index.d.cts +2 -1
  29. package/__cjs/link/client-awareness/ClientAwarenessLink.cjs +36 -3
  30. package/__cjs/link/client-awareness/ClientAwarenessLink.cjs.map +1 -1
  31. package/__cjs/link/client-awareness/ClientAwarenessLink.d.cts +55 -3
  32. package/__cjs/link/context/index.cjs +19 -0
  33. package/__cjs/link/context/index.cjs.map +1 -1
  34. package/__cjs/link/context/index.d.cts +64 -2
  35. package/__cjs/link/error/index.cjs +44 -0
  36. package/__cjs/link/error/index.cjs.map +1 -1
  37. package/__cjs/link/error/index.d.cts +64 -4
  38. package/__cjs/link/http/BaseHttpLink.cjs +60 -10
  39. package/__cjs/link/http/BaseHttpLink.cjs.map +1 -1
  40. package/__cjs/link/http/BaseHttpLink.d.cts +256 -2
  41. package/__cjs/link/http/HttpLink.cjs +23 -1
  42. package/__cjs/link/http/HttpLink.cjs.map +1 -1
  43. package/__cjs/link/http/HttpLink.d.cts +41 -141
  44. package/__cjs/link/http/checkFetcher.cjs +1 -1
  45. package/__cjs/link/http/index.cjs +1 -3
  46. package/__cjs/link/http/index.cjs.map +1 -1
  47. package/__cjs/link/http/index.d.cts +0 -2
  48. package/__cjs/link/http/parseAndCheckHttpResponse.cjs +1 -1
  49. package/__cjs/link/http/rewriteURIForGET.cjs +2 -3
  50. package/__cjs/link/http/rewriteURIForGET.cjs.map +1 -1
  51. package/__cjs/link/http/rewriteURIForGET.d.cts +2 -2
  52. package/__cjs/link/http/selectHttpOptionsAndBody.cjs.map +1 -1
  53. package/__cjs/link/http/selectHttpOptionsAndBody.d.cts +7 -7
  54. package/__cjs/link/persisted-queries/index.cjs +18 -2
  55. package/__cjs/link/persisted-queries/index.cjs.map +1 -1
  56. package/__cjs/link/persisted-queries/index.d.cts +204 -24
  57. package/__cjs/link/remove-typename/index.cjs.map +1 -1
  58. package/__cjs/link/remove-typename/index.d.cts +0 -1
  59. package/__cjs/link/remove-typename/removeTypenameFromVariables.cjs +48 -0
  60. package/__cjs/link/remove-typename/removeTypenameFromVariables.cjs.map +1 -1
  61. package/__cjs/link/remove-typename/removeTypenameFromVariables.d.cts +124 -8
  62. package/__cjs/link/retry/delayFunction.cjs.map +1 -1
  63. package/__cjs/link/retry/delayFunction.d.cts +2 -39
  64. package/__cjs/link/retry/retryFunction.cjs.map +1 -1
  65. package/__cjs/link/retry/retryFunction.d.cts +2 -29
  66. package/__cjs/link/retry/retryLink.cjs +35 -10
  67. package/__cjs/link/retry/retryLink.cjs.map +1 -1
  68. package/__cjs/link/retry/retryLink.d.cts +129 -4
  69. package/__cjs/link/schema/index.cjs +20 -0
  70. package/__cjs/link/schema/index.cjs.map +1 -1
  71. package/__cjs/link/schema/index.d.cts +129 -7
  72. package/__cjs/link/subscriptions/index.cjs +23 -0
  73. package/__cjs/link/subscriptions/index.cjs.map +1 -1
  74. package/__cjs/link/subscriptions/index.d.cts +23 -0
  75. package/__cjs/link/ws/index.cjs +35 -1
  76. package/__cjs/link/ws/index.cjs.map +1 -1
  77. package/__cjs/link/ws/index.d.cts +63 -5
  78. package/__cjs/react/hooks/useSyncExternalStore.cjs +2 -6
  79. package/__cjs/react/hooks/useSyncExternalStore.cjs.map +1 -1
  80. package/__cjs/utilities/internal/removeDirectivesFromDocument.cjs +2 -6
  81. package/__cjs/utilities/internal/removeDirectivesFromDocument.cjs.map +1 -1
  82. package/__cjs/utilities/subscriptions/relay/index.cjs +1 -2
  83. package/__cjs/utilities/subscriptions/relay/index.cjs.map +1 -1
  84. package/__cjs/version.cjs +1 -1
  85. package/cache/inmemory/writeToStore.js +1 -1
  86. package/cache/inmemory/writeToStore.js.map +1 -1
  87. package/core/ObservableQuery.js +1 -1
  88. package/core/ObservableQuery.js.map +1 -1
  89. package/core/QueryInfo.js +1 -2
  90. package/core/QueryInfo.js.map +1 -1
  91. package/core/index.d.ts +1 -2
  92. package/core/index.js +1 -1
  93. package/core/index.js.map +1 -1
  94. package/invariantErrorCodes.js +9 -9
  95. package/link/batch/batchLink.d.ts +103 -27
  96. package/link/batch/batchLink.js +30 -3
  97. package/link/batch/batchLink.js.map +1 -1
  98. package/link/batch/batching.d.ts +2 -2
  99. package/link/batch/batching.js.map +1 -1
  100. package/link/batch/index.d.ts +1 -2
  101. package/link/batch/index.js +1 -1
  102. package/link/batch/index.js.map +1 -1
  103. package/link/batch-http/BaseBatchHttpLink.d.ts +68 -0
  104. package/link/batch-http/BaseBatchHttpLink.js +152 -0
  105. package/link/batch-http/BaseBatchHttpLink.js.map +1 -0
  106. package/link/batch-http/batchHttpLink.d.ts +40 -16
  107. package/link/batch-http/batchHttpLink.js +23 -127
  108. package/link/batch-http/batchHttpLink.js.map +1 -1
  109. package/link/batch-http/index.d.ts +2 -1
  110. package/link/batch-http/index.js +2 -1
  111. package/link/batch-http/index.js.map +1 -1
  112. package/link/client-awareness/ClientAwarenessLink.d.ts +56 -4
  113. package/link/client-awareness/ClientAwarenessLink.js +36 -3
  114. package/link/client-awareness/ClientAwarenessLink.js.map +1 -1
  115. package/link/context/index.d.ts +65 -3
  116. package/link/context/index.js +19 -0
  117. package/link/context/index.js.map +1 -1
  118. package/link/error/index.d.ts +65 -5
  119. package/link/error/index.js +44 -0
  120. package/link/error/index.js.map +1 -1
  121. package/link/http/BaseHttpLink.d.ts +257 -3
  122. package/link/http/BaseHttpLink.js +60 -10
  123. package/link/http/BaseHttpLink.js.map +1 -1
  124. package/link/http/HttpLink.d.ts +41 -141
  125. package/link/http/HttpLink.js +23 -1
  126. package/link/http/HttpLink.js.map +1 -1
  127. package/link/http/checkFetcher.js +1 -1
  128. package/link/http/index.d.ts +0 -2
  129. package/link/http/index.js +0 -1
  130. package/link/http/index.js.map +1 -1
  131. package/link/http/parseAndCheckHttpResponse.js +1 -1
  132. package/link/http/rewriteURIForGET.d.ts +2 -2
  133. package/link/http/rewriteURIForGET.js +2 -3
  134. package/link/http/rewriteURIForGET.js.map +1 -1
  135. package/link/http/selectHttpOptionsAndBody.d.ts +7 -7
  136. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  137. package/link/persisted-queries/index.d.ts +205 -25
  138. package/link/persisted-queries/index.js +18 -2
  139. package/link/persisted-queries/index.js.map +1 -1
  140. package/link/remove-typename/index.d.ts +0 -1
  141. package/link/remove-typename/index.js.map +1 -1
  142. package/link/remove-typename/removeTypenameFromVariables.d.ts +124 -8
  143. package/link/remove-typename/removeTypenameFromVariables.js +48 -0
  144. package/link/remove-typename/removeTypenameFromVariables.js.map +1 -1
  145. package/link/retry/delayFunction.d.ts +2 -39
  146. package/link/retry/delayFunction.js.map +1 -1
  147. package/link/retry/retryFunction.d.ts +2 -29
  148. package/link/retry/retryFunction.js.map +1 -1
  149. package/link/retry/retryLink.d.ts +130 -5
  150. package/link/retry/retryLink.js +36 -11
  151. package/link/retry/retryLink.js.map +1 -1
  152. package/link/schema/index.d.ts +130 -8
  153. package/link/schema/index.js +20 -0
  154. package/link/schema/index.js.map +1 -1
  155. package/link/subscriptions/index.d.ts +23 -0
  156. package/link/subscriptions/index.js +23 -0
  157. package/link/subscriptions/index.js.map +1 -1
  158. package/link/ws/index.d.ts +63 -5
  159. package/link/ws/index.js +31 -1
  160. package/link/ws/index.js.map +1 -1
  161. package/package.json +1 -1
  162. package/react/hooks/useSyncExternalStore.js +1 -1
  163. package/react/hooks/useSyncExternalStore.js.map +1 -1
  164. package/react/hooks-compiled/useSyncExternalStore.js +1 -1
  165. package/react/hooks-compiled/useSyncExternalStore.js.map +1 -1
  166. package/utilities/internal/removeDirectivesFromDocument.js +1 -2
  167. package/utilities/internal/removeDirectivesFromDocument.js.map +1 -1
  168. package/utilities/subscriptions/relay/index.js +1 -2
  169. package/utilities/subscriptions/relay/index.js.map +1 -1
  170. package/version.js +1 -1
  171. package/__cjs/link/http/serializeFetchParameter.cjs +0 -18
  172. package/__cjs/link/http/serializeFetchParameter.cjs.map +0 -1
  173. package/__cjs/link/http/serializeFetchParameter.d.cts +0 -6
  174. package/link/http/serializeFetchParameter.d.ts +0 -6
  175. package/link/http/serializeFetchParameter.js +0 -14
  176. package/link/http/serializeFetchParameter.js.map +0 -1
@@ -8,6 +8,50 @@ import { ApolloLink } from "@apollo/client/link";
8
8
  export function onError(errorHandler) {
9
9
  return new ErrorLink(errorHandler);
10
10
  }
11
+ /**
12
+ * Use the `ErrorLink` to perform custom logic when a [GraphQL or network error](https://apollographql.com/docs/react/data/error-handling)
13
+ * occurs.
14
+ *
15
+ * @remarks
16
+ *
17
+ * This link is used after the GraphQL operation completes and execution is
18
+ * moving back up your [link chain](https://apollographql.com/docs/react/introduction#handling-a-response). The `errorHandler` function should
19
+ * not return a value unless you want to [retry the operation](https://apollographql.com/docs/react/data/error-handling#retrying-operations).
20
+ *
21
+ * For more information on the types of errors that might be encountered, see
22
+ * the guide on [error handling](https://apollographql.com/docs/react/data/error-handling).
23
+ *
24
+ * @example
25
+ *
26
+ * ```ts
27
+ * import { ErrorLink } from "@apollo/client/link/error";
28
+ * import {
29
+ * CombinedGraphQLErrors,
30
+ * CombinedProtocolErrors,
31
+ * } from "@apollo/client/errors";
32
+ *
33
+ * // Log any GraphQL errors, protocol errors, or network error that occurred
34
+ * const errorLink = new ErrorLink(({ error, operation }) => {
35
+ * if (CombinedGraphQLErrors.is(error)) {
36
+ * error.errors.forEach(({ message, locations, path }) =>
37
+ * console.log(
38
+ * `[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
39
+ * )
40
+ * );
41
+ * } else if (CombinedProtocolErrors.is(error)) {
42
+ * error.errors.forEach(({ message, extensions }) =>
43
+ * console.log(
44
+ * `[Protocol error]: Message: ${message}, Extensions: ${JSON.stringify(
45
+ * extensions
46
+ * )}`
47
+ * )
48
+ * );
49
+ * } else {
50
+ * console.error(`[Network error]: ${error}`);
51
+ * }
52
+ * });
53
+ * ```
54
+ */
11
55
  export class ErrorLink extends ApolloLink {
12
56
  constructor(errorHandler) {
13
57
  super((operation, forward) => {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/link/error/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAGlC,OAAO,EACL,qBAAqB,EACrB,8BAA8B,EAC9B,sBAAsB,EACtB,WAAW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EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC;4BAEhD,IAAI,CAAC,UAAU,EAAE,CAAC;gCAChB,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;4BACxB,CAAC;wBACH,CAAC;wBACD,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;4BACf,aAAa,GAAG,YAAY,CAAC;gCAC3B,SAAS;gCACT,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC;gCACzB,OAAO;6BACR,CAAC,CAAC;4BACH,UAAU,GAAG,aAAa,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC;4BAEhD,IAAI,CAAC,UAAU,EAAE,CAAC;gCAChB,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;4BACxB,CAAC;wBACH,CAAC;wBACD,QAAQ,EAAE,GAAG,EAAE;4BACb,+DAA+D;4BAC/D,yBAAyB;4BACzB,IAAI,CAAC,aAAa,EAAE,CAAC;gCACnB,QAAQ,CAAC,QAAQ,EAAE,CAAC;4BACtB,CAAC;wBACH,CAAC;qBACF,CAAC,CAAC;gBACL,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACX,YAAY,CAAC,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;oBAC5D,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBACpB,CAAC;gBAED,OAAO,GAAG,EAAE;oBACV,IAAI,GAAG;wBAAE,GAAG,CAAC,WAAW,EAAE,CAAC;oBAC3B,IAAI,UAAU;wBAAE,UAAU,CAAC,WAAW,EAAE,CAAC;gBAC3C,CAAC,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type { Subscription } from \"rxjs\";\nimport { Observable } from \"rxjs\";\n\nimport type { ErrorLike } from \"@apollo/client\";\nimport {\n CombinedGraphQLErrors,\n graphQLResultHasProtocolErrors,\n PROTOCOL_ERRORS_SYMBOL,\n toErrorLike,\n} from \"@apollo/client/errors\";\nimport { ApolloLink } from \"@apollo/client/link\";\n\nexport declare namespace ErrorLink {\n /**\n * Callback to be triggered when an error occurs within the link stack.\n */\n export interface ErrorHandler {\n (options: ErrorHandlerOptions): Observable<ApolloLink.Result> | void;\n }\n\n export interface ErrorHandlerOptions {\n /**\n * The error that occurred during the operation execution. This can be a\n * `CombinedGraphQLErrors` instance (for GraphQL errors) or another error\n * type (for network errors).\n *\n * Use `CombinedGraphQLErrors.is(error)` to check if it's a GraphQL error with an `errors` array.\n */\n error: ErrorLike;\n /**\n * The raw GraphQL result from the server (if available), which may include\n * partial data alongside errors.\n */\n result?: ApolloLink.Result;\n\n /** The details of the GraphQL operation that produced an error. */\n operation: ApolloLink.Operation;\n\n /**\n * A function that calls the next link in the link chain. Calling\n * `return forward(operation)` in your `ErrorLink` callback\n * [retries the operation](../../data/error-handling#retrying-operations), returning a new observable for the\n * upstream link to subscribe to.\n */\n forward: ApolloLink.ForwardFunction;\n }\n}\n\n// For backwards compatibility.\nexport import ErrorHandler = ErrorLink.ErrorHandler;\n\n/**\n * @deprecated\n * Use `ErrorLink` from `@apollo/client/link/error` instead.\n */\nexport function onError(errorHandler: ErrorHandler) {\n return new ErrorLink(errorHandler);\n}\n\nexport class ErrorLink extends ApolloLink {\n constructor(errorHandler: ErrorLink.ErrorHandler) {\n super((operation, forward) => {\n return new Observable((observer) => {\n let sub: Subscription | undefined;\n let retriedSub: Subscription | undefined;\n let retriedResult: ReturnType<ErrorHandler>;\n\n try {\n sub = forward(operation).subscribe({\n next: (result) => {\n const handler =\n operation.client[\"queryManager\"].incrementalHandler;\n const errors =\n handler.isIncrementalResult(result) ?\n handler.extractErrors(result)\n : result.errors;\n if (errors) {\n retriedResult = errorHandler({\n error: new CombinedGraphQLErrors(result, errors),\n result,\n operation,\n forward,\n });\n } else if (graphQLResultHasProtocolErrors(result)) {\n retriedResult = errorHandler({\n error: result.extensions[PROTOCOL_ERRORS_SYMBOL],\n result,\n operation,\n forward,\n });\n }\n\n retriedSub = retriedResult?.subscribe(observer);\n\n if (!retriedSub) {\n observer.next(result);\n }\n },\n error: (error) => {\n retriedResult = errorHandler({\n operation,\n error: toErrorLike(error),\n forward,\n });\n retriedSub = retriedResult?.subscribe(observer);\n\n if (!retriedSub) {\n observer.error(error);\n }\n },\n complete: () => {\n // disable the previous sub from calling complete on observable\n // if retry is in flight.\n if (!retriedResult) {\n observer.complete();\n }\n },\n });\n } catch (e) {\n errorHandler({ error: toErrorLike(e), operation, forward });\n observer.error(e);\n }\n\n return () => {\n if (sub) sub.unsubscribe();\n if (retriedSub) retriedSub.unsubscribe();\n };\n });\n });\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/link/error/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAGlC,OAAO,EACL,qBAAqB,EACrB,8BAA8B,EAC9B,sBAAsB,EACtB,WAAW,GACZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAsDjD;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAC,YAAoC;IAC1D,OAAO,IAAI,SAAS,CAAC,YAAY,CAAC,CAAC;AACrC,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,MAAM,OAAO,SAAU,SAAQ,UAAU;IACvC,YAAY,YAAoC;QAC9C,KAAK,CAAC,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE;YAC3B,OAAO,IAAI,UAAU,CAAC,CAAC,QAAQ,EAAE,EAAE;gBACjC,IAAI,GAA6B,CAAC;gBAClC,IAAI,UAAoC,CAAC;gBACzC,IAAI,aAAiD,CAAC;gBAEtD,IAAI,CAAC;oBACH,GAAG,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC;wBACjC,IAAI,EA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AC/D,yBAAyB;4BACzB,IAAI,CAAC,aAAa,EAAE,CAAC;gCACnB,QAAQ,CAAC,QAAQ,EAAE,CAAC;4BACtB,CAAC;wBACH,CAAC;qBACF,CAAC,CAAC;gBACL,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACX,YAAY,CAAC,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;oBAC5D,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBACpB,CAAC;gBAED,OAAO,GAAG,EAAE;oBACV,IAAI,GAAG;wBAAE,GAAG,CAAC,WAAW,EAAE,CAAC;oBAC3B,IAAI,UAAU;wBAAE,UAAU,CAAC,WAAW,EAAE,CAAC;gBAC3C,CAAC,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type { Subscription } from \"rxjs\";\nimport { Observable } from \"rxjs\";\n\nimport type { ErrorLike } from \"@apollo/client\";\nimport {\n CombinedGraphQLErrors,\n graphQLResultHasProtocolErrors,\n PROTOCOL_ERRORS_SYMBOL,\n toErrorLike,\n} from \"@apollo/client/errors\";\nimport { ApolloLink } from \"@apollo/client/link\";\n\nexport declare namespace ErrorLink {\n // Using a different namespace name to avoid clash with\n // `ApolloLink.DocumentationTypes`\n export namespace ErrorLinkDocumentationTypes {\n /**\n * Callback that is called by `ErrorLink` when an error occurs from a\n * downstream link in link chain.\n *\n * @param options - The options object provided by `ErrorLink` to the error\n * handler when an error occurs.\n */\n export function ErrorHandler(\n options: ErrorHandlerOptions\n ): Observable<ApolloLink.Result> | void;\n }\n\n /** {@inheritDoc @apollo/client/link/error!ErrorLink.ErrorLinkDocumentationTypes.ErrorHandler:function(1)} */\n export interface ErrorHandler {\n (options: ErrorHandlerOptions): Observable<ApolloLink.Result> | void;\n }\n\n /**\n * The object provided to the `ErrorHandler` callback function.\n */\n export interface ErrorHandlerOptions {\n /**\n * The error that occurred during the operation execution. This can be a\n * `CombinedGraphQLErrors` instance (for GraphQL errors) or another error\n * type (for network errors).\n *\n * Use `CombinedGraphQLErrors.is(error)` to check if it's a GraphQL error with an `errors` array.\n */\n error: ErrorLike;\n /**\n * The raw GraphQL result from the server (if available), which may include\n * partial data alongside errors.\n */\n result?: ApolloLink.Result;\n\n /** The details of the GraphQL operation that produced an error. */\n operation: ApolloLink.Operation;\n\n /**\n * A function that calls the next link in the link chain. Calling\n * `return forward(operation)` in your `ErrorLink` callback\n * [retries the operation](../../data/error-handling#retrying-operations), returning a new observable for the\n * upstream link to subscribe to.\n */\n forward: ApolloLink.ForwardFunction;\n }\n}\n\n/**\n * @deprecated\n * Use `ErrorLink` from `@apollo/client/link/error` instead.\n */\nexport function onError(errorHandler: ErrorLink.ErrorHandler) {\n return new ErrorLink(errorHandler);\n}\n\n/**\n * Use the `ErrorLink` to perform custom logic when a [GraphQL or network error](https://apollographql.com/docs/react/data/error-handling)\n * occurs.\n *\n * @remarks\n *\n * This link is used after the GraphQL operation completes and execution is\n * moving back up your [link chain](https://apollographql.com/docs/react/introduction#handling-a-response). The `errorHandler` function should\n * not return a value unless you want to [retry the operation](https://apollographql.com/docs/react/data/error-handling#retrying-operations).\n *\n * For more information on the types of errors that might be encountered, see\n * the guide on [error handling](https://apollographql.com/docs/react/data/error-handling).\n *\n * @example\n *\n * ```ts\n * import { ErrorLink } from \"@apollo/client/link/error\";\n * import {\n * CombinedGraphQLErrors,\n * CombinedProtocolErrors,\n * } from \"@apollo/client/errors\";\n *\n * // Log any GraphQL errors, protocol errors, or network error that occurred\n * const errorLink = new ErrorLink(({ error, operation }) => {\n * if (CombinedGraphQLErrors.is(error)) {\n * error.errors.forEach(({ message, locations, path }) =>\n * console.log(\n * `[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`\n * )\n * );\n * } else if (CombinedProtocolErrors.is(error)) {\n * error.errors.forEach(({ message, extensions }) =>\n * console.log(\n * `[Protocol error]: Message: ${message}, Extensions: ${JSON.stringify(\n * extensions\n * )}`\n * )\n * );\n * } else {\n * console.error(`[Network error]: ${error}`);\n * }\n * });\n * ```\n */\nexport class ErrorLink extends ApolloLink {\n constructor(errorHandler: ErrorLink.ErrorHandler) {\n super((operation, forward) => {\n return new Observable((observer) => {\n let sub: Subscription | undefined;\n let retriedSub: Subscription | undefined;\n let retriedResult: ReturnType<ErrorLink.ErrorHandler>;\n\n try {\n sub = forward(operation).subscribe({\n next: (result) => {\n const handler =\n operation.client[\"queryManager\"].incrementalHandler;\n const errors =\n handler.isIncrementalResult(result) ?\n handler.extractErrors(result)\n : result.errors;\n if (errors) {\n retriedResult = errorHandler({\n error: new CombinedGraphQLErrors(result, errors),\n result,\n operation,\n forward,\n });\n } else if (graphQLResultHasProtocolErrors(result)) {\n retriedResult = errorHandler({\n error: result.extensions[PROTOCOL_ERRORS_SYMBOL],\n result,\n operation,\n forward,\n });\n }\n\n retriedSub = retriedResult?.subscribe(observer);\n\n if (!retriedSub) {\n observer.next(result);\n }\n },\n error: (error) => {\n retriedResult = errorHandler({\n operation,\n error: toErrorLike(error),\n forward,\n });\n retriedSub = retriedResult?.subscribe(observer);\n\n if (!retriedSub) {\n observer.error(error);\n }\n },\n complete: () => {\n // disable the previous sub from calling complete on observable\n // if retry is in flight.\n if (!retriedResult) {\n observer.complete();\n }\n },\n });\n } catch (e) {\n errorHandler({ error: toErrorLike(e), operation, forward });\n observer.error(e);\n }\n\n return () => {\n if (sub) sub.unsubscribe();\n if (retriedSub) retriedSub.unsubscribe();\n };\n });\n });\n }\n}\n"]}
@@ -1,6 +1,260 @@
1
+ import type { ASTNode, print } from "graphql";
1
2
  import { ApolloLink } from "@apollo/client/link";
2
- import type { HttpLink } from "./HttpLink.js";
3
+ export declare namespace BaseHttpLink {
4
+ /**
5
+ * Options passed to `BaseHttpLink` through [request context](https://apollographql.com/docs/react/api/link/introduction#managing-context). Previous
6
+ * non-terminating links in the link chain also can set these values to
7
+ * customize the behavior of `BaseHttpLink` for each operation.
8
+ *
9
+ * > [!NOTE]
10
+ * > Some of these values can also be provided to the `HttpLink` constructor.
11
+ * > If a value is provided to both, the value in `context` takes precedence.
12
+ */
13
+ interface ContextOptions {
14
+ /**
15
+ * The URL of the GraphQL endpoint to send requests to. Can also be a
16
+ * function that accepts an `ApolloLink.Operation` object and returns the
17
+ * string URL to use for that operation.
18
+ *
19
+ * @defaultValue "/graphql"
20
+ */
21
+ uri?: string | BaseHttpLink.UriFunction;
22
+ /**
23
+ * An object representing headers to include in every HTTP request.
24
+ *
25
+ * @example
26
+ *
27
+ * ```json
28
+ * {
29
+ * "Authorization": "Bearer 1234"
30
+ * }
31
+ * ```
32
+ */
33
+ headers?: Record<string, string>;
34
+ /**
35
+ * The credentials policy to use for each `fetch` call.
36
+ */
37
+ credentials?: RequestCredentials;
38
+ /**
39
+ * Any overrides of the fetch options argument to pass to the fetch call.
40
+ *
41
+ * An object containing options to use for each call to `fetch`. If a
42
+ * particular option is not included in this object, the default value of
43
+ * that option is used.
44
+ *
45
+ * > [!NOTE]
46
+ * > If you set `fetchOptions.method` to `GET`, `HttpLink` follows [standard
47
+ * > GraphQL HTTP GET encoding](http://graphql.org/learn/serving-over-http/#get-request).
48
+ *
49
+ * See [available options](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
50
+ */
51
+ fetchOptions?: RequestInit;
52
+ /**
53
+ * An object that configures advanced functionality, such as support for
54
+ * persisted queries.
55
+ */
56
+ http?: BaseHttpLink.HttpOptions;
57
+ }
58
+ /**
59
+ * Options passed to `BaseHttpLink` through the `http` property of a request
60
+ * context.
61
+ */
62
+ interface HttpOptions {
63
+ /**
64
+ * If `true`, includes the `extensions` field in operations sent to your
65
+ * GraphQL endpoint.
66
+ *
67
+ * @defaultValue true
68
+ */
69
+ includeExtensions?: boolean;
70
+ /**
71
+ * If `false`, the GraphQL query string is not included in the request. Set
72
+ * this option if you're sending a request that uses a [persisted query](https://www.apollographql.com/docs/react/api/link/persisted-queries/).
73
+ *
74
+ * @defaultValue `true`
75
+ */
76
+ includeQuery?: boolean;
77
+ /**
78
+ * If `true`, header names won't be automatically normalized to lowercase.
79
+ * This allows for non-http-spec-compliant servers that might expect
80
+ * capitalized header names.
81
+ *
82
+ * @defaultValue false
83
+ */
84
+ preserveHeaderCase?: boolean;
85
+ /**
86
+ * A list of additional `accept` headers to include in the request,
87
+ * as defined in https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.2
88
+ *
89
+ * @example
90
+ *
91
+ * ```json
92
+ * ["application/custom+json;q=1.0"]
93
+ * ```
94
+ */
95
+ accept?: string[];
96
+ }
97
+ namespace Shared {
98
+ /** These options are shared between `BaseHttpLink` and `BaseBatchHttpLink` */
99
+ interface Options {
100
+ /**
101
+ * The URL of the GraphQL endpoint to send requests to. Can also be a
102
+ * function that accepts an `ApolloLink.Operation` object and returns the
103
+ * string URL to use for that operation.
104
+ *
105
+ * @defaultValue "/graphql"
106
+ */
107
+ uri?: string | BaseHttpLink.UriFunction;
108
+ /**
109
+ * If `true`, includes the `extensions` field in operations sent to your
110
+ * GraphQL endpoint.
111
+ *
112
+ * @defaultValue true
113
+ */
114
+ includeExtensions?: boolean;
115
+ /**
116
+ * A function to use instead of calling the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch) directly
117
+ * when sending HTTP requests to your GraphQL endpoint. The function must
118
+ * conform to the signature of `fetch`.
119
+ *
120
+ * By default, the Fetch API is used unless it isn't available in your
121
+ * runtime environment.
122
+ *
123
+ * See [Customizing `fetch`](https://apollographql.com/docs/react/api/link/introduction#customizing-fetch).
124
+ */
125
+ fetch?: typeof fetch;
126
+ /**
127
+ * An object representing headers to include in every HTTP request.
128
+ *
129
+ * @example
130
+ *
131
+ * ```json
132
+ * {
133
+ * "Authorization": "Bearer 1234"
134
+ * }
135
+ * ```
136
+ */
137
+ headers?: Record<string, string>;
138
+ /**
139
+ * If `true`, header names won't be automatically normalized to lowercase.
140
+ * This allows for non-http-spec-compliant servers that might expect
141
+ * capitalized header names.
142
+ *
143
+ * @defaultValue false
144
+ */
145
+ preserveHeaderCase?: boolean;
146
+ /**
147
+ * The credentials policy to use for each `fetch` call.
148
+ */
149
+ credentials?: RequestCredentials;
150
+ /**
151
+ * Any overrides of the fetch options argument to pass to the fetch call.
152
+ *
153
+ * An object containing options to use for each call to `fetch`. If a
154
+ * particular option is not included in this object, the default value of
155
+ * that option is used.
156
+ *
157
+ * > [!NOTE]
158
+ * > If you set `fetchOptions.method` to `GET`, `HttpLink` follows [standard
159
+ * > GraphQL HTTP GET encoding](http://graphql.org/learn/serving-over-http/#get-request).
160
+ *
161
+ * See [available options](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
162
+ */
163
+ fetchOptions?: RequestInit;
164
+ /**
165
+ * If `true`, unused variables from the operation will not be stripped from
166
+ * the request and will instead be sent to the GraphQL endpoint.
167
+ *
168
+ * @remarks
169
+ * Unused variables are likely to trigger server-side validation errors,
170
+ * per https://spec.graphql.org/draft/#sec-All-Variables-Used.
171
+ * `includeUnusedVariables` can be useful if your server deviates
172
+ * from the GraphQL specification by not strictly enforcing that rule.
173
+ *
174
+ * @defaultValue false
175
+ */
176
+ includeUnusedVariables?: boolean;
177
+ /**
178
+ * A function to use when transforming a GraphQL document into a string. It
179
+ * accepts an `ASTNode` (typically a `DocumentNode`) and the original `print`
180
+ * function as arguments, and is expected to return a string. This option
181
+ * enables you to, for example, use `stripIgnoredCharacters` to remove
182
+ * whitespace from queries.
183
+ *
184
+ * By default the [GraphQL `print` function](https://graphql.org/graphql-js/language/#print) is used.
185
+ *
186
+ * @example
187
+ *
188
+ * ```ts
189
+ * import { stripIgnoredCharacters } from "graphql";
190
+ *
191
+ * const httpLink = new HttpLink({
192
+ * uri: "/graphql",
193
+ * print: (ast, originalPrint) => stripIgnoredCharacters(originalPrint(ast)),
194
+ * });
195
+ * ```
196
+ */
197
+ print?: BaseHttpLink.Printer;
198
+ }
199
+ }
200
+ /**
201
+ * Options provided to the `BaseHttpLink` constructor.
202
+ *
203
+ * > [!NOTE]
204
+ * > Some of these options are also available to override in [request context](https://apollographql.com/docs/react/api/link/introduction#managing-context).
205
+ * > Context options override the options passed to the constructor. Treat
206
+ * > these options as default values that are used when the request context
207
+ * > does not override the value.
208
+ */
209
+ interface Options extends Shared.Options {
210
+ /**
211
+ * If `true`, the link uses an HTTP `GET` request when sending query
212
+ * operations to your GraphQL endpoint. Mutation operations continue to use
213
+ * `POST` requests. If you want all operations to use `GET` requests,
214
+ * set `fetchOptions.method` instead.
215
+ *
216
+ * @defaultValue false
217
+ */
218
+ useGETForQueries?: boolean;
219
+ }
220
+ interface Body {
221
+ query?: string;
222
+ operationName?: string;
223
+ variables?: Record<string, any>;
224
+ extensions?: Record<string, any>;
225
+ }
226
+ type Printer = (node: ASTNode, originalPrint: typeof print) => string;
227
+ type UriFunction = (operation: ApolloLink.Operation) => string;
228
+ }
229
+ /**
230
+ * `BaseHttpLink` is a terminating link that sends a GraphQL operation to a
231
+ * remote endpoint over HTTP. It serves as a base link to `HttpLink`.
232
+ *
233
+ * @remarks
234
+ *
235
+ * `BaseHttpLink` supports both POST and GET requests, and you can configure
236
+ * HTTP options on a per-operation basis. You can use these options for
237
+ * authentication, persisted queries, dynamic URIs, and other granular updates.
238
+ *
239
+ * > [!NOTE]
240
+ * > Prefer using `HttpLink` over `BaseHttpLink`. Use `BaseHttpLink` when you
241
+ * > need to disable client awareness features and would like to tree-shake
242
+ * > the implementation of `ClientAwarenessLink` out of your app bundle.
243
+ *
244
+ * @example
245
+ *
246
+ * ```ts
247
+ * import { BaseHttpLink } from "@apollo/client/link/http";
248
+ *
249
+ * const link = new BaseHttpLink({
250
+ * uri: "http://localhost:4000/graphql",
251
+ * headers: {
252
+ * authorization: `Bearer ${token}`,
253
+ * },
254
+ * });
255
+ * ```
256
+ */
3
257
  export declare class BaseHttpLink extends ApolloLink {
4
- constructor(linkOptions?: HttpLink.Options);
258
+ constructor(options?: BaseHttpLink.Options);
5
259
  }
6
- //# sourceMappingURL=BaseHttpLink.d.ts.map
260
+ //# sourceMappingURL=BaseHttpLink.d.ts.map
@@ -10,13 +10,41 @@ import { parseAndCheckHttpResponse, readMultipartBody, } from "./parseAndCheckHt
10
10
  import { rewriteURIForGET } from "./rewriteURIForGET.js";
11
11
  import { defaultPrinter, fallbackHttpConfig, selectHttpOptionsAndBodyInternal, } from "./selectHttpOptionsAndBody.js";
12
12
  import { selectURI } from "./selectURI.js";
13
- import { serializeFetchParameter } from "./serializeFetchParameter.js";
14
13
  const backupFetch = maybe(() => fetch);
14
+ function noop() { }
15
+ /**
16
+ * `BaseHttpLink` is a terminating link that sends a GraphQL operation to a
17
+ * remote endpoint over HTTP. It serves as a base link to `HttpLink`.
18
+ *
19
+ * @remarks
20
+ *
21
+ * `BaseHttpLink` supports both POST and GET requests, and you can configure
22
+ * HTTP options on a per-operation basis. You can use these options for
23
+ * authentication, persisted queries, dynamic URIs, and other granular updates.
24
+ *
25
+ * > [!NOTE]
26
+ * > Prefer using `HttpLink` over `BaseHttpLink`. Use `BaseHttpLink` when you
27
+ * > need to disable client awareness features and would like to tree-shake
28
+ * > the implementation of `ClientAwarenessLink` out of your app bundle.
29
+ *
30
+ * @example
31
+ *
32
+ * ```ts
33
+ * import { BaseHttpLink } from "@apollo/client/link/http";
34
+ *
35
+ * const link = new BaseHttpLink({
36
+ * uri: "http://localhost:4000/graphql",
37
+ * headers: {
38
+ * authorization: `Bearer ${token}`,
39
+ * },
40
+ * });
41
+ * ```
42
+ */
15
43
  export class BaseHttpLink extends ApolloLink {
16
- constructor(linkOptions = {}) {
44
+ constructor(options = {}) {
17
45
  let { uri = "/graphql",
18
46
  // use default global fetch if nothing passed in
19
- fetch: preferredFetch, print = defaultPrinter, includeExtensions, preserveHeaderCase, useGETForQueries, includeUnusedVariables = false, ...requestOptions } = linkOptions;
47
+ fetch: preferredFetch, print = defaultPrinter, includeExtensions, preserveHeaderCase, useGETForQueries, includeUnusedVariables = false, ...requestOptions } = options;
20
48
  if (__DEV__) {
21
49
  // Make sure at least one of preferredFetch, window.fetch, or backupFetch is
22
50
  // defined, so requests won't fail at runtime.
@@ -49,11 +77,33 @@ export class BaseHttpLink extends ApolloLink {
49
77
  if (body.variables && !includeUnusedVariables) {
50
78
  body.variables = filterOperationVariables(body.variables, operation.query);
51
79
  }
52
- let controller;
53
- if (!options.signal && typeof AbortController !== "undefined") {
54
- controller = new AbortController();
55
- options.signal = controller.signal;
80
+ let controller = new AbortController();
81
+ let cleanupController = () => {
82
+ controller = undefined;
83
+ };
84
+ if (options.signal) {
85
+ const externalSignal = options.signal;
86
+ // in an ideal world we could use `AbortSignal.any` here, but
87
+ // React Native uses https://github.com/mysticatea/abort-controller as
88
+ // a polyfill for `AbortController`, and it does not support `AbortSignal.any`.
89
+ const listener = () => {
90
+ controller?.abort(externalSignal.reason);
91
+ };
92
+ externalSignal.addEventListener("abort", listener, { once: true });
93
+ cleanupController = () => {
94
+ controller?.signal.removeEventListener("abort", cleanupController);
95
+ controller = undefined;
96
+ // on cleanup, we need to stop listening to `options.signal` to avoid memory leaks
97
+ externalSignal.removeEventListener("abort", listener);
98
+ cleanupController = noop;
99
+ };
100
+ // react native also does not support the addEventListener `signal` option
101
+ // so we have to simulate that ourself
102
+ controller.signal.addEventListener("abort", cleanupController, {
103
+ once: true,
104
+ });
56
105
  }
106
+ options.signal = controller.signal;
57
107
  if (useGETForQueries && !isMutationOperation(operation.query)) {
58
108
  options.method = "GET";
59
109
  }
@@ -66,7 +116,7 @@ export class BaseHttpLink extends ApolloLink {
66
116
  chosenURI = newURI;
67
117
  }
68
118
  else {
69
- options.body = serializeFetchParameter(body, "Payload");
119
+ options.body = JSON.stringify(body);
70
120
  }
71
121
  // Prefer linkOptions.fetch (preferredFetch) if provided, and otherwise
72
122
  // fall back to the *current* global window.fetch function (see issue
@@ -87,11 +137,11 @@ export class BaseHttpLink extends ApolloLink {
87
137
  }
88
138
  })
89
139
  .then(() => {
90
- controller = undefined;
140
+ cleanupController();
91
141
  observer.complete();
92
142
  })
93
143
  .catch((err) => {
94
- controller = undefined;
144
+ cleanupController();
95
145
  observer.error(err);
96
146
  });
97
147
  return () => {
@@ -1 +1 @@
1
- {"version":3,"file":"BaseHttpLink.js","sourceRoot":"","sources":["../../../src/link/http/BaseHttpLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EACL,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,2CAA2C,CAAC;AAElE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EACL,yBAAyB,EACzB,iBAAiB,GAClB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,gCAAgC,GACjC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,MAAM,WAAW,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;AAEvC,MAAM,OAAO,YAAa,SAAQ,UAAU;IAC1C,YAAY,cAAgC,EAAE;QAC5C,IAAI,EACF,GAAG,GAAG,UAAU;QAChB,gDAAgD;QAChD,KAAK,EAAE,cAAc,EACrB,KAAK,GAAG,cAAc,EACtB,iBAAiB,EAC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,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;oBACnC,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;oBAEpD,IAAI,KAAK,KAAK,IAAI,IAAI,oBAAoB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;wBACvD,OAAO,iBAAiB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;oBACnD,CAAC;yBAAM,CAAC;wBACN,OAAO,yBAAyB,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CACxD,YAAY,CACb,CAAC;oBACJ,CAAC;gBACH,CAAC,CAAC;qBACD,IAAI,CAAC,GAAG,EAAE;oBACT,UAAU,GAAG,SAAS,CAAC;oBACvB,QAAQ,CAAC,QAAQ,EAAE,CAAC;gBACtB,CAAC,CAAC;qBACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;oBACb,UAAU,GAAG,SAAS,CAAC;oBACvB,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACtB,CAAC,CAAC,CAAC;gBAEL,OAAO,GAAG,EAAE;oBACV,qCAAqC;oBACrC,oEAAoE;oBACpE,IAAI,UAAU;wBAAE,UAAU,CAAC,KAAK,EAAE,CAAC;gBACrC,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\";\nimport { filterOperationVariables } from \"@apollo/client/link/utils\";\nimport {\n isMutationOperation,\n isSubscriptionOperation,\n} from \"@apollo/client/utilities\";\nimport { __DEV__ } from \"@apollo/client/utilities/environment\";\nimport { compact } from \"@apollo/client/utilities/internal\";\nimport { maybe } from \"@apollo/client/utilities/internal/globals\";\n\nimport { checkFetcher } from \"./checkFetcher.js\";\nimport type { HttpLink } from \"./HttpLink.js\";\nimport {\n parseAndCheckHttpResponse,\n readMultipartBody,\n} from \"./parseAndCheckHttpResponse.js\";\nimport { rewriteURIForGET } from \"./rewriteURIForGET.js\";\nimport {\n defaultPrinter,\n fallbackHttpConfig,\n selectHttpOptionsAndBodyInternal,\n} from \"./selectHttpOptionsAndBody.js\";\nimport { selectURI } from \"./selectURI.js\";\nimport { serializeFetchParameter } from \"./serializeFetchParameter.js\";\n\nconst backupFetch = maybe(() => fetch);\n\nexport class BaseHttpLink extends ApolloLink {\n constructor(linkOptions: HttpLink.Options = {}) {\n let {\n uri = \"/graphql\",\n // use default global fetch if nothing passed in\n fetch: preferredFetch,\n print = defaultPrinter,\n includeExtensions,\n preserveHeaderCase,\n useGETForQueries,\n includeUnusedVariables = false,\n ...requestOptions\n } = linkOptions;\n\n if (__DEV__) {\n // Make sure at least one of preferredFetch, window.fetch, or backupFetch is\n // 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 super((operation) => {\n let chosenURI = selectURI(operation, uri);\n\n const context = operation.getContext();\n\n const http = { ...context.http };\n if (isSubscriptionOperation(operation.query)) {\n http.accept = [\n \"multipart/mixed;boundary=graphql;subscriptionSpec=1.0\",\n ...(http.accept || []),\n ];\n }\n\n const contextConfig = {\n 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 { options, body } = selectHttpOptionsAndBodyInternal(\n operation,\n print,\n fallbackHttpConfig,\n linkConfig,\n contextConfig\n );\n\n if (body.variables && !includeUnusedVariables) {\n body.variables = filterOperationVariables(\n body.variables,\n operation.query\n );\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 if (useGETForQueries && !isMutationOperation(operation.query)) {\n options.method = \"GET\";\n }\n\n return new Observable((observer) => {\n if (options.method === \"GET\") {\n const { newURI, parseError } = rewriteURIForGET(chosenURI, body);\n if (parseError) {\n throw parseError;\n }\n chosenURI = newURI;\n } else {\n options.body = serializeFetchParameter(body, \"Payload\");\n }\n // Prefer linkOptions.fetch (preferredFetch) if provided, and otherwise\n // fall back to the *current* global window.fetch function (see issue\n // #7832), or (if all else fails) the backupFetch function we saved when\n // this module was first evaluated. This last option protects against the\n // removal of window.fetch, which is unlikely but not impossible.\n const currentFetch =\n preferredFetch || maybe(() => fetch) || backupFetch;\n\n const observerNext = observer.next.bind(observer);\n currentFetch!(chosenURI, options)\n .then((response) => {\n operation.setContext({ response });\n const ctype = response.headers?.get(\"content-type\");\n\n if (ctype !== null && /^multipart\\/mixed/i.test(ctype)) {\n return readMultipartBody(response, observerNext);\n } else {\n return parseAndCheckHttpResponse(operation)(response).then(\n observerNext\n );\n }\n })\n .then(() => {\n controller = undefined;\n observer.complete();\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}\n"]}
1
+ {"version":3,"file":"BaseHttpLink.js","sourceRoot":"","sources":["../../../src/link/http/BaseHttpLink.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EACL,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,2CAA2C,CAAC;AAElE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACj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AC,CAAC;gBAClD,YAAa,CAAC,SAAS,EAAE,OAAO,CAAC;qBAC9B,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;oBACjB,SAAS,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;oBACnC,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;oBAEpD,IAAI,KAAK,KAAK,IAAI,IAAI,oBAAoB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;wBACvD,OAAO,iBAAiB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;oBACnD,CAAC;yBAAM,CAAC;wBACN,OAAO,yBAAyB,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CACxD,YAAY,CACb,CAAC;oBACJ,CAAC;gBACH,CAAC,CAAC;qBACD,IAAI,CAAC,GAAG,EAAE;oBACT,iBAAiB,EAAE,CAAC;oBACpB,QAAQ,CAAC,QAAQ,EAAE,CAAC;gBACtB,CAAC,CAAC;qBACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;oBACb,iBAAiB,EAAE,CAAC;oBACpB,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACtB,CAAC,CAAC,CAAC;gBAEL,OAAO,GAAG,EAAE;oBACV,qCAAqC;oBACrC,oEAAoE;oBACpE,IAAI,UAAU;wBAAE,UAAU,CAAC,KAAK,EAAE,CAAC;gBACrC,CAAC,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type { ASTNode, print } from \"graphql\";\nimport { Observable } from \"rxjs\";\n\nimport { ApolloLink } from \"@apollo/client/link\";\nimport { filterOperationVariables } from \"@apollo/client/link/utils\";\nimport {\n isMutationOperation,\n isSubscriptionOperation,\n} from \"@apollo/client/utilities\";\nimport { __DEV__ } from \"@apollo/client/utilities/environment\";\nimport { compact } from \"@apollo/client/utilities/internal\";\nimport { maybe } from \"@apollo/client/utilities/internal/globals\";\n\nimport { checkFetcher } from \"./checkFetcher.js\";\nimport {\n parseAndCheckHttpResponse,\n readMultipartBody,\n} from \"./parseAndCheckHttpResponse.js\";\nimport { rewriteURIForGET } from \"./rewriteURIForGET.js\";\nimport {\n defaultPrinter,\n fallbackHttpConfig,\n selectHttpOptionsAndBodyInternal,\n} from \"./selectHttpOptionsAndBody.js\";\nimport { selectURI } from \"./selectURI.js\";\n\nconst backupFetch = maybe(() => fetch);\nfunction noop() {}\n\nexport declare namespace BaseHttpLink {\n /**\n * Options passed to `BaseHttpLink` through [request context](https://apollographql.com/docs/react/api/link/introduction#managing-context). Previous\n * non-terminating links in the link chain also can set these values to\n * customize the behavior of `BaseHttpLink` for each operation.\n *\n * > [!NOTE]\n * > Some of these values can also be provided to the `HttpLink` constructor.\n * > If a value is provided to both, the value in `context` takes precedence.\n */\n interface ContextOptions {\n /** {@inheritDoc @apollo/client/link/http!BaseHttpLink.Shared.Options#uri:member} */\n uri?: string | BaseHttpLink.UriFunction;\n\n /** {@inheritDoc @apollo/client/link/http!BaseHttpLink.Shared.Options#headers:member} */\n headers?: Record<string, string>;\n\n /** {@inheritDoc @apollo/client/link/http!BaseHttpLink.Shared.Options#credentials:member} */\n credentials?: RequestCredentials;\n\n /** {@inheritDoc @apollo/client/link/http!BaseHttpLink.Shared.Options#fetchOptions:member} */\n fetchOptions?: RequestInit;\n\n /**\n * An object that configures advanced functionality, such as support for\n * persisted queries.\n */\n http?: BaseHttpLink.HttpOptions;\n }\n\n /**\n * Options passed to `BaseHttpLink` through the `http` property of a request\n * context.\n */\n export interface HttpOptions {\n /** {@inheritDoc @apollo/client/link/http!BaseHttpLink.Shared.Options#includeExtensions:member} */\n includeExtensions?: boolean;\n\n /**\n * If `false`, the GraphQL query string is not included in the request. Set\n * this option if you're sending a request that uses a [persisted query](https://www.apollographql.com/docs/react/api/link/persisted-queries/).\n *\n * @defaultValue `true`\n */\n includeQuery?: boolean;\n\n /** {@inheritDoc @apollo/client/link/http!BaseHttpLink.Shared.Options#preserveHeaderCase:member} */\n preserveHeaderCase?: boolean;\n\n /**\n * A list of additional `accept` headers to include in the request,\n * as defined in https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.2\n *\n * @example\n *\n * ```json\n * [\"application/custom+json;q=1.0\"]\n * ```\n */\n accept?: string[];\n }\n\n export namespace Shared {\n /** These options are shared between `BaseHttpLink` and `BaseBatchHttpLink` */\n export interface Options {\n /**\n * The URL of the GraphQL endpoint to send requests to. Can also be a\n * function that accepts an `ApolloLink.Operation` object and returns the\n * string URL to use for that operation.\n *\n * @defaultValue \"/graphql\"\n */\n uri?: string | BaseHttpLink.UriFunction;\n\n /**\n * If `true`, includes the `extensions` field in operations sent to your\n * GraphQL endpoint.\n *\n * @defaultValue true\n */\n includeExtensions?: boolean;\n\n /**\n * A function to use instead of calling the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch) directly\n * when sending HTTP requests to your GraphQL endpoint. The function must\n * conform to the signature of `fetch`.\n *\n * By default, the Fetch API is used unless it isn't available in your\n * runtime environment.\n *\n * See [Customizing `fetch`](https://apollographql.com/docs/react/api/link/introduction#customizing-fetch).\n */\n fetch?: typeof fetch;\n\n /**\n * An object representing headers to include in every HTTP request.\n *\n * @example\n *\n * ```json\n * {\n * \"Authorization\": \"Bearer 1234\"\n * }\n * ```\n */\n headers?: Record<string, string>;\n\n /**\n * If `true`, header names won't be automatically normalized to lowercase.\n * This allows for non-http-spec-compliant servers that might expect\n * capitalized header names.\n *\n * @defaultValue false\n */\n preserveHeaderCase?: boolean;\n\n /**\n * The credentials policy to use for each `fetch` call.\n */\n credentials?: RequestCredentials;\n\n /**\n * Any overrides of the fetch options argument to pass to the fetch call.\n *\n * An object containing options to use for each call to `fetch`. If a\n * particular option is not included in this object, the default value of\n * that option is used.\n *\n * > [!NOTE]\n * > If you set `fetchOptions.method` to `GET`, `HttpLink` follows [standard\n * > GraphQL HTTP GET encoding](http://graphql.org/learn/serving-over-http/#get-request).\n *\n * See [available options](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)\n */\n fetchOptions?: RequestInit;\n\n /**\n * If `true`, unused variables from the operation will not be stripped from\n * the request and will instead be sent to the GraphQL endpoint.\n *\n * @remarks\n * Unused variables are likely to trigger server-side validation errors,\n * per https://spec.graphql.org/draft/#sec-All-Variables-Used.\n * `includeUnusedVariables` can be useful if your server deviates\n * from the GraphQL specification by not strictly enforcing that rule.\n *\n * @defaultValue false\n */\n includeUnusedVariables?: boolean;\n /**\n * A function to use when transforming a GraphQL document into a string. It\n * accepts an `ASTNode` (typically a `DocumentNode`) and the original `print`\n * function as arguments, and is expected to return a string. This option\n * enables you to, for example, use `stripIgnoredCharacters` to remove\n * whitespace from queries.\n *\n * By default the [GraphQL `print` function](https://graphql.org/graphql-js/language/#print) is used.\n *\n * @example\n *\n * ```ts\n * import { stripIgnoredCharacters } from \"graphql\";\n *\n * const httpLink = new HttpLink({\n * uri: \"/graphql\",\n * print: (ast, originalPrint) => stripIgnoredCharacters(originalPrint(ast)),\n * });\n * ```\n */\n print?: BaseHttpLink.Printer;\n }\n }\n\n /**\n * Options provided to the `BaseHttpLink` constructor.\n *\n * > [!NOTE]\n * > Some of these options are also available to override in [request context](https://apollographql.com/docs/react/api/link/introduction#managing-context).\n * > Context options override the options passed to the constructor. Treat\n * > these options as default values that are used when the request context\n * > does not override the value.\n */\n interface Options extends Shared.Options {\n /**\n * If `true`, the link uses an HTTP `GET` request when sending query\n * operations to your GraphQL endpoint. Mutation operations continue to use\n * `POST` requests. If you want all operations to use `GET` requests,\n * set `fetchOptions.method` instead.\n *\n * @defaultValue false\n */\n useGETForQueries?: boolean;\n }\n\n interface Body {\n query?: string;\n operationName?: string;\n variables?: Record<string, any>;\n extensions?: Record<string, any>;\n }\n\n type Printer = (node: ASTNode, originalPrint: typeof print) => string;\n type UriFunction = (operation: ApolloLink.Operation) => string;\n}\n\n/**\n * `BaseHttpLink` is a terminating link that sends a GraphQL operation to a\n * remote endpoint over HTTP. It serves as a base link to `HttpLink`.\n *\n * @remarks\n *\n * `BaseHttpLink` supports both POST and GET requests, and you can configure\n * HTTP options on a per-operation basis. You can use these options for\n * authentication, persisted queries, dynamic URIs, and other granular updates.\n *\n * > [!NOTE]\n * > Prefer using `HttpLink` over `BaseHttpLink`. Use `BaseHttpLink` when you\n * > need to disable client awareness features and would like to tree-shake\n * > the implementation of `ClientAwarenessLink` out of your app bundle.\n *\n * @example\n *\n * ```ts\n * import { BaseHttpLink } from \"@apollo/client/link/http\";\n *\n * const link = new BaseHttpLink({\n * uri: \"http://localhost:4000/graphql\",\n * headers: {\n * authorization: `Bearer ${token}`,\n * },\n * });\n * ```\n */\nexport class BaseHttpLink extends ApolloLink {\n constructor(options: BaseHttpLink.Options = {}) {\n let {\n uri = \"/graphql\",\n // use default global fetch if nothing passed in\n fetch: preferredFetch,\n print = defaultPrinter,\n includeExtensions,\n preserveHeaderCase,\n useGETForQueries,\n includeUnusedVariables = false,\n ...requestOptions\n } = options;\n\n if (__DEV__) {\n // Make sure at least one of preferredFetch, window.fetch, or backupFetch is\n // 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 super((operation) => {\n let chosenURI = selectURI(operation, uri);\n\n const context = operation.getContext();\n\n const http = { ...context.http };\n if (isSubscriptionOperation(operation.query)) {\n http.accept = [\n \"multipart/mixed;boundary=graphql;subscriptionSpec=1.0\",\n ...(http.accept || []),\n ];\n }\n\n const contextConfig = {\n 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 { options, body } = selectHttpOptionsAndBodyInternal(\n operation,\n print,\n fallbackHttpConfig,\n linkConfig,\n contextConfig\n );\n\n if (body.variables && !includeUnusedVariables) {\n body.variables = filterOperationVariables(\n body.variables,\n operation.query\n );\n }\n\n let controller: AbortController | undefined = new AbortController();\n let cleanupController = () => {\n controller = undefined;\n };\n if (options.signal) {\n const externalSignal: AbortSignal = options.signal;\n // in an ideal world we could use `AbortSignal.any` here, but\n // React Native uses https://github.com/mysticatea/abort-controller as\n // a polyfill for `AbortController`, and it does not support `AbortSignal.any`.\n\n const listener = () => {\n controller?.abort(externalSignal.reason);\n };\n externalSignal.addEventListener(\"abort\", listener, { once: true });\n cleanupController = () => {\n controller?.signal.removeEventListener(\"abort\", cleanupController);\n controller = undefined;\n // on cleanup, we need to stop listening to `options.signal` to avoid memory leaks\n externalSignal.removeEventListener(\"abort\", listener);\n cleanupController = noop;\n };\n // react native also does not support the addEventListener `signal` option\n // so we have to simulate that ourself\n controller.signal.addEventListener(\"abort\", cleanupController, {\n once: true,\n });\n }\n options.signal = controller.signal;\n\n if (useGETForQueries && !isMutationOperation(operation.query)) {\n options.method = \"GET\";\n }\n\n return new Observable((observer) => {\n if (options.method === \"GET\") {\n const { newURI, parseError } = rewriteURIForGET(chosenURI, body);\n if (parseError) {\n throw parseError;\n }\n chosenURI = newURI;\n } else {\n options.body = JSON.stringify(body);\n }\n // Prefer linkOptions.fetch (preferredFetch) if provided, and otherwise\n // fall back to the *current* global window.fetch function (see issue\n // #7832), or (if all else fails) the backupFetch function we saved when\n // this module was first evaluated. This last option protects against the\n // removal of window.fetch, which is unlikely but not impossible.\n const currentFetch =\n preferredFetch || maybe(() => fetch) || backupFetch;\n\n const observerNext = observer.next.bind(observer);\n currentFetch!(chosenURI, options)\n .then((response) => {\n operation.setContext({ response });\n const ctype = response.headers?.get(\"content-type\");\n\n if (ctype !== null && /^multipart\\/mixed/i.test(ctype)) {\n return readMultipartBody(response, observerNext);\n } else {\n return parseAndCheckHttpResponse(operation)(response).then(\n observerNext\n );\n }\n })\n .then(() => {\n cleanupController();\n observer.complete();\n })\n .catch((err) => {\n cleanupController();\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}\n"]}