@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
@@ -1,16 +1,29 @@
1
- import { Observable, throwError } from "rxjs";
2
1
  import { ApolloLink } from "@apollo/client/link";
3
- import { BatchLink } from "@apollo/client/link/batch";
4
2
  import { ClientAwarenessLink } from "@apollo/client/link/client-awareness";
5
- import { checkFetcher, defaultPrinter, fallbackHttpConfig, parseAndCheckHttpResponse, selectHttpOptionsAndBodyInternal, selectURI, serializeFetchParameter, } from "@apollo/client/link/http";
6
- import { filterOperationVariables } from "@apollo/client/link/utils";
7
- import { __DEV__ } from "@apollo/client/utilities/environment";
8
- import { compact } from "@apollo/client/utilities/internal";
9
- import { maybe } from "@apollo/client/utilities/internal/globals";
10
- const backupFetch = maybe(() => fetch);
3
+ import { BaseBatchHttpLink } from "./BaseBatchHttpLink.js";
11
4
  /**
12
- * Transforms Operation for into HTTP results.
13
- * context can include the headers property, which will be passed to the fetch function
5
+ * `BatchHttpLink` is a terminating link that batches array of individual
6
+ * GraphQL operations into a single HTTP request that's sent to a single GraphQL
7
+ * endpoint. It combines the functionality of `BaseBatchHttpLink` and
8
+ * `ClientAwarenessLink` into a single link.
9
+ *
10
+ * @remarks
11
+ *
12
+ * If you use `BatchHttpLink` instead of `HttpLink` as your terminating link,
13
+ * Apollo Client automatically batches executed GraphQL operations and transmits
14
+ * them to your server according to the batching options you provide.
15
+ *
16
+ * @example
17
+ *
18
+ * ```ts
19
+ * import { BatchHttpLink } from "@apollo/client/link/batch-http";
20
+ *
21
+ * const link = new BatchHttpLink({
22
+ * uri: "http://localhost:4000/graphql",
23
+ * batchMax: 5, // No more than 5 operations per batch
24
+ * batchInterval: 20, // Wait no more than 20ms after first batched operation
25
+ * });
26
+ * ```
14
27
  */
