@apollo/client 4.0.0-rc.8 → 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 (114) hide show
  1. package/CHANGELOG.md +12 -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/link/batch/batchLink.cjs +30 -2
  9. package/__cjs/link/batch/batchLink.cjs.map +1 -1
  10. package/__cjs/link/batch/batchLink.d.cts +69 -2
  11. package/__cjs/link/batch-http/BaseBatchHttpLink.cjs +156 -0
  12. package/__cjs/link/batch-http/BaseBatchHttpLink.cjs.map +1 -0
  13. package/__cjs/link/batch-http/BaseBatchHttpLink.d.cts +68 -0
  14. package/__cjs/link/batch-http/batchHttpLink.cjs +3 -128
  15. package/__cjs/link/batch-http/batchHttpLink.cjs.map +1 -1
  16. package/__cjs/link/batch-http/batchHttpLink.d.cts +4 -20
  17. package/__cjs/link/batch-http/index.cjs +2 -1
  18. package/__cjs/link/batch-http/index.cjs.map +1 -1
  19. package/__cjs/link/batch-http/index.d.cts +2 -1
  20. package/__cjs/link/client-awareness/ClientAwarenessLink.cjs +3 -3
  21. package/__cjs/link/client-awareness/ClientAwarenessLink.cjs.map +1 -1
  22. package/__cjs/link/client-awareness/ClientAwarenessLink.d.cts +20 -1
  23. package/__cjs/link/context/index.cjs +19 -0
  24. package/__cjs/link/context/index.cjs.map +1 -1
  25. package/__cjs/link/context/index.d.cts +64 -2
  26. package/__cjs/link/http/BaseHttpLink.cjs +59 -8
  27. package/__cjs/link/http/BaseHttpLink.cjs.map +1 -1
  28. package/__cjs/link/http/BaseHttpLink.d.cts +256 -2
  29. package/__cjs/link/http/HttpLink.cjs +1 -1
  30. package/__cjs/link/http/HttpLink.cjs.map +1 -1
  31. package/__cjs/link/http/HttpLink.d.cts +5 -208
  32. package/__cjs/link/http/rewriteURIForGET.cjs.map +1 -1
  33. package/__cjs/link/http/rewriteURIForGET.d.cts +2 -2
  34. package/__cjs/link/http/selectHttpOptionsAndBody.cjs.map +1 -1
  35. package/__cjs/link/http/selectHttpOptionsAndBody.d.cts +7 -7
  36. package/__cjs/link/persisted-queries/index.cjs +16 -0
  37. package/__cjs/link/persisted-queries/index.cjs.map +1 -1
  38. package/__cjs/link/persisted-queries/index.d.cts +181 -0
  39. package/__cjs/link/remove-typename/removeTypenameFromVariables.cjs +48 -0
  40. package/__cjs/link/remove-typename/removeTypenameFromVariables.cjs.map +1 -1
  41. package/__cjs/link/remove-typename/removeTypenameFromVariables.d.cts +115 -0
  42. package/__cjs/link/retry/retryLink.cjs +25 -3
  43. package/__cjs/link/retry/retryLink.cjs.map +1 -1
  44. package/__cjs/link/retry/retryLink.d.cts +82 -9
  45. package/__cjs/link/schema/index.cjs +20 -0
  46. package/__cjs/link/schema/index.cjs.map +1 -1
  47. package/__cjs/link/schema/index.d.cts +128 -6
  48. package/__cjs/link/ws/index.cjs +18 -0
  49. package/__cjs/link/ws/index.cjs.map +1 -1
  50. package/__cjs/link/ws/index.d.cts +56 -5
  51. package/__cjs/react/hooks/useSyncExternalStore.cjs +2 -6
  52. package/__cjs/react/hooks/useSyncExternalStore.cjs.map +1 -1
  53. package/__cjs/utilities/internal/removeDirectivesFromDocument.cjs +2 -6
  54. package/__cjs/utilities/internal/removeDirectivesFromDocument.cjs.map +1 -1
  55. package/__cjs/utilities/subscriptions/relay/index.cjs.map +1 -1
  56. package/__cjs/version.cjs +1 -1
  57. package/cache/inmemory/writeToStore.js +1 -1
  58. package/cache/inmemory/writeToStore.js.map +1 -1
  59. package/core/ObservableQuery.js +1 -1
  60. package/core/ObservableQuery.js.map +1 -1
  61. package/core/QueryInfo.js +1 -2
  62. package/core/QueryInfo.js.map +1 -1
  63. package/link/batch/batchLink.d.ts +69 -2
  64. package/link/batch/batchLink.js +30 -2
  65. package/link/batch/batchLink.js.map +1 -1
  66. package/link/batch-http/BaseBatchHttpLink.d.ts +68 -0
  67. package/link/batch-http/BaseBatchHttpLink.js +152 -0
  68. package/link/batch-http/BaseBatchHttpLink.js.map +1 -0
  69. package/link/batch-http/batchHttpLink.d.ts +5 -21
  70. package/link/batch-http/batchHttpLink.js +1 -125
  71. package/link/batch-http/batchHttpLink.js.map +1 -1
  72. package/link/batch-http/index.d.ts +2 -1
  73. package/link/batch-http/index.js +2 -1
  74. package/link/batch-http/index.js.map +1 -1
  75. package/link/client-awareness/ClientAwarenessLink.d.ts +21 -2
  76. package/link/client-awareness/ClientAwarenessLink.js +3 -3
  77. package/link/client-awareness/ClientAwarenessLink.js.map +1 -1
  78. package/link/context/index.d.ts +65 -3
  79. package/link/context/index.js +19 -0
  80. package/link/context/index.js.map +1 -1
  81. package/link/http/BaseHttpLink.d.ts +257 -3
  82. package/link/http/BaseHttpLink.js +59 -8
  83. package/link/http/BaseHttpLink.js.map +1 -1
  84. package/link/http/HttpLink.d.ts +6 -209
  85. package/link/http/HttpLink.js +1 -1
  86. package/link/http/HttpLink.js.map +1 -1
  87. package/link/http/rewriteURIForGET.d.ts +2 -2
  88. package/link/http/rewriteURIForGET.js.map +1 -1
  89. package/link/http/selectHttpOptionsAndBody.d.ts +7 -7
  90. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  91. package/link/persisted-queries/index.d.ts +182 -1
  92. package/link/persisted-queries/index.js +16 -0
  93. package/link/persisted-queries/index.js.map +1 -1
  94. package/link/remove-typename/removeTypenameFromVariables.d.ts +115 -0
  95. package/link/remove-typename/removeTypenameFromVariables.js +48 -0
  96. package/link/remove-typename/removeTypenameFromVariables.js.map +1 -1
  97. package/link/retry/retryLink.d.ts +83 -10
  98. package/link/retry/retryLink.js +25 -3
  99. package/link/retry/retryLink.js.map +1 -1
  100. package/link/schema/index.d.ts +129 -7
  101. package/link/schema/index.js +20 -0
  102. package/link/schema/index.js.map +1 -1
  103. package/link/ws/index.d.ts +56 -5
  104. package/link/ws/index.js +18 -0
  105. package/link/ws/index.js.map +1 -1
  106. package/package.json +1 -1
  107. package/react/hooks/useSyncExternalStore.js +1 -1
  108. package/react/hooks/useSyncExternalStore.js.map +1 -1
  109. package/react/hooks-compiled/useSyncExternalStore.js +1 -1
  110. package/react/hooks-compiled/useSyncExternalStore.js.map +1 -1
  111. package/utilities/internal/removeDirectivesFromDocument.js +1 -2
  112. package/utilities/internal/removeDirectivesFromDocument.js.map +1 -1
  113. package/utilities/subscriptions/relay/index.js.map +1 -1
  114. package/version.js +1 -1
@@ -0,0 +1,68 @@
1
+ import { Observable } from "rxjs";
2
+ import { ApolloLink } from "@apollo/client/link";
3
+ import { BatchLink } from "@apollo/client/link/batch";
4
+ import type { BaseHttpLink } from "@apollo/client/link/http";
5
+ export declare namespace BaseBatchHttpLink {
6
+ /**
7
+ * Options passed to `BaseBatchHttpLink` through [request context](https://apollographql.com/docs/react/api/link/introduction#managing-context). Previous
8
+ * non-terminating links in the link chain also can set these values to
9
+ * customize the behavior of `BatchHttpLink` for each operation.
10
+ *
11
+ * > [!NOTE]
12
+ * > Some of these values can also be provided to the `BaseBatchHttpLink` constructor.
13
+ * > If a value is provided to both, the value in `context` takes precedence.
14
+ */
15
+ interface ContextOptions extends BaseHttpLink.ContextOptions {
16
+ }
17
+ /**
18
+ * Configuration options for creating a `BaseBatchHttpLink` instance.
19
+ *
20
+ * > [!NOTE]
21
+ * > Some of these options are also available to override in [request context](https://apollographql.com/docs/react/api/link/introduction#managing-context).
22
+ * > Context options override the options passed to the constructor. Treat
23
+ * > these options as default values that are used when the request context
24
+ * > does not override the value.
25
+ */
26
+ interface Options extends BatchLink.Shared.Options, BaseHttpLink.Shared.Options {
27
+ /**
28
+ * The maximum number of operations to include in a single batch.
29
+ *
30
+ * @defaultValue 10
31
+ */
32
+ batchMax?: number;
33
+ }
34
+ }
35
+ /**
36
+ * `BaseBatchHttpLink` is a terminating link that batches array of individual
37
+ * GraphQL operations into a single HTTP request that's sent to a single GraphQL
38
+ * endpoint. It serves as a base link to `BatchHttpLink`.
39
+ *
40
+ * @remarks
41
+ *
42
+ * > [!NOTE]
43
+ * > Prefer using `BatchHttpLink` over `BaseBatchHttpLink`. Use
44
+ * > `BaseBatchHttpLink` when you need to disable client awareness features and
45
+ * > would like to tree-shake the implementation of `ClientAwarenessLink` out
46
+ * > of your app bundle.
47
+ *
48
+ * @example
49
+ *
50
+ * ```ts
51
+ * import { BaseBatchHttpLink } from "@apollo/client/link/batch-http";
52
+ *
53
+ * const link = new BaseBatchHttpLink({
54
+ * uri: "http://localhost:4000/graphql",
55
+ * batchMax: 5, // No more than 5 operations per batch
56
+ * batchInterval: 20, // Wait no more than 20ms after first batched operation
57
+ * });
58
+ * ```
59
+ */
60
+ export declare class BaseBatchHttpLink extends ApolloLink {
61
+ private batchDebounce?;
62
+ private batchInterval;
63
+ private batchMax;
64
+ private batcher;
65
+ constructor(options?: BaseBatchHttpLink.Options);
66
+ request(operation: ApolloLink.Operation, forward: ApolloLink.ForwardFunction): Observable<ApolloLink.Result>;
67
+ }
68
+ //# sourceMappingURL=BaseBatchHttpLink.d.ts.map
@@ -0,0 +1,152 @@
1
+ import { Observable, throwError } from "rxjs";
2
+ import { ApolloLink } from "@apollo/client/link";
3
+ import { BatchLink } from "@apollo/client/link/batch";
4
+ import { checkFetcher, defaultPrinter, fallbackHttpConfig, parseAndCheckHttpResponse, selectHttpOptionsAndBodyInternal, selectURI, } from "@apollo/client/link/http";
5
+ import { filterOperationVariables } from "@apollo/client/link/utils";
6
+ import { __DEV__ } from "@apollo/client/utilities/environment";
7
+ import { compact } from "@apollo/client/utilities/internal";
8
+ import { maybe } from "@apollo/client/utilities/internal/globals";
9
+ const backupFetch = maybe(() => fetch);
10
+ /**
11
+ * `BaseBatchHttpLink` is a terminating link that batches array of individual
12
+ * GraphQL operations into a single HTTP request that's sent to a single GraphQL
13
+ * endpoint. It serves as a base link to `BatchHttpLink`.
14
+ *
15
+ * @remarks
16
+ *
17
+ * > [!NOTE]
18
+ * > Prefer using `BatchHttpLink` over `BaseBatchHttpLink`. Use
19
+ * > `BaseBatchHttpLink` when you need to disable client awareness features and
20
+ * > would like to tree-shake the implementation of `ClientAwarenessLink` out
21
+ * > of your app bundle.
22
+ *
23
+ * @example
24
+ *
25
+ * ```ts
26
+ * import { BaseBatchHttpLink } from "@apollo/client/link/batch-http";
27
+ *
28
+ * const link = new BaseBatchHttpLink({
29
+ * uri: "http://localhost:4000/graphql",
30
+ * batchMax: 5, // No more than 5 operations per batch
31
+ * batchInterval: 20, // Wait no more than 20ms after first batched operation
32
+ * });
33
+ * ```
34
+ */
35
+ export class BaseBatchHttpLink extends ApolloLink {
36
+ batchDebounce;
37
+ batchInterval;
38
+ batchMax;
39
+ batcher;
40
+ constructor(options = {}) {
41
+ super();
42
+ let { uri = "/graphql",
43
+ // use default global fetch if nothing is passed in
44
+ fetch: preferredFetch, print = defaultPrinter, includeExtensions, preserveHeaderCase, batchInterval, batchDebounce, batchMax, batchKey, includeUnusedVariables = false, ...requestOptions } = options;
45
+ if (__DEV__) {
46
+ // Make sure at least one of preferredFetch, window.fetch, or backupFetch
47
+ // is defined, so requests won't fail at runtime.
48
+ checkFetcher(preferredFetch || backupFetch);
49
+ }
50
+ const linkConfig = {
51
+ http: compact({ includeExtensions, preserveHeaderCase }),
52
+ options: requestOptions.fetchOptions,
53
+ credentials: requestOptions.credentials,
54
+ headers: requestOptions.headers,
55
+ };
56
+ this.batchDebounce = batchDebounce;
57
+ this.batchInterval = batchInterval || 10;
58
+ this.batchMax = batchMax || 10;
59
+ const batchHandler = (operations) => {
60
+ const chosenURI = selectURI(operations[0], uri);
61
+ const context = operations[0].getContext();
62
+ const contextConfig = {
63
+ http: context.http,
64
+ options: context.fetchOptions,
65
+ credentials: context.credentials,
66
+ headers: context.headers,
67
+ };
68
+ //uses fallback, link, and then context to build options
69
+ const optsAndBody = operations.map((operation) => {
70
+ const result = selectHttpOptionsAndBodyInternal(operation, print, fallbackHttpConfig, linkConfig, contextConfig);
71
+ if (result.body.variables && !includeUnusedVariables) {
72
+ result.body.variables = filterOperationVariables(result.body.variables, operation.query);
73
+ }
74
+ return result;
75
+ });
76
+ const loadedBody = optsAndBody.map(({ body }) => body);
77
+ const options = optsAndBody[0].options;
78
+ // There's no spec for using GET with batches.
79
+ if (options.method === "GET") {
80
+ return throwError(() => new Error("apollo-link-batch-http does not support GET requests"));
81
+ }
82
+ try {
83
+ options.body = JSON.stringify(loadedBody);
84
+ }
85
+ catch (parseError) {
86
+ return throwError(() => parseError);
87
+ }
88
+ let controller;
89
+ if (!options.signal && typeof AbortController !== "undefined") {
90
+ controller = new AbortController();
91
+ options.signal = controller.signal;
92
+ }
93
+ return new Observable((observer) => {
94
+ // Prefer BatchHttpLink.Options.fetch (preferredFetch) if provided, and
95
+ // otherwise fall back to the *current* global window.fetch function
96
+ // (see issue #7832), or (if all else fails) the backupFetch function we
97
+ // saved when this module was first evaluated. This last option protects
98
+ // against the removal of window.fetch, which is unlikely but not
99
+ // impossible.
100
+ const currentFetch = preferredFetch || maybe(() => fetch) || backupFetch;
101
+ currentFetch(chosenURI, options)
102
+ .then((response) => {
103
+ // Make the raw response available in the context.
104
+ operations.forEach((operation) => operation.setContext({ response }));
105
+ return response;
106
+ })
107
+ .then(parseAndCheckHttpResponse(operations))
108
+ .then((result) => {
109
+ controller = undefined;
110
+ // we have data and can send it to back up the link chain
111
+ observer.next(result);
112
+ observer.complete();
113
+ return result;
114
+ })
115
+ .catch((err) => {
116
+ controller = undefined;
117
+ observer.error(err);
118
+ });
119
+ return () => {
120
+ // XXX support canceling this request
121
+ // https://developers.google.com/web/updates/2017/09/abortable-fetch
122
+ if (controller)
123
+ controller.abort();
124
+ };
125
+ });
126
+ };
127
+ batchKey =
128
+ batchKey ||
129
+ ((operation) => {
130
+ const context = operation.getContext();
131
+ const contextConfig = {
132
+ http: context.http,
133
+ options: context.fetchOptions,
134
+ credentials: context.credentials,
135
+ headers: context.headers,
136
+ };
137
+ //may throw error if config not serializable
138
+ return selectURI(operation, uri) + JSON.stringify(contextConfig);
139
+ });
140
+ this.batcher = new BatchLink({
141
+ batchDebounce: this.batchDebounce,
142
+ batchInterval: this.batchInterval,
143
+ batchMax: this.batchMax,
144
+ batchKey,
145
+ batchHandler,
146
+ });
147
+ }
148
+ request(operation, forward) {
149
+ return this.batcher.request(operation, forward);
150
+ }
151
+ }
152
+ //# sourceMappingURL=BaseBatchHttpLink.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseBatchHttpLink.js","sourceRoot":"","sources":["../../../src/link/batch-http/BaseBatchHttpLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAEtD,OAAO,EACL,YAAY,EACZ,cAAc,EACd,kBAAkB,EAClB,yBAAyB,EACzB,gCAAgC,EAChC,SAAS,GACV,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,2CAA2C,CAAC;AA8BlE,MAAM,WAAW,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;AAEvC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,OAAO,iBAAkB,SAAQ,UAAU;IACvC,aAAa,CAAW;IACxB,aAAa,CAAS;IACtB,QAAQ,CAAS;IACjB,OAAO,CAAa;IAE5B,YAAY,UAAqC,EAAE;QACjD,K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C7B,WAAW,EAAE,OAAO,CAAC,WAAW;wBAChC,OAAO,EAAE,OAAO,CAAC,OAAO;qBACzB,CAAC;oBAEF,4CAA4C;oBAC5C,OAAO,SAAS,CAAC,SAAS,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;gBACnE,CAAC,CAAC,CAAC;QAEL,IAAI,CAAC,OAAO,GAAG,IAAI,SAAS,CAAC;YAC3B,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,QAAQ;YACR,YAAY;SACb,CAAC,CAAC;IACL,CAAC;IAEM,OAAO,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 { BatchLink } from \"@apollo/client/link/batch\";\nimport type { BaseHttpLink } from \"@apollo/client/link/http\";\nimport {\n checkFetcher,\n defaultPrinter,\n fallbackHttpConfig,\n parseAndCheckHttpResponse,\n selectHttpOptionsAndBodyInternal,\n selectURI,\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 BaseBatchHttpLink {\n /**\n * Options passed to `BaseBatchHttpLink` 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 `BaseBatchHttpLink` constructor.\n * > If a value is provided to both, the value in `context` takes precedence.\n */\n export interface ContextOptions extends BaseHttpLink.ContextOptions {}\n /**\n * Configuration options for creating a `BaseBatchHttpLink` instance.\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\n extends BatchLink.Shared.Options,\n BaseHttpLink.Shared.Options {\n /** {@inheritDoc @apollo/client/link/batch!BatchLink.Shared.Options#batchMax:member {\"defaultValue\": 10}} */\n batchMax?: number;\n }\n}\n\nconst backupFetch = maybe(() => fetch);\n\n/**\n * `BaseBatchHttpLink` 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 serves as a base link to `BatchHttpLink`.\n *\n * @remarks\n *\n * > [!NOTE]\n * > Prefer using `BatchHttpLink` over `BaseBatchHttpLink`. Use\n * > `BaseBatchHttpLink` when you need to disable client awareness features and\n * > would like to tree-shake the implementation of `ClientAwarenessLink` out\n * > of your app bundle.\n *\n * @example\n *\n * ```ts\n * import { BaseBatchHttpLink } from \"@apollo/client/link/batch-http\";\n *\n * const link = new BaseBatchHttpLink({\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 BaseBatchHttpLink extends ApolloLink {\n private batchDebounce?: boolean;\n private batchInterval: number;\n private batchMax: number;\n private batcher: ApolloLink;\n\n constructor(options: BaseBatchHttpLink.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 } = 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: BatchLink.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 = JSON.stringify(loadedBody);\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,19 +1,11 @@
1
- import { Observable } 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 type { HttpLink } from "@apollo/client/link/http";
3
+ import { BaseBatchHttpLink } from "./BaseBatchHttpLink.js";
6
4
  export declare namespace BatchHttpLink {
7
5
  /**
8
6
  * Options provided to the `BatchHttpLink` constructor.
9
7
  */
10
- interface Options extends BatchLink.Shared.Options, HttpLink.Shared.Options {
11
- /**
12
- * The maximum number of operations to include in a single batch.
13
- *
14
- * @defaultValue 10
15
- */
16
- batchMax?: number;
8
+ interface Options extends BaseBatchHttpLink.Options, ClientAwarenessLink.Options {
17
9
  }
18
10
  /**
19
11
  * Options passed to `BatchHttpLink` through [request context](https://apollographql.com/docs/react/api/link/introduction#managing-context). Previous
@@ -24,7 +16,7 @@ export declare namespace BatchHttpLink {
24
16
  * > Some of these values can also be provided to the `BatchHttpLink` constructor.
25
17
  * > If a value is provided to both, the value in `context` takes precedence.
26
18
  */
27
- interface ContextOptions extends HttpLink.ContextOptions {
19
+ interface ContextOptions extends BaseBatchHttpLink.ContextOptions, ClientAwarenessLink.ContextOptions {
28
20
  }
29
21
  }
30
22
  /**
@@ -52,14 +44,6 @@ export declare namespace BatchHttpLink {
52
44
  * ```
53
45
  */
54
46
  export declare class BatchHttpLink extends ApolloLink {
55
- constructor(options?: BatchHttpLink.Options & ClientAwarenessLink.Options);
47
+ constructor(options?: BatchHttpLink.Options);
56
48
  }
57
- export declare class BaseBatchHttpLink extends ApolloLink {
58
- private batchDebounce?;
59
- private batchInterval;
60
- private batchMax;
61
- private batcher;
62
- constructor(fetchParams?: BatchHttpLink.Options);
63
- request(operation: ApolloLink.Operation, forward: ApolloLink.ForwardFunction): Observable<ApolloLink.Result>;
64
- }
65
- //# sourceMappingURL=batchHttpLink.d.ts.map
49
+ //# sourceMappingURL=batchHttpLink.d.ts.map
@@ -1,13 +1,6 @@
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, } 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
5
  * `BatchHttpLink` is a terminating link that batches array of individual
13
6
  * GraphQL operations into a single HTTP request that's sent to a single GraphQL
@@ -42,121 +35,4 @@ export class BatchHttpLink extends ApolloLink {
42
35
  Object.assign(this, { left, right });
43
36
  }
44
37
  }