15
28
  export class BatchHttpLink extends ApolloLink {
16
29
  constructor(options = {}) {
@@ -22,121 +35,4 @@ export class BatchHttpLink extends ApolloLink {
22
35
  Object.assign(this, { left, right });
23
36
  }
24
37
  }
25
- export class BaseBatchHttpLink extends ApolloLink {
26
- batchDebounce;
27
- batchInterval;
28
- batchMax;
29
- batcher;
30
- constructor(fetchParams) {
31
- super();
32
- let { uri = "/graphql",
33
- // use default global fetch if nothing is passed in
34
- fetch: preferredFetch, print = defaultPrinter, includeExtensions, preserveHeaderCase, batchInterval, batchDebounce, batchMax, batchKey, includeUnusedVariables = false, ...requestOptions } = fetchParams || {};
35
- if (__DEV__) {
36
- // Make sure at least one of preferredFetch, window.fetch, or backupFetch
37
- // is defined, so requests won't fail at runtime.
38
- checkFetcher(preferredFetch || backupFetch);
39
- }
40
- const linkConfig = {
41
- http: compact({ includeExtensions, preserveHeaderCase }),
42
- options: requestOptions.fetchOptions,
43
- credentials: requestOptions.credentials,
44
- headers: requestOptions.headers,
45
- };
46
- this.batchDebounce = batchDebounce;
47
- this.batchInterval = batchInterval || 10;
48
- this.batchMax = batchMax || 10;
49
- const batchHandler = (operations) => {
50
- const chosenURI = selectURI(operations[0], uri);
51
- const context = operations[0].getContext();
52
- const contextConfig = {
53
- http: context.http,
54
- options: context.fetchOptions,
55
- credentials: context.credentials,
56
- headers: context.headers,
57
- };
58
- //uses fallback, link, and then context to build options
59
- const optsAndBody = operations.map((operation) => {
60
- const result = selectHttpOptionsAndBodyInternal(operation, print, fallbackHttpConfig, linkConfig, contextConfig);
61
- if (result.body.variables && !includeUnusedVariables) {
62
- result.body.variables = filterOperationVariables(result.body.variables, operation.query);
63
- }
64
- return result;
65
- });
66
- const loadedBody = optsAndBody.map(({ body }) => body);
67
- const options = optsAndBody[0].options;
68
- // There's no spec for using GET with batches.
69
- if (options.method === "GET") {
70
- return throwError(() => new Error("apollo-link-batch-http does not support GET requests"));
71
- }
72
- try {
73
- options.body = serializeFetchParameter(loadedBody, "Payload");
74
- }
75
- catch (parseError) {
76
- return throwError(() => parseError);
77
- }
78
- let controller;
79
- if (!options.signal && typeof AbortController !== "undefined") {
80
- controller = new AbortController();
81
- options.signal = controller.signal;
82
- }
83
- return new Observable((observer) => {
84
- // Prefer BatchHttpLink.Options.fetch (preferredFetch) if provided, and
85
- // otherwise fall back to the *current* global window.fetch function
86
- // (see issue #7832), or (if all else fails) the backupFetch function we
87
- // saved when this module was first evaluated. This last option protects
88
- // against the removal of window.fetch, which is unlikely but not
89
- // impossible.
90
- const currentFetch = preferredFetch || maybe(() => fetch) || backupFetch;
91
- currentFetch(chosenURI, options)
92
- .then((response) => {
93
- // Make the raw response available in the context.
94
- operations.forEach((operation) => operation.setContext({ response }));
95
- return response;
96
- })
97
- .then(parseAndCheckHttpResponse(operations))
98
- .then((result) => {
99
- controller = undefined;
100
- // we have data and can send it to back up the link chain
101
- observer.next(result);
102
- observer.complete();
103
- return result;
104
- })
105
- .catch((err) => {
106
- controller = undefined;
107
- observer.error(err);
108
- });
109
- return () => {
110
- // XXX support canceling this request
111
- // https://developers.google.com/web/updates/2017/09/abortable-fetch
112
- if (controller)
113
- controller.abort();
114
- };
115
- });
116
- };
117
- batchKey =
118
- batchKey ||
119
- ((operation) => {
120
- const context = operation.getContext();
121
- const contextConfig = {
122
- http: context.http,
123
- options: context.fetchOptions,
124
- credentials: context.credentials,
125
- headers: context.headers,
126
- };
127
- //may throw error if config not serializable
128
- return selectURI(operation, uri) + JSON.stringify(contextConfig);
129
- });
130
- this.batcher = new BatchLink({
131
- batchDebounce: this.batchDebounce,
132
- batchInterval: this.batchInterval,
133
- batchMax: this.batchMax,
134
- batchKey,
135
- batchHandler,
136
- });
137
- }
138
- request(operation, forward) {
139
- return this.batcher.request(operation, forward);
140
- }
141
- }
142
38
  //# sourceMappingURL=batchHttpLink.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"batchHttpLink.js","sourceRoot":"","sources":["../../../src/link/batch-http/batchHttpLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAE3E,OAAO,EACL,YAAY,EACZ,cAAc,EACd,kBAAkB,EAClB,yBAAyB,EACzB,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AAa;YACjC,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,QAAQ;YACR,YAAY;SACb,CAAC,CAAC;IACL,CAAC;IAEM,OAAO,CACZ,SAA+B,EAC/B,OAAmC;QAEnC,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC;CACF","sourcesContent":["import { Observable, throwError } from \"rxjs\";\n\nimport { ApolloLink } from \"@apollo/client/link\";\nimport type { BatchHandler } from \"@apollo/client/link/batch\";\nimport { BatchLink } from \"@apollo/client/link/batch\";\nimport { ClientAwarenessLink } from \"@apollo/client/link/client-awareness\";\nimport type { HttpLink } from \"@apollo/client/link/http\";\nimport {\n checkFetcher,\n defaultPrinter,\n fallbackHttpConfig,\n parseAndCheckHttpResponse,\n selectHttpOptionsAndBodyInternal,\n selectURI,\n serializeFetchParameter,\n} from \"@apollo/client/link/http\";\nimport { filterOperationVariables } from \"@apollo/client/link/utils\";\nimport { __DEV__ } from \"@apollo/client/utilities/environment\";\nimport { compact } from \"@apollo/client/utilities/internal\";\nimport { maybe } from \"@apollo/client/utilities/internal/globals\";\n\nexport declare namespace BatchHttpLink {\n export type Options = Pick<\n BatchLink.Options,\n \"batchMax\" | \"batchDebounce\" | \"batchInterval\" | \"batchKey\"\n > &\n Omit<HttpLink.Options, \"useGETForQueries\">;\n\n export type ContextOptions = HttpLink.ContextOptions;\n}\n\nconst backupFetch = maybe(() => fetch);\n\n/**\n * Transforms Operation for into HTTP results.\n * context can include the headers property, which will be passed to the fetch function\n */\nexport class BatchHttpLink extends ApolloLink {\n constructor(\n options: BatchHttpLink.Options & ClientAwarenessLink.Options = {}\n ) {\n const { left, right, request } = ApolloLink.from([\n new ClientAwarenessLink(options),\n new BaseBatchHttpLink(options),\n ]);\n super(request);\n Object.assign(this, { left, right });\n }\n}\nexport class BaseBatchHttpLink extends ApolloLink {\n private batchDebounce?: boolean;\n private batchInterval: number;\n private batchMax: number;\n private batcher: ApolloLink;\n\n constructor(fetchParams?: BatchHttpLink.Options) {\n super();\n\n let {\n uri = \"/graphql\",\n // use default global fetch if nothing is passed in\n fetch: preferredFetch,\n print = defaultPrinter,\n includeExtensions,\n preserveHeaderCase,\n batchInterval,\n batchDebounce,\n batchMax,\n batchKey,\n includeUnusedVariables = false,\n ...requestOptions\n } = fetchParams || ({} as BatchHttpLink.Options);\n\n if (__DEV__) {\n // Make sure at least one of preferredFetch, window.fetch, or backupFetch\n // is defined, so requests won't fail at runtime.\n checkFetcher(preferredFetch || backupFetch);\n }\n\n const linkConfig = {\n http: compact({ includeExtensions, preserveHeaderCase }),\n options: requestOptions.fetchOptions,\n credentials: requestOptions.credentials,\n headers: requestOptions.headers,\n };\n\n this.batchDebounce = batchDebounce;\n this.batchInterval = batchInterval || 10;\n this.batchMax = batchMax || 10;\n\n const batchHandler: BatchHandler = (operations) => {\n const chosenURI = selectURI(operations[0], uri);\n\n const context = operations[0].getContext();\n\n const contextConfig = {\n http: context.http,\n options: context.fetchOptions,\n credentials: context.credentials,\n headers: context.headers,\n };\n\n //uses fallback, link, and then context to build options\n const optsAndBody = operations.map((operation) => {\n const result = selectHttpOptionsAndBodyInternal(\n operation,\n print,\n fallbackHttpConfig,\n linkConfig,\n contextConfig\n );\n\n if (result.body.variables && !includeUnusedVariables) {\n result.body.variables = filterOperationVariables(\n result.body.variables,\n operation.query\n );\n }\n\n return result;\n });\n\n const loadedBody = optsAndBody.map(({ body }) => body);\n const options = optsAndBody[0].options;\n\n // There's no spec for using GET with batches.\n if (options.method === \"GET\") {\n return throwError(\n () =>\n new Error(\"apollo-link-batch-http does not support GET requests\")\n );\n }\n\n try {\n (options as any).body = serializeFetchParameter(loadedBody, \"Payload\");\n } catch (parseError) {\n return throwError(() => parseError);\n }\n\n let controller: AbortController | undefined;\n if (!options.signal && typeof AbortController !== \"undefined\") {\n controller = new AbortController();\n options.signal = controller.signal;\n }\n\n return new Observable((observer) => {\n // Prefer BatchHttpLink.Options.fetch (preferredFetch) if provided, and\n // otherwise fall back to the *current* global window.fetch function\n // (see issue #7832), or (if all else fails) the backupFetch function we\n // saved when this module was first evaluated. This last option protects\n // against the removal of window.fetch, which is unlikely but not\n // impossible.\n const currentFetch =\n preferredFetch || maybe(() => fetch) || backupFetch;\n\n currentFetch!(chosenURI, options)\n .then((response) => {\n // Make the raw response available in the context.\n operations.forEach((operation) =>\n operation.setContext({ response })\n );\n return response;\n })\n .then(parseAndCheckHttpResponse(operations))\n .then((result) => {\n controller = undefined;\n // we have data and can send it to back up the link chain\n observer.next(result);\n observer.complete();\n return result;\n })\n .catch((err) => {\n controller = undefined;\n observer.error(err);\n });\n\n return () => {\n // XXX support canceling this request\n // https://developers.google.com/web/updates/2017/09/abortable-fetch\n if (controller) controller.abort();\n };\n });\n };\n\n batchKey =\n batchKey ||\n ((operation: ApolloLink.Operation) => {\n const context = operation.getContext();\n\n const contextConfig = {\n http: context.http,\n options: context.fetchOptions,\n credentials: context.credentials,\n headers: context.headers,\n };\n\n //may throw error if config not serializable\n return selectURI(operation, uri) + JSON.stringify(contextConfig);\n });\n\n this.batcher = new BatchLink({\n batchDebounce: this.batchDebounce,\n batchInterval: this.batchInterval,\n batchMax: this.batchMax,\n batchKey,\n batchHandler,\n });\n }\n\n public request(\n operation: ApolloLink.Operation,\n forward: ApolloLink.ForwardFunction\n ): Observable<ApolloLink.Result> {\n return this.batcher.request(operation, forward);\n }\n}\n"]}
1
+ {"version":3,"file":"batchHttpLink.js","sourceRoot":"","sources":["../../../src/link/batch-http/batchHttpLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAG3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAwB3D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,OAAO,aAAc,SAAQ,UAAU;IAC3C,YAAY,UAAiC,EAAE;QAC7C,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC,IAAI,CAAC;YAC/C,IAAI,mBAAmB,CAAC,OAAO,CAAC;YAChC,IAAI,iBAAiB,CAAC,OAAO,CAAC;SAC/B,CAAC,CAAC;QACH,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IACvC,CAAC;CACF","sourcesContent":["import { ApolloLink } from \"@apollo/client/link\";\nimport { ClientAwarenessLink } from \"@apollo/client/link/client-awareness\";\nimport { __DEV__ } from \"@apollo/client/utilities/environment\";\n\nimport { BaseBatchHttpLink } from \"./BaseBatchHttpLink.js\";\n\nexport declare namespace BatchHttpLink {\n /**\n * Options provided to the `BatchHttpLink` constructor.\n */\n export interface Options\n extends BaseBatchHttpLink.Options,\n ClientAwarenessLink.Options {}\n\n /**\n * Options passed to `BatchHttpLink` 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 `BatchHttpLink` for each operation.\n *\n * > [!NOTE]\n * > Some of these values can also be provided to the `BatchHttpLink` constructor.\n * > If a value is provided to both, the value in `context` takes precedence.\n */\n export interface ContextOptions\n extends BaseBatchHttpLink.ContextOptions,\n ClientAwarenessLink.ContextOptions {}\n}\n\n/**\n * `BatchHttpLink` is a terminating link that batches array of individual\n * GraphQL operations into a single HTTP request that's sent to a single GraphQL\n * endpoint. It combines the functionality of `BaseBatchHttpLink` and\n * `ClientAwarenessLink` into a single link.\n *\n * @remarks\n *\n * If you use `BatchHttpLink` instead of `HttpLink` as your terminating link,\n * Apollo Client automatically batches executed GraphQL operations and transmits\n * them to your server according to the batching options you provide.\n *\n * @example\n *\n * ```ts\n * import { BatchHttpLink } from \"@apollo/client/link/batch-http\";\n *\n * const link = new BatchHttpLink({\n * uri: \"http://localhost:4000/graphql\",\n * batchMax: 5, // No more than 5 operations per batch\n * batchInterval: 20, // Wait no more than 20ms after first batched operation\n * });\n * ```\n */\nexport class BatchHttpLink extends ApolloLink {\n constructor(options: BatchHttpLink.Options = {}) {\n const { left, right, request } = ApolloLink.from([\n new ClientAwarenessLink(options),\n new BaseBatchHttpLink(options),\n ]);\n super(request);\n Object.assign(this, { left, right });\n }\n}\n"]}
@@ -1,2 +1,3 @@
1
- export { BaseBatchHttpLink, BatchHttpLink } from "./batchHttpLink.js";
1
+ export { BaseBatchHttpLink } from "./BaseBatchHttpLink.js";
2
+ export { BatchHttpLink } from "./batchHttpLink.js";
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1,2 +1,3 @@
1
- export { BaseBatchHttpLink, BatchHttpLink } from "./batchHttpLink.js";
1
+ export { BaseBatchHttpLink } from "./BaseBatchHttpLink.js";
2
+ export { BatchHttpLink } from "./batchHttpLink.js";
2
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/link/batch-http/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export { BaseBatchHttpLink, BatchHttpLink } from \"./batchHttpLink.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/link/batch-http/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export { BaseBatchHttpLink } from \"./BaseBatchHttpLink.js\";\nexport { BatchHttpLink } from \"./batchHttpLink.js\";\n"]}
@@ -1,5 +1,24 @@
1
1
  import { ApolloLink } from "@apollo/client/link";
2
2
  export declare namespace ClientAwarenessLink {
3
+ /**
4
+ * Options passed to `ClientAwarenessLink` through [request context](https://apollographql.com/docs/react/api/link/introduction#managing-context). Previous
5
+ * non-terminating links in the link chain also can set these values to
6
+ * customize the behavior of `ClientAwarenessLink` for each operation.
7
+ *
8
+ * > [!NOTE]
9
+ * > Some of these values can also be provided to the `ClientAwarenessLink`
10
+ * > constructor. If a value is provided to both, the value in `context` takes
11
+ * > precedence.
12
+ */
13
+ interface ContextOptions {
14
+ /**
15
+ * Configures the "client awareness" feature.
16
+ * This feature allows you to identify distinct applications in Apollo Studio
17
+ * and Apollo Server logs (and other monitoring or analytics tools) by adding
18
+ * information about the your application to outgoing requests.
19
+ */
20
+ clientAwareness?: ClientAwarenessLink.ClientAwarenessOptions;
21
+ }
3
22
  interface ClientAwarenessOptions {
4
23
  /**
5
24
  * A custom name (e.g., `iOS`) that identifies this particular client among your set of clients. Apollo Server and Apollo Studio use this property as part of the [client awareness](https://www.apollographql.com/docs/apollo-server/monitoring/metrics#identifying-distinct-clients) feature.
@@ -46,17 +65,50 @@ export declare namespace ClientAwarenessLink {
46
65
  * and Apollo Server logs (and other monitoring or analytics tools) by adding
47
66
  * information about the your application to outgoing requests.
48
67
  */
49
- clientAwareness?: ClientAwarenessOptions;
68
+ clientAwareness?: ClientAwarenessLink.ClientAwarenessOptions;
50
69
  /**
51
70
  * Configures the "enhanced client awareness" feature.
52
71
  * This feature allows you to identify the version of the Apollo Client library
53
72
  * used in your application in Apollo Studio (and other monitoring or analytics tools)
54
73
  * by adding information about the Apollo Client library to outgoing requests.
55
74
  */
56
- enhancedClientAwareness?: EnhancedClientAwarenessOptions;
75
+ enhancedClientAwareness?: ClientAwarenessLink.EnhancedClientAwarenessOptions;
57
76
  }
58
77
  }
78
+ /**
79
+ * `ClientAwarenessLink` provides support for providing client awareness
80
+ * features.
81
+ *
82
+ * @remarks
83
+ *
84
+ * Client awareness adds identifying information about the client to HTTP
85
+ * requests for use with metrics reporting tools, such as [Apollo GraphOS](https://apollographql.com/docs/graphos/platform).
86
+ * It is included in the functionality of [`HttpLink`](https://apollographql.com/docs/react/api/link/apollo-link-http) by default.
87
+ *
88
+ * Client awareness distinguishes between user-provided client awareness
89
+ * (provided by the `clientAwareness` option) and enhanced client awareness
90
+ * (provided by the `enhancedClientAwareness` option). User-provided client
91
+ * awareness enables you to set a customized client name and version for
92
+ * identification in metrics reporting tools. Enhanced client awareness enables
93
+ * the identification of the Apollo Client package name and version.
94
+ *
95
+ * @example
96
+ *
97
+ * ```ts
98
+ * import { ClientAwarenessLink } from "@apollo/client/link/client-awareness";
99
+ *
100
+ * const link = new ClientAwarenessLink({
101
+ * clientAwareness: {
102
+ * name: "My Client",
103
+ * version: "1",
104
+ * },
105
+ * enhancedClientAwareness: {
106
+ * transport: "extensions",
107
+ * },
108
+ * });
109
+ * ```
110
+ */
59
111
  export declare class ClientAwarenessLink extends ApolloLink {
60
- constructor(constructorOptions?: ClientAwarenessLink.Options);
112
+ constructor(options?: ClientAwarenessLink.Options);
61
113
  }