45
- export class BaseBatchHttpLink extends ApolloLink {
46
- batchDebounce;
47
- batchInterval;
48
- batchMax;
49
- batcher;
50
- constructor(fetchParams) {
51
- super();
52
- let { uri = "/graphql",
53
- // use default global fetch if nothing is passed in
54
- fetch: preferredFetch, print = defaultPrinter, includeExtensions, preserveHeaderCase, batchInterval, batchDebounce, batchMax, batchKey, includeUnusedVariables = false, ...requestOptions } = fetchParams || {};
55
- if (__DEV__) {
56
- // Make sure at least one of preferredFetch, window.fetch, or backupFetch
57
- // is defined, so requests won't fail at runtime.
58
- checkFetcher(preferredFetch || backupFetch);
59
- }
60
- const linkConfig = {
61
- http: compact({ includeExtensions, preserveHeaderCase }),
62
- options: requestOptions.fetchOptions,
63
- credentials: requestOptions.credentials,
64
- headers: requestOptions.headers,
65
- };
66
- this.batchDebounce = batchDebounce;
67
- this.batchInterval = batchInterval || 10;
68
- this.batchMax = batchMax || 10;
69
- const batchHandler = (operations) => {
70
- const chosenURI = selectURI(operations[0], uri);
71
- const context = operations[0].getContext();
72
- const contextConfig = {
73
- http: context.http,
74
- options: context.fetchOptions,
75
- credentials: context.credentials,
76
- headers: context.headers,
77
- };
78
- //uses fallback, link, and then context to build options
79
- const optsAndBody = operations.map((operation) => {
80
- const result = selectHttpOptionsAndBodyInternal(operation, print, fallbackHttpConfig, linkConfig, contextConfig);
81
- if (result.body.variables && !includeUnusedVariables) {
82
- result.body.variables = filterOperationVariables(result.body.variables, operation.query);
83
- }
84
- return result;
85
- });
86
- const loadedBody = optsAndBody.map(({ body }) => body);
87
- const options = optsAndBody[0].options;
88
- // There's no spec for using GET with batches.
89
- if (options.method === "GET") {
90
- return throwError(() => new Error("apollo-link-batch-http does not support GET requests"));
91
- }
92
- try {
93
- options.body = JSON.stringify(loadedBody);
94
- }
95
- catch (parseError) {
96
- return throwError(() => parseError);
97
- }
98
- let controller;
99
- if (!options.signal && typeof AbortController !== "undefined") {
100
- controller = new AbortController();
101
- options.signal = controller.signal;
102
- }
103
- return new Observable((observer) => {
104
- // Prefer BatchHttpLink.Options.fetch (preferredFetch) if provided, and
105
- // otherwise fall back to the *current* global window.fetch function
106
- // (see issue #7832), or (if all else fails) the backupFetch function we
107
- // saved when this module was first evaluated. This last option protects
108
- // against the removal of window.fetch, which is unlikely but not
109
- // impossible.
110
- const currentFetch = preferredFetch || maybe(() => fetch) || backupFetch;
111
- currentFetch(chosenURI, options)
112
- .then((response) => {
113
- // Make the raw response available in the context.
114
- operations.forEach((operation) => operation.setContext({ response }));
115
- return response;
116
- })
117
- .then(parseAndCheckHttpResponse(operations))
118
- .then((result) => {
119
- controller = undefined;
120
- // we have data and can send it to back up the link chain
121
- observer.next(result);
122
- observer.complete();
123
- return result;
124
- })
125
- .catch((err) => {
126
- controller = undefined;
127
- observer.error(err);
128
- });
129
- return () => {
130
- // XXX support canceling this request
131
- // https://developers.google.com/web/updates/2017/09/abortable-fetch
132
- if (controller)
133
- controller.abort();
134
- };
135
- });
136
- };
137
- batchKey =
138
- batchKey ||
139
- ((operation) => {
140
- const context = operation.getContext();
141
- const contextConfig = {
142
- http: context.http,
143
- options: context.fetchOptions,
144
- credentials: context.credentials,
145
- headers: context.headers,
146
- };
147
- //may throw error if config not serializable
148
- return selectURI(operation, uri) + JSON.stringify(contextConfig);
149
- });
150
- this.batcher = new BatchLink({
151
- batchDebounce: this.batchDebounce,
152
- batchInterval: this.batchInterval,
153
- batchMax: this.batchMax,
154
- batchKey,
155
- batchHandler,
156
- });
157
- }
158
- request(operation, forward) {
159
- return this.batcher.request(operation, forward);
160
- }
161
- }
162
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;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAE3E,OAAO,EACL,YAAY,EAC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AAE,IAAI,CAAC,aAAa;YACjC,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,QAAQ;YACR,YAAY;SACb,CAAC,CAAC;IACL,CAAC;IAEM,OAAO,CACZ,SAA+B,EAC/B,OAAmC;QAEnC,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC;CACF","sourcesContent":["import { Observable, throwError } from \"rxjs\";\n\nimport { ApolloLink } from \"@apollo/client/link\";\nimport { 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} 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 /**\n * Options provided to the `BatchHttpLink` constructor.\n */\n export interface Options\n extends BatchLink.Shared.Options,\n HttpLink.Shared.Options {\n /** {@inheritDoc @apollo/client/link/batch!BatchLink.Shared.Options#batchMax:member {\"defaultValue\": 10}} */\n batchMax?: number;\n }\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 extends HttpLink.ContextOptions {}\n}\n\nconst backupFetch = maybe(() => fetch);\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(\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: BatchLink.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 = JSON.stringify(loadedBody);\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.
@@ -90,6 +109,6 @@ export declare namespace ClientAwarenessLink {
90
109
  * ```
91
110
  */
92
111
  export declare class ClientAwarenessLink extends ApolloLink {
93
- constructor(constructorOptions?: ClientAwarenessLink.Options);
112
+ constructor(options?: ClientAwarenessLink.Options);
94
113
  }
95
- //# sourceMappingURL=ClientAwarenessLink.d.ts.map
114
+ //# sourceMappingURL=ClientAwarenessLink.d.ts.map
@@ -34,13 +34,13 @@ import { compact } from "@apollo/client/utilities/internal";
34
34
  * ```
35
35
  */
36
36
  export class ClientAwarenessLink extends ApolloLink {
37
- constructor(constructorOptions = {}) {
37
+ constructor(options = {}) {
38
38
  super((operation, forward) => {
39
39
  const client = operation.client;
40
40
  const clientOptions = client["queryManager"].clientOptions;
41
41
  const context = operation.getContext();
42
42
  {
43
- 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);
44
44
  if (transport === "headers") {
45
45
  operation.setContext(({ headers, extensions }) => {
46
46
  return {
@@ -55,7 +55,7 @@ export class ClientAwarenessLink extends ApolloLink {
55
55
  }
56
56
  }
57
57
  {
58
- const { transport = "extensions" } = compact({}, clientOptions.enhancedClientAwareness, constructorOptions.enhancedClientAwareness);
58
+ const { transport = "extensions" } = compact({}, clientOptions.enhancedClientAwareness, options.enhancedClientAwareness);
59
59
  if (transport === "extensions") {
60
60
  operation.extensions = compact(
61
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,OAAO,mBAAoB,SAAQ,UAAU;IACjD,YAAY,qBAAkD,EAAE;QAC9D,KA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ink } 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?: 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(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"]}