62
- //# sourceMappingURL=ClientAwarenessLink.d.ts.map
114
+ //# sourceMappingURL=ClientAwarenessLink.d.ts.map
@@ -1,13 +1,46 @@
1
1
  import { ApolloLink } from "@apollo/client/link";
2
2
  import { compact } from "@apollo/client/utilities/internal";
3
+ /**
4
+ * `ClientAwarenessLink` provides support for providing client awareness
5
+ * features.
6
+ *
7
+ * @remarks
8
+ *
9
+ * Client awareness adds identifying information about the client to HTTP
10
+ * requests for use with metrics reporting tools, such as [Apollo GraphOS](https://apollographql.com/docs/graphos/platform).
11
+ * It is included in the functionality of [`HttpLink`](https://apollographql.com/docs/react/api/link/apollo-link-http) by default.
12
+ *
13
+ * Client awareness distinguishes between user-provided client awareness
14
+ * (provided by the `clientAwareness` option) and enhanced client awareness
15
+ * (provided by the `enhancedClientAwareness` option). User-provided client
16
+ * awareness enables you to set a customized client name and version for
17
+ * identification in metrics reporting tools. Enhanced client awareness enables
18
+ * the identification of the Apollo Client package name and version.
19
+ *
20
+ * @example
21
+ *
22
+ * ```ts
23
+ * import { ClientAwarenessLink } from "@apollo/client/link/client-awareness";
24
+ *
25
+ * const link = new ClientAwarenessLink({
26
+ * clientAwareness: {
27
+ * name: "My Client",
28
+ * version: "1",
29
+ * },
30
+ * enhancedClientAwareness: {
31
+ * transport: "extensions",
32
+ * },
33
+ * });
34
+ * ```
35
+ */
3
36
  export class ClientAwarenessLink extends ApolloLink {
4
- constructor(constructorOptions = {}) {
37
+ constructor(options = {}) {
5
38
  super((operation, forward) => {
6
39
  const client = operation.client;
7
40
  const clientOptions = client["queryManager"].clientOptions;
8
41
  const context = operation.getContext();
9
42
  {
10
- const { name, version, transport = "headers", } = compact({}, clientOptions.clientAwareness, constructorOptions.clientAwareness, context.clientAwareness);
43
+ const { name, version, transport = "headers", } = compact({}, clientOptions.clientAwareness, options.clientAwareness, context.clientAwareness);
11
44
  if (transport === "headers") {
12
45
  operation.setContext(({ headers, extensions }) => {
13
46
  return {
@@ -22,7 +55,7 @@ export class ClientAwarenessLink extends ApolloLink {
22
55
  }
23
56
  }
24
57
  {
25
- const { transport = "extensions" } = compact({}, clientOptions.enhancedClientAwareness, constructorOptions.enhancedClientAwareness);
58
+ const { transport = "extensions" } = compact({}, clientOptions.enhancedClientAwareness, options.enhancedClientAwareness);
26
59
  if (transport === "extensions") {
27
60
  operation.extensions = compact(
28
61
  // setting these first so that it can be overridden by user-provided extensions
@@ -1 +1 @@
1
- {"version":3,"file":"ClientAwarenessLink.js","sourceRoot":"","sources":["../../../src/link/client-awareness/ClientAwarenessLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AA6D5D,MAAM,OAAO,mBAAoB,SAAQ,UAAU;IACjD,YAAY,qBAAkD,EAAE;QAC9D,KAAK,CAAC,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE;YAC3B,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC;YAEhC,MAAM,aAAa,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC,aAAa,CAAC;YAC3D,MAAM,OAAO,GAAG,SAAS,CAAC,UAAU,EAAE,CAAC;YACvC,CAAC;gBACC,MAAM,EACJ,IAAI,EACJ,OAAO,EACP,SAAS,GAAG,SAAS,GACtB,GAAG,OAAO,CACT,EAAE,EACF,aAAa,CAAC,eAAe,EAC7B,kBAAkB,CAAC,eAAe,EAClC,OAAO,CAAC,eAAe,CACxB,CAAC;gBAEF,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;oBAC5B,SAAS,CAAC,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE;wBAC/C,OAAO;4BACL,OAAO,EAAE,OAAO;4BACd,8EAA8E;4BAC9E;gCACE,2BAA2B,EAAE,IAAI;gCACjC,8BAA8B,EAAE,OAAO;6BACxC,EACD,OAAO,CACR;yBACF,CAAC;oBACJ,CAAC,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;YACD,CAAC;gBACC,MAAM,EAAE,SAAS,GAAG,YAAY,EAAE,GAAG,OAAO,CAC1C,EAAE,EACF,aAAa,CAAC,uBAAuB,EACrC,kBAAkB,CAAC,uBAAuB,CAC3C,CAAC;gBACF,IAAI,SAAS,KAAK,YAAY,EAAE,CAAC;oBAC/B,SAAS,CAAC,UAAU,GAAG,OAAO;oBAC5B,+EAA+E;oBAC/E;wBACE,aAAa,EAAE;4BACb,IAAI,EAAE,gBAAgB;4BACtB,OAAO,EAAE,MAAM,CAAC,OAAO;yBACxB;qBACF,EACD,SAAS,CAAC,UAAU,CACrB,CAAC;gBACJ,CAAC;YACH,CAAC;YAED,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { ApolloLink } from \"@apollo/client/link\";\nimport { compact } from \"@apollo/client/utilities/internal\";\n\nexport declare namespace ClientAwarenessLink {\n export interface ClientAwarenessOptions {\n /**\n * A custom name (e.g., `iOS`) that identifies this particular client among your set of clients. Apollo Server and Apollo Studio use this property as part of the [client awareness](https://www.apollographql.com/docs/apollo-server/monitoring/metrics#identifying-distinct-clients) feature.\n *\n * This option can either be set as part of the Apollo Client constructor call or when manually constructing a `HttpLink`, `BatchHttpLink` or `ClientAwarenessLink`.\n */\n name?: string;\n /**\n * A custom version that identifies the current version of this particular client (e.g., `1.2`). Apollo Server and Apollo Studio use this property as part of the [client awareness](https://www.apollographql.com/docs/apollo-server/monitoring/metrics#identifying-distinct-clients) feature.\n *\n * This is **not** the version of Apollo Client that you are using, but rather any version string that helps you differentiate between versions of your client.\n *\n * This option can either be set as part of the Apollo Client constructor call or when manually constructing a `HttpLink`, `BatchHttpLink` or `ClientAwarenessLink`.\n */\n version?: string;\n /**\n * Determines how `name` and `version` are sent in outgoing requests.\n *\n * If `name` and `version` are not provided, this option will be ignored.\n * (These options can either be set as part of the Apollo Client constructor call or when manually constructing a `HttpLink`, `BatchHttpLink` or `ClientAwarenessLink`.)\n *\n * - If set to `\"headers\"`, `name` and `version` will be sent in the request headers as `apollographql-client-name` and `apollographql-client-version`, respectively.\n * - If set to `false`, `name` and `version` will not be included in outgoing requests.\n *\n * @defaultValue \"headers\"\n */\n transport?: \"headers\" | false;\n }\n export interface EnhancedClientAwarenessOptions {\n /**\n * Determines how the the version information of Apollo Client is sent in outgoing requests.\n *\n * - If set to `\"extensions\"`, library `name` and `version` will be sent in an object in the request extensions as `clientLibrary`.\n * - If set to `false`, library name and version will not be included in outgoing requests.\n *\n * @defaultValue \"extensions\"\n */\n transport?: \"extensions\" | false;\n }\n\n export interface Options {\n /**\n * Configures the \"client awareness\" feature.\n * This feature allows you to identify distinct applications in Apollo Studio\n * and Apollo Server logs (and other monitoring or analytics tools) by adding\n * information about the your application to outgoing requests.\n */\n clientAwareness?: ClientAwarenessOptions;\n /**\n * Configures the \"enhanced client awareness\" feature.\n * This feature allows you to identify the version of the Apollo Client library\n * used in your application in Apollo Studio (and other monitoring or analytics tools)\n * by adding information about the Apollo Client library to outgoing requests.\n */\n enhancedClientAwareness?: EnhancedClientAwarenessOptions;\n }\n}\n\nexport class ClientAwarenessLink extends ApolloLink {\n constructor(constructorOptions: ClientAwarenessLink.Options = {}) {\n super((operation, forward) => {\n const client = operation.client;\n\n const clientOptions = client[\"queryManager\"].clientOptions;\n const context = operation.getContext();\n {\n const {\n name,\n version,\n transport = \"headers\",\n } = compact(\n {},\n clientOptions.clientAwareness,\n constructorOptions.clientAwareness,\n context.clientAwareness\n );\n\n if (transport === \"headers\") {\n operation.setContext(({ headers, extensions }) => {\n return {\n headers: compact(\n // setting these first so that they can be overridden by user-provided headers\n {\n \"apollographql-client-name\": name,\n \"apollographql-client-version\": version,\n },\n headers\n ),\n };\n });\n }\n }\n {\n const { transport = \"extensions\" } = compact(\n {},\n clientOptions.enhancedClientAwareness,\n constructorOptions.enhancedClientAwareness\n );\n if (transport === \"extensions\") {\n operation.extensions = compact(\n // setting these first so that it can be overridden by user-provided extensions\n {\n clientLibrary: {\n name: \"@apollo/client\",\n version: client.version,\n },\n },\n operation.extensions\n );\n }\n }\n\n return forward(operation);\n });\n }\n}\n"]}
1
+ {"version":3,"file":"ClientAwarenessLink.js","sourceRoot":"","sources":["../../../src/link/client-awareness/ClientAwarenessLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AA4E5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,OAAO,mBAAoB,SAAQ,UAAU;IACjD,YAAY,UAAuC,EAAE;QACnD,KAAK,CAAC,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE;YAC3B,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC;YAEhC,MAAM,aAAa,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC,aAAa,CAAC;YAC3D,MAAM,OAAO,GAAG,SAAS,CAAC,UAAU,EAAE,CAAC;YACvC,CAAC;gBACC,MAAM,EACJ,IAAI,EACJ,OAAO,EACP,SAAS,GAAG,SAAS,GACtB,GAAG,OAAO,CACT,EAAE,EACF,aAAa,CAAC,eAAe,EAC7B,OAAO,CAAC,eAAe,EACvB,OAAO,CAAC,eAAe,CACxB,CAAC;gBAEF,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;oBAC5B,SAAS,CAAC,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE;wBAC/C,OAAO;4BACL,OAAO,EAAE,OAAO;4BACd,8EAA8E;4BAC9E;gCACE,2BAA2B,EAAE,IAAI;gCACjC,8BAA8B,EAAE,OAAO;6BACxC,EACD,OAAO,CACR;yBACF,CAAC;oBACJ,CAAC,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;YACD,CAAC;gBACC,MAAM,EAAE,SAAS,GAAG,YAAY,EAAE,GAAG,OAAO,CAC1C,EAAE,EACF,aAAa,CAAC,uBAAuB,EACrC,OAAO,CAAC,uBAAuB,CAChC,CAAC;gBACF,IAAI,SAAS,KAAK,YAAY,EAAE,CAAC;oBAC/B,SAAS,CAAC,UAAU,GAAG,OAAO;oBAC5B,+EAA+E;oBAC/E;wBACE,aAAa,EAAE;4BACb,IAAI,EAAE,gBAAgB;4BACtB,OAAO,EAAE,MAAM,CAAC,OAAO;yBACxB;qBACF,EACD,SAAS,CAAC,UAAU,CACrB,CAAC;gBACJ,CAAC;YACH,CAAC;YAED,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { ApolloLink } from \"@apollo/client/link\";\nimport { compact } from \"@apollo/client/utilities/internal\";\n\nexport declare namespace ClientAwarenessLink {\n /**\n * Options passed to `ClientAwarenessLink` 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 `ClientAwarenessLink` for each operation.\n *\n * > [!NOTE]\n * > Some of these values can also be provided to the `ClientAwarenessLink`\n * > constructor. If a value is provided to both, the value in `context` takes\n * > precedence.\n */\n export interface ContextOptions {\n /** {@inheritDoc @apollo/client/link/client-awareness!ClientAwarenessLink.Options#clientAwareness:member} */\n clientAwareness?: ClientAwarenessLink.ClientAwarenessOptions;\n }\n\n export interface ClientAwarenessOptions {\n /**\n * A custom name (e.g., `iOS`) that identifies this particular client among your set of clients. Apollo Server and Apollo Studio use this property as part of the [client awareness](https://www.apollographql.com/docs/apollo-server/monitoring/metrics#identifying-distinct-clients) feature.\n *\n * This option can either be set as part of the Apollo Client constructor call or when manually constructing a `HttpLink`, `BatchHttpLink` or `ClientAwarenessLink`.\n */\n name?: string;\n /**\n * A custom version that identifies the current version of this particular client (e.g., `1.2`). Apollo Server and Apollo Studio use this property as part of the [client awareness](https://www.apollographql.com/docs/apollo-server/monitoring/metrics#identifying-distinct-clients) feature.\n *\n * This is **not** the version of Apollo Client that you are using, but rather any version string that helps you differentiate between versions of your client.\n *\n * This option can either be set as part of the Apollo Client constructor call or when manually constructing a `HttpLink`, `BatchHttpLink` or `ClientAwarenessLink`.\n */\n version?: string;\n /**\n * Determines how `name` and `version` are sent in outgoing requests.\n *\n * If `name` and `version` are not provided, this option will be ignored.\n * (These options can either be set as part of the Apollo Client constructor call or when manually constructing a `HttpLink`, `BatchHttpLink` or `ClientAwarenessLink`.)\n *\n * - If set to `\"headers\"`, `name` and `version` will be sent in the request headers as `apollographql-client-name` and `apollographql-client-version`, respectively.\n * - If set to `false`, `name` and `version` will not be included in outgoing requests.\n *\n * @defaultValue \"headers\"\n */\n transport?: \"headers\" | false;\n }\n export interface EnhancedClientAwarenessOptions {\n /**\n * Determines how the the version information of Apollo Client is sent in outgoing requests.\n *\n * - If set to `\"extensions\"`, library `name` and `version` will be sent in an object in the request extensions as `clientLibrary`.\n * - If set to `false`, library name and version will not be included in outgoing requests.\n *\n * @defaultValue \"extensions\"\n */\n transport?: \"extensions\" | false;\n }\n\n export interface Options {\n /**\n * Configures the \"client awareness\" feature.\n * This feature allows you to identify distinct applications in Apollo Studio\n * and Apollo Server logs (and other monitoring or analytics tools) by adding\n * information about the your application to outgoing requests.\n */\n clientAwareness?: ClientAwarenessLink.ClientAwarenessOptions;\n /**\n * Configures the \"enhanced client awareness\" feature.\n * This feature allows you to identify the version of the Apollo Client library\n * used in your application in Apollo Studio (and other monitoring or analytics tools)\n * by adding information about the Apollo Client library to outgoing requests.\n */\n enhancedClientAwareness?: ClientAwarenessLink.EnhancedClientAwarenessOptions;\n }\n}\n\n/**\n * `ClientAwarenessLink` provides support for providing client awareness\n * features.\n *\n * @remarks\n *\n * Client awareness adds identifying information about the client to HTTP\n * requests for use with metrics reporting tools, such as [Apollo GraphOS](https://apollographql.com/docs/graphos/platform).\n * It is included in the functionality of [`HttpLink`](https://apollographql.com/docs/react/api/link/apollo-link-http) by default.\n *\n * Client awareness distinguishes between user-provided client awareness\n * (provided by the `clientAwareness` option) and enhanced client awareness\n * (provided by the `enhancedClientAwareness` option). User-provided client\n * awareness enables you to set a customized client name and version for\n * identification in metrics reporting tools. Enhanced client awareness enables\n * the identification of the Apollo Client package name and version.\n *\n * @example\n *\n * ```ts\n * import { ClientAwarenessLink } from \"@apollo/client/link/client-awareness\";\n *\n * const link = new ClientAwarenessLink({\n * clientAwareness: {\n * name: \"My Client\",\n * version: \"1\",\n * },\n * enhancedClientAwareness: {\n * transport: \"extensions\",\n * },\n * });\n * ```\n */\nexport class ClientAwarenessLink extends ApolloLink {\n constructor(options: ClientAwarenessLink.Options = {}) {\n super((operation, forward) => {\n const client = operation.client;\n\n const clientOptions = client[\"queryManager\"].clientOptions;\n const context = operation.getContext();\n {\n const {\n name,\n version,\n transport = \"headers\",\n } = compact(\n {},\n clientOptions.clientAwareness,\n options.clientAwareness,\n context.clientAwareness\n );\n\n if (transport === \"headers\") {\n operation.setContext(({ headers, extensions }) => {\n return {\n headers: compact(\n // setting these first so that they can be overridden by user-provided headers\n {\n \"apollographql-client-name\": name,\n \"apollographql-client-version\": version,\n },\n headers\n ),\n };\n });\n }\n }\n {\n const { transport = \"extensions\" } = compact(\n {},\n clientOptions.enhancedClientAwareness,\n options.enhancedClientAwareness\n );\n if (transport === \"extensions\") {\n operation.extensions = compact(\n // setting these first so that it can be overridden by user-provided extensions\n {\n clientLibrary: {\n name: \"@apollo/client\",\n version: client.version,\n },\n },\n operation.extensions\n );\n }\n }\n\n return forward(operation);\n });\n }\n}\n"]}
@@ -1,7 +1,50 @@
1
1
  import { ApolloLink } from "@apollo/client/link";
2
2
  export declare namespace SetContextLink {
3
- type ContextSetter = (prevContext: ApolloLink.OperationContext, operation: SetContextOperation) => Promise<Partial<ApolloLink.OperationContext>> | Partial<ApolloLink.OperationContext>;
4
- type LegacyContextSetter = (operation: SetContextOperation, prevContext: ApolloLink.OperationContext) => Promise<Partial<ApolloLink.OperationContext>> | Partial<ApolloLink.OperationContext>;
3
+ namespace SetContextLinkDocumentationTypes {
4
+ /**
5
+ * A function that returns an updated context object for an Apollo Link
6
+ * operation.
7
+ *
8
+ * The context setter function is called for each operation and allows you to
9
+ * modify the operation's context before it's passed to the next link in the
10
+ * chain. The returned context object is shallowly merged with the previous
11
+ * context object.
12
+ *
13
+ * @param prevContext - The previous context of the operation (e.g. the value
14
+ * of `operation.getContext()`)
15
+ * @param operation - The GraphQL operation being executed, without the
16
+ * `getContext` and `setContext` methods
17
+ * @returns A partial context object or a promise that resolves to a partial context object
18
+ */
19
+ function ContextSetter(prevContext: Readonly<ApolloLink.OperationContext>, operation: SetContextLink.SetContextOperation): Promise<Partial<ApolloLink.OperationContext>> | Partial<ApolloLink.OperationContext>;
20
+ }
21
+ /**
22
+ * A function that returns an updated context object for an Apollo Link
23
+ * operation.
24
+ *
25
+ * The context setter function is called for each operation and allows you to
26
+ * modify the operation's context before it's passed to the next link in the
27
+ * chain. The returned context object is shallowly merged with the previous
28
+ * context object.
29
+ *
30
+ * @param prevContext - The previous context of the operation (e.g. the value
31
+ * of `operation.getContext()`)
32
+ * @param operation - The GraphQL operation being executed, without the
33
+ * `getContext` and `setContext` methods
34
+ * @returns A partial context object or a promise that resolves to a partial context object
35
+ */
36
+ type ContextSetter = (prevContext: Readonly<ApolloLink.OperationContext>, operation: SetContextLink.SetContextOperation) => Promise<Partial<ApolloLink.OperationContext>> | Partial<ApolloLink.OperationContext>;
37
+ /**
38
+ * @deprecated
39
+ * Use `ContextSetter` instead. This type is used by the deprecated
40
+ * `setContext` function.
41
+ */
42
+ type LegacyContextSetter = (operation: SetContextLink.SetContextOperation, prevContext: Readonly<ApolloLink.OperationContext>) => Promise<Partial<ApolloLink.OperationContext>> | Partial<ApolloLink.OperationContext>;
43
+ /**
44
+ * An `ApolloLink.Operation` object without the `getContext` and `setContext`
45
+ * methods. This prevents context setters from directly manipulating the
46
+ * context during the setter function execution.
47
+ */
5
48
  type SetContextOperation = Omit<ApolloLink.Operation, "getContext" | "setContext">;
6
49
  }
7
50
  /**
@@ -17,7 +60,26 @@ export declare namespace SetContextLink {
17
60
  * ```
18
61
  */
19
62
  export declare function setContext(setter: SetContextLink.LegacyContextSetter): SetContextLink;
63
+ /**
64
+ * `SetContextLink` is a non-terminating link that allows you to modify the
65
+ * context of GraphQL operations before they're passed to the next link in the
66
+ * chain. This is commonly used for authentication, adding headers, and other
67
+ * request-time configuration.
68
+ *
69
+ * @example
70
+ *
71
+ * ```ts
72
+ * import { SetContextLink } from "@apollo/client/link/context";
73
+ *
74
+ * const link = new SetContextLink((prevContext, operation) => {
75
+ * return {
76
+ * credentials: "include",
77
+ * // ...
78
+ * };
79
+ * });
80
+ * ```
81
+ */
20
82
  export declare class SetContextLink extends ApolloLink {
21
83
  constructor(setter: SetContextLink.ContextSetter);
22
84
  }
23
- //# sourceMappingURL=index.d.ts.map
85
+ //# sourceMappingURL=index.d.ts.map
@@ -15,6 +15,25 @@ import { ApolloLink } from "@apollo/client/link";
15
15
  export function setContext(setter) {
16
16
  return new SetContextLink((prevContext, operation) => setter(operation, prevContext));
17
17
  }
18
+ /**
19
+ * `SetContextLink` is a non-terminating link that allows you to modify the
20
+ * context of GraphQL operations before they're passed to the next link in the
21
+ * chain. This is commonly used for authentication, adding headers, and other
22
+ * request-time configuration.
23
+ *
24
+ * @example
25
+ *
26
+ * ```ts
27
+ * import { SetContextLink } from "@apollo/client/link/context";
28
+ *
29
+ * const link = new SetContextLink((prevContext, operation) => {
30
+ * return {
31
+ * credentials: "include",
32
+ * // ...
33
+ * };
34
+ * });
35
+ * ```
36
+ */
18
37
  export class SetContextLink extends ApolloLink {
19
38
  constructor(setter) {
20
39
  super((operation, forward) => {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/link/context/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAuBjD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,UAAU,CAAC,MAA0C;IACnE,OAAO,IAAI,cAAc,CAAC,CAAC,WAAW,EAAE,SAAS,EAAE,EAAE,CACnD,MAAM,CAAC,SAAS,EAAE,WAAW,CAAC,CAC/B,CAAC;AACJ,CAAC;AACD,MAAM,OAAO,cAAe,SAAQ,UAAU;IAC5C,YAAY,MAAoC;QAC9C,KAAK,CAAC,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE;YAC3B,MAAM,EAAE,GAAG,OAAO,EAAE,GAAG,SAA+C,CAAC;YAEvE,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,QAAQ,EAAE;gBACvC,UAAU,EAAE,KAAK;gBACjB,KAAK,EAAE,SAAS,CAAC,MAAM;aACxB,CAAC,CAAC;YAEH,OAAO,IAAI,UAAU,CAAC,CAAC,QAAQ,EAAE,EAAE;gBACjC,IAAI,MAAM,GAAG,KAAK,CAAC;gBACnB,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC;qBACrB,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,EAAE,EAAE,GAAG,CAAC,CAAC;qBAClD,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC;qBAC1B,IAAI,CAAC,GAAG,EAAE;oBACT,IAAI,CAAC,MAAM,EAAE,CAAC;wBACZ,OAAO,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;oBACzC,CAAC;gBACH,CAAC,CAAC;qBACD,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;gBAExC,OAAO,GAAG,EAAE;oBACV,MAAM,GAAG,IAAI,CAAC;gBAChB,CAAC,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { Observable } from \"rxjs\";\n\nimport { ApolloLink } from \"@apollo/client/link\";\n\nexport declare namespace SetContextLink {\n export type ContextSetter = (\n prevContext: ApolloLink.OperationContext,\n operation: SetContextOperation\n ) =>\n | Promise<Partial<ApolloLink.OperationContext>>\n | Partial<ApolloLink.OperationContext>;\n\n export type LegacyContextSetter = (\n operation: SetContextOperation,\n prevContext: ApolloLink.OperationContext\n ) =>\n | Promise<Partial<ApolloLink.OperationContext>>\n | Partial<ApolloLink.OperationContext>;\n\n export type SetContextOperation = Omit<\n ApolloLink.Operation,\n \"getContext\" | \"setContext\"\n >;\n}\n\n/**\n * @deprecated\n * Use `SetContextLink` from `@apollo/client/link/context` instead. Note you\n * will need to flip the arguments when using `SetContextLink` as `prevContext`\n * is the first argument.\n *\n * ```ts\n * new SetContextLink((prevContext, operation) => {\n * // ...\n * });\n * ```\n */\nexport function setContext(setter: SetContextLink.LegacyContextSetter) {\n return new SetContextLink((prevContext, operation) =>\n setter(operation, prevContext)\n );\n}\nexport class SetContextLink extends ApolloLink {\n constructor(setter: SetContextLink.ContextSetter) {\n super((operation, forward) => {\n const { ...request } = operation as SetContextLink.SetContextOperation;\n\n Object.defineProperty(request, \"client\", {\n enumerable: false,\n value: operation.client,\n });\n\n return new Observable((observer) => {\n let closed = false;\n Promise.resolve(request)\n .then((req) => setter(operation.getContext(), req))\n .then(operation.setContext)\n .then(() => {\n if (!closed) {\n forward(operation).subscribe(observer);\n }\n })\n .catch(observer.error.bind(observer));\n\n return () => {\n closed = true;\n };\n });\n });\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/link/context/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AA0DjD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,UAAU,CAAC,MAA0C;IACnE,OAAO,IAAI,cAAc,CAAC,CAAC,WAAW,EAAE,SAAS,EAAE,EAAE,CACnD,MAAM,CAAC,SAAS,EAAE,WAAW,CAAC,CAC/B,CAAC;AACJ,CAAC;AACD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,cAAe,SAAQ,UAAU;IAC5C,YAAY,MAAoC;QAC9C,KAAK,CAAC,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE;YAC3B,MAAM,EAAE,GAAG,OAAO,EAAE,GAAG,SAA+C,CAAC;YAEvE,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,QAAQ,EAAE;gBACvC,UAAU,EAAE,KAAK;gBACjB,KAAK,EAAE,SAAS,CAAC,MAAM;aACxB,CAAC,CAAC;YAEH,OAAO,IAAI,UAAU,CAAC,CAAC,QAAQ,EAAE,EAAE;gBACjC,IAAI,MAAM,GAAG,KAAK,CAAC;gBACnB,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC;qBACrB,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,EAAE,EAAE,GAAG,CAAC,CAAC;qBAClD,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC;qBAC1B,IAAI,CAAC,GAAG,EAAE;oBACT,IAAI,CAAC,MAAM,EAAE,CAAC;wBACZ,OAAO,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;oBACzC,CAAC;gBACH,CAAC,CAAC;qBACD,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;gBAExC,OAAO,GAAG,EAAE;oBACV,MAAM,GAAG,IAAI,CAAC;gBAChB,CAAC,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { Observable } from \"rxjs\";\n\nimport { ApolloLink } from \"@apollo/client/link\";\n\nexport declare namespace SetContextLink {\n namespace SetContextLinkDocumentationTypes {\n /**\n * A function that returns an updated context object for an Apollo Link\n * operation.\n *\n * The context setter function is called for each operation and allows you to\n * modify the operation's context before it's passed to the next link in the\n * chain. The returned context object is shallowly merged with the previous\n * context object.\n *\n * @param prevContext - The previous context of the operation (e.g. the value\n * of `operation.getContext()`)\n * @param operation - The GraphQL operation being executed, without the\n * `getContext` and `setContext` methods\n * @returns A partial context object or a promise that resolves to a partial context object\n */\n export function ContextSetter(\n prevContext: Readonly<ApolloLink.OperationContext>,\n operation: SetContextLink.SetContextOperation\n ):\n | Promise<Partial<ApolloLink.OperationContext>>\n | Partial<ApolloLink.OperationContext>;\n }\n\n /** {@inheritDoc @apollo/client/link/context!SetContextLink.SetContextLinkDocumentationTypes.ContextSetter:function(1)} */\n export type ContextSetter = (\n prevContext: Readonly<ApolloLink.OperationContext>,\n operation: SetContextLink.SetContextOperation\n ) =>\n | Promise<Partial<ApolloLink.OperationContext>>\n | Partial<ApolloLink.OperationContext>;\n\n /**\n * @deprecated\n * Use `ContextSetter` instead. This type is used by the deprecated\n * `setContext` function.\n */\n export type LegacyContextSetter = (\n operation: SetContextLink.SetContextOperation,\n prevContext: Readonly<ApolloLink.OperationContext>\n ) =>\n | Promise<Partial<ApolloLink.OperationContext>>\n | Partial<ApolloLink.OperationContext>;\n\n /**\n * An `ApolloLink.Operation` object without the `getContext` and `setContext`\n * methods. This prevents context setters from directly manipulating the\n * context during the setter function execution.\n */\n export type SetContextOperation = Omit<\n ApolloLink.Operation,\n \"getContext\" | \"setContext\"\n >;\n}\n\n/**\n * @deprecated\n * Use `SetContextLink` from `@apollo/client/link/context` instead. Note you\n * will need to flip the arguments when using `SetContextLink` as `prevContext`\n * is the first argument.\n *\n * ```ts\n * new SetContextLink((prevContext, operation) => {\n * // ...\n * });\n * ```\n */\nexport function setContext(setter: SetContextLink.LegacyContextSetter) {\n return new SetContextLink((prevContext, operation) =>\n setter(operation, prevContext)\n );\n}\n/**\n * `SetContextLink` is a non-terminating link that allows you to modify the\n * context of GraphQL operations before they're passed to the next link in the\n * chain. This is commonly used for authentication, adding headers, and other\n * request-time configuration.\n *\n * @example\n *\n * ```ts\n * import { SetContextLink } from \"@apollo/client/link/context\";\n *\n * const link = new SetContextLink((prevContext, operation) => {\n * return {\n * credentials: \"include\",\n * // ...\n * };\n * });\n * ```\n */\nexport class SetContextLink extends ApolloLink {\n constructor(setter: SetContextLink.ContextSetter) {\n super((operation, forward) => {\n const { ...request } = operation as SetContextLink.SetContextOperation;\n\n Object.defineProperty(request, \"client\", {\n enumerable: false,\n value: operation.client,\n });\n\n return new Observable((observer) => {\n let closed = false;\n Promise.resolve(request)\n .then((req) => setter(operation.getContext(), req))\n .then(operation.setContext)\n .then(() => {\n if (!closed) {\n forward(operation).subscribe(observer);\n }\n })\n .catch(observer.error.bind(observer));\n\n return () => {\n closed = true;\n };\n });\n });\n }\n}\n"]}
@@ -2,12 +2,29 @@ import { Observable } from "rxjs";
2
2
  import type { ErrorLike } from "@apollo/client";
3
3
  import { ApolloLink } from "@apollo/client/link";
4
4
  export declare namespace ErrorLink {
5
+ namespace ErrorLinkDocumentationTypes {
6
+ /**
7
+ * Callback that is called by `ErrorLink` when an error occurs from a
8
+ * downstream link in link chain.
9
+ *
10
+ * @param options - The options object provided by `ErrorLink` to the error
11
+ * handler when an error occurs.
12
+ */
13
+ function ErrorHandler(options: ErrorHandlerOptions): Observable<ApolloLink.Result> | void;
14
+ }
5
15
  /**
6
- * Callback to be triggered when an error occurs within the link stack.
7
- */
16
+ * Callback that is called by `ErrorLink` when an error occurs from a
17
+ * downstream link in link chain.
18
+ *
19
+ * @param options - The options object provided by `ErrorLink` to the error
20
+ * handler when an error occurs.
21
+ */
8
22
  interface ErrorHandler {
9
23
  (options: ErrorHandlerOptions): Observable<ApolloLink.Result> | void;
10
24
  }
25
+ /**
26
+ * The object provided to the `ErrorHandler` callback function.
27
+ */
11
28
  interface ErrorHandlerOptions {
12
29
  /**
13
30
  * The error that occurred during the operation execution. This can be a
@@ -33,13 +50,56 @@ export declare namespace ErrorLink {
33
50
  forward: ApolloLink.ForwardFunction;
34
51
  }
35
52
  }
36
- export import ErrorHandler = ErrorLink.ErrorHandler;
37
53
  /**
38
54
  * @deprecated
39
55
  * Use `ErrorLink` from `@apollo/client/link/error` instead.
40
56
  */
41
- export declare function onError(errorHandler: ErrorHandler): ErrorLink;
57
+ export declare function onError(errorHandler: ErrorLink.ErrorHandler): ErrorLink;
58
+ /**
59
+ * Use the `ErrorLink` to perform custom logic when a [GraphQL or network error](https://apollographql.com/docs/react/data/error-handling)
60
+ * occurs.
61
+ *
62
+ * @remarks
63
+ *
64
+ * This link is used after the GraphQL operation completes and execution is
65
+ * moving back up your [link chain](https://apollographql.com/docs/react/introduction#handling-a-response). The `errorHandler` function should
66
+ * not return a value unless you want to [retry the operation](https://apollographql.com/docs/react/data/error-handling#retrying-operations).
67
+ *
68
+ * For more information on the types of errors that might be encountered, see
69
+ * the guide on [error handling](https://apollographql.com/docs/react/data/error-handling).
70
+ *
71
+ * @example
72
+ *
73
+ * ```ts
74
+ * import { ErrorLink } from "@apollo/client/link/error";
75
+ * import {
76
+ * CombinedGraphQLErrors,
77
+ * CombinedProtocolErrors,
78
+ * } from "@apollo/client/errors";
79
+ *
80
+ * // Log any GraphQL errors, protocol errors, or network error that occurred
81
+ * const errorLink = new ErrorLink(({ error, operation }) => {
82
+ * if (CombinedGraphQLErrors.is(error)) {
83
+ * error.errors.forEach(({ message, locations, path }) =>
84
+ * console.log(
85
+ * `[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
86
+ * )
87
+ * );
88
+ * } else if (CombinedProtocolErrors.is(error)) {
89
+ * error.errors.forEach(({ message, extensions }) =>
90
+ * console.log(
91
+ * `[Protocol error]: Message: ${message}, Extensions: ${JSON.stringify(
92
+ * extensions
93
+ * )}`
94
+ * )
95
+ * );
96
+ * } else {
97
+ * console.error(`[Network error]: ${error}`);
98
+ * }
99
+ * });
100
+ * ```
101
+ */
42
102
  export declare class ErrorLink extends ApolloLink {
43
103
  constructor(errorHandler: ErrorLink.ErrorHandler);
44
104
  }
45
- //# sourceMappingURL=index.d.ts.map
105
+ //# sourceMappingURL=index.d.ts.map