@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.
- package/CHANGELOG.md +12 -0
- package/__cjs/cache/inmemory/writeToStore.cjs +1 -1
- package/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
- package/__cjs/core/ObservableQuery.cjs +1 -1
- package/__cjs/core/ObservableQuery.cjs.map +1 -1
- package/__cjs/core/QueryInfo.cjs +2 -6
- package/__cjs/core/QueryInfo.cjs.map +1 -1
- package/__cjs/link/batch/batchLink.cjs +30 -2
- package/__cjs/link/batch/batchLink.cjs.map +1 -1
- package/__cjs/link/batch/batchLink.d.cts +69 -2
- package/__cjs/link/batch-http/BaseBatchHttpLink.cjs +156 -0
- package/__cjs/link/batch-http/BaseBatchHttpLink.cjs.map +1 -0
- package/__cjs/link/batch-http/BaseBatchHttpLink.d.cts +68 -0
- package/__cjs/link/batch-http/batchHttpLink.cjs +3 -128
- package/__cjs/link/batch-http/batchHttpLink.cjs.map +1 -1
- package/__cjs/link/batch-http/batchHttpLink.d.cts +4 -20
- package/__cjs/link/batch-http/index.cjs +2 -1
- package/__cjs/link/batch-http/index.cjs.map +1 -1
- package/__cjs/link/batch-http/index.d.cts +2 -1
- package/__cjs/link/client-awareness/ClientAwarenessLink.cjs +3 -3
- package/__cjs/link/client-awareness/ClientAwarenessLink.cjs.map +1 -1
- package/__cjs/link/client-awareness/ClientAwarenessLink.d.cts +20 -1
- package/__cjs/link/context/index.cjs +19 -0
- package/__cjs/link/context/index.cjs.map +1 -1
- package/__cjs/link/context/index.d.cts +64 -2
- package/__cjs/link/http/BaseHttpLink.cjs +59 -8
- package/__cjs/link/http/BaseHttpLink.cjs.map +1 -1
- package/__cjs/link/http/BaseHttpLink.d.cts +256 -2
- package/__cjs/link/http/HttpLink.cjs +1 -1
- package/__cjs/link/http/HttpLink.cjs.map +1 -1
- package/__cjs/link/http/HttpLink.d.cts +5 -208
- package/__cjs/link/http/rewriteURIForGET.cjs.map +1 -1
- package/__cjs/link/http/rewriteURIForGET.d.cts +2 -2
- package/__cjs/link/http/selectHttpOptionsAndBody.cjs.map +1 -1
- package/__cjs/link/http/selectHttpOptionsAndBody.d.cts +7 -7
- package/__cjs/link/persisted-queries/index.cjs +16 -0
- package/__cjs/link/persisted-queries/index.cjs.map +1 -1
- package/__cjs/link/persisted-queries/index.d.cts +181 -0
- package/__cjs/link/remove-typename/removeTypenameFromVariables.cjs +48 -0
- package/__cjs/link/remove-typename/removeTypenameFromVariables.cjs.map +1 -1
- package/__cjs/link/remove-typename/removeTypenameFromVariables.d.cts +115 -0
- package/__cjs/link/retry/retryLink.cjs +25 -3
- package/__cjs/link/retry/retryLink.cjs.map +1 -1
- package/__cjs/link/retry/retryLink.d.cts +82 -9
- package/__cjs/link/schema/index.cjs +20 -0
- package/__cjs/link/schema/index.cjs.map +1 -1
- package/__cjs/link/schema/index.d.cts +128 -6
- package/__cjs/link/ws/index.cjs +18 -0
- package/__cjs/link/ws/index.cjs.map +1 -1
- package/__cjs/link/ws/index.d.cts +56 -5
- package/__cjs/react/hooks/useSyncExternalStore.cjs +2 -6
- package/__cjs/react/hooks/useSyncExternalStore.cjs.map +1 -1
- package/__cjs/utilities/internal/removeDirectivesFromDocument.cjs +2 -6
- package/__cjs/utilities/internal/removeDirectivesFromDocument.cjs.map +1 -1
- package/__cjs/utilities/subscriptions/relay/index.cjs.map +1 -1
- package/__cjs/version.cjs +1 -1
- package/cache/inmemory/writeToStore.js +1 -1
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/core/ObservableQuery.js +1 -1
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.js +1 -2
- package/core/QueryInfo.js.map +1 -1
- package/link/batch/batchLink.d.ts +69 -2
- package/link/batch/batchLink.js +30 -2
- package/link/batch/batchLink.js.map +1 -1
- package/link/batch-http/BaseBatchHttpLink.d.ts +68 -0
- package/link/batch-http/BaseBatchHttpLink.js +152 -0
- package/link/batch-http/BaseBatchHttpLink.js.map +1 -0
- package/link/batch-http/batchHttpLink.d.ts +5 -21
- package/link/batch-http/batchHttpLink.js +1 -125
- package/link/batch-http/batchHttpLink.js.map +1 -1
- package/link/batch-http/index.d.ts +2 -1
- package/link/batch-http/index.js +2 -1
- package/link/batch-http/index.js.map +1 -1
- package/link/client-awareness/ClientAwarenessLink.d.ts +21 -2
- package/link/client-awareness/ClientAwarenessLink.js +3 -3
- package/link/client-awareness/ClientAwarenessLink.js.map +1 -1
- package/link/context/index.d.ts +65 -3
- package/link/context/index.js +19 -0
- package/link/context/index.js.map +1 -1
- package/link/http/BaseHttpLink.d.ts +257 -3
- package/link/http/BaseHttpLink.js +59 -8
- package/link/http/BaseHttpLink.js.map +1 -1
- package/link/http/HttpLink.d.ts +6 -209
- package/link/http/HttpLink.js +1 -1
- package/link/http/HttpLink.js.map +1 -1
- package/link/http/rewriteURIForGET.d.ts +2 -2
- package/link/http/rewriteURIForGET.js.map +1 -1
- package/link/http/selectHttpOptionsAndBody.d.ts +7 -7
- package/link/http/selectHttpOptionsAndBody.js.map +1 -1
- package/link/persisted-queries/index.d.ts +182 -1
- package/link/persisted-queries/index.js +16 -0
- package/link/persisted-queries/index.js.map +1 -1
- package/link/remove-typename/removeTypenameFromVariables.d.ts +115 -0
- package/link/remove-typename/removeTypenameFromVariables.js +48 -0
- package/link/remove-typename/removeTypenameFromVariables.js.map +1 -1
- package/link/retry/retryLink.d.ts +83 -10
- package/link/retry/retryLink.js +25 -3
- package/link/retry/retryLink.js.map +1 -1
- package/link/schema/index.d.ts +129 -7
- package/link/schema/index.js +20 -0
- package/link/schema/index.js.map +1 -1
- package/link/ws/index.d.ts +56 -5
- package/link/ws/index.js +18 -0
- package/link/ws/index.js.map +1 -1
- package/package.json +1 -1
- package/react/hooks/useSyncExternalStore.js +1 -1
- package/react/hooks/useSyncExternalStore.js.map +1 -1
- package/react/hooks-compiled/useSyncExternalStore.js +1 -1
- package/react/hooks-compiled/useSyncExternalStore.js.map +1 -1
- package/utilities/internal/removeDirectivesFromDocument.js +1 -2
- package/utilities/internal/removeDirectivesFromDocument.js.map +1 -1
- package/utilities/subscriptions/relay/index.js.map +1 -1
- package/version.js +1 -1
package/link/http/HttpLink.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { ASTNode } from "graphql";
|
|
2
1
|
import { ApolloLink } from "@apollo/client/link";
|
|
3
2
|
import { ClientAwarenessLink } from "@apollo/client/link/client-awareness";
|
|
4
|
-
import
|
|
3
|
+
import { BaseHttpLink } from "./BaseHttpLink.js";
|
|
5
4
|
export declare namespace HttpLink {
|
|
6
5
|
/**
|
|
7
6
|
* Options passed to `HttpLink` through [request context](https://apollographql.com/docs/react/api/link/introduction#managing-context). Previous
|
|
@@ -12,192 +11,7 @@ export declare namespace HttpLink {
|
|
|
12
11
|
* > Some of these values can also be provided to the `HttpLink` constructor.
|
|
13
12
|
* > If a value is provided to both, the value in `context` takes precedence.
|
|
14
13
|
*/
|
|
15
|
-
interface ContextOptions {
|
|
16
|
-
/**
|
|
17
|
-
* The URL of the GraphQL endpoint to send requests to. Can also be a
|
|
18
|
-
* function that accepts an `ApolloLink.Operation` object and returns the
|
|
19
|
-
* string URL to use for that operation.
|
|
20
|
-
*
|
|
21
|
-
* @defaultValue "/graphql"
|
|
22
|
-
*/
|
|
23
|
-
uri?: string | HttpLink.UriFunction;
|
|
24
|
-
/**
|
|
25
|
-
* An object representing headers to include in every HTTP request.
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
*
|
|
29
|
-
* ```json
|
|
30
|
-
* {
|
|
31
|
-
* "Authorization": "Bearer 1234"
|
|
32
|
-
* }
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
headers?: Record<string, string>;
|
|
36
|
-
/**
|
|
37
|
-
* The credentials policy to use for each `fetch` call.
|
|
38
|
-
*/
|
|
39
|
-
credentials?: RequestCredentials;
|
|
40
|
-
/**
|
|
41
|
-
* Any overrides of the fetch options argument to pass to the fetch call.
|
|
42
|
-
*
|
|
43
|
-
* An object containing options to use for each call to `fetch`. If a
|
|
44
|
-
* particular option is not included in this object, the default value of
|
|
45
|
-
* that option is used.
|
|
46
|
-
*
|
|
47
|
-
* > [!NOTE]
|
|
48
|
-
* > If you set `fetchOptions.method` to `GET`, `HttpLink` follows [standard
|
|
49
|
-
* > GraphQL HTTP GET encoding](http://graphql.org/learn/serving-over-http/#get-request).
|
|
50
|
-
*
|
|
51
|
-
* See [available options](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
|
|
52
|
-
*/
|
|
53
|
-
fetchOptions?: RequestInit;
|
|
54
|
-
/**
|
|
55
|
-
* An object that configures advanced `HttpLink` functionality, such as
|
|
56
|
-
* support for persisted queries.
|
|
57
|
-
*/
|
|
58
|
-
http?: HttpLink.HttpOptions;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Options passed to `HttpLink` through the `http` property of a request
|
|
62
|
-
* context.
|
|
63
|
-
*/
|
|
64
|
-
interface HttpOptions {
|
|
65
|
-
/**
|
|
66
|
-
* If `true`, includes the `extensions` field in operations sent to your
|
|
67
|
-
* GraphQL endpoint.
|
|
68
|
-
*
|
|
69
|
-
* @defaultValue true
|
|
70
|
-
*/
|
|
71
|
-
includeExtensions?: boolean;
|
|
72
|
-
/**
|
|
73
|
-
* If `false`, the GraphQL query string is not included in the request. Set
|
|
74
|
-
* this option if you're sending a request that uses a [persisted query](https://www.apollographql.com/docs/react/api/link/persisted-queries/).
|
|
75
|
-
*
|
|
76
|
-
* @defaultValue true
|
|
77
|
-
*/
|
|
78
|
-
includeQuery?: boolean;
|
|
79
|
-
/**
|
|
80
|
-
* If `true`, header names won't be automatically normalized to lowercase.
|
|
81
|
-
* This allows for non-http-spec-compliant servers that might expect
|
|
82
|
-
* capitalized header names.
|
|
83
|
-
*
|
|
84
|
-
* @defaultValue false
|
|
85
|
-
*/
|
|
86
|
-
preserveHeaderCase?: boolean;
|
|
87
|
-
/**
|
|
88
|
-
* A list of additional `accept` headers to include in the request,
|
|
89
|
-
* as defined in https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.2
|
|
90
|
-
*
|
|
91
|
-
* @example
|
|
92
|
-
*
|
|
93
|
-
* ```json
|
|
94
|
-
* ["application/custom+json;q=1.0"]
|
|
95
|
-
* ```
|
|
96
|
-
*/
|
|
97
|
-
accept?: string[];
|
|
98
|
-
}
|
|
99
|
-
namespace Shared {
|
|
100
|
-
/** These options are shared between `HttpLink` and `BatchHttpLink` */
|
|
101
|
-
interface Options {
|
|
102
|
-
/**
|
|
103
|
-
* The URL of the GraphQL endpoint to send requests to. Can also be a
|
|
104
|
-
* function that accepts an `ApolloLink.Operation` object and returns the
|
|
105
|
-
* string URL to use for that operation.
|
|
106
|
-
*
|
|
107
|
-
* @defaultValue "/graphql"
|
|
108
|
-
*/
|
|
109
|
-
uri?: string | HttpLink.UriFunction;
|
|
110
|
-
/**
|
|
111
|
-
* If `true`, includes the `extensions` field in operations sent to your
|
|
112
|
-
* GraphQL endpoint.
|
|
113
|
-
*
|
|
114
|
-
* @defaultValue true
|
|
115
|
-
*/
|
|
116
|
-
includeExtensions?: boolean;
|
|
117
|
-
/**
|
|
118
|
-
* A function to use instead of calling the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch) directly
|
|
119
|
-
* when sending HTTP requests to your GraphQL endpoint. The function must
|
|
120
|
-
* conform to the signature of `fetch`.
|
|
121
|
-
*
|
|
122
|
-
* By default, the Fetch API is used unless it isn't available in your
|
|
123
|
-
* runtime environment.
|
|
124
|
-
*
|
|
125
|
-
* See [Customizing `fetch`](https://apollographql.com/docs/react/api/link/introduction#customizing-fetch).
|
|
126
|
-
*/
|
|
127
|
-
fetch?: typeof fetch;
|
|
128
|
-
/**
|
|
129
|
-
* An object representing headers to include in every HTTP request.
|
|
130
|
-
*
|
|
131
|
-
* @example
|
|
132
|
-
*
|
|
133
|
-
* ```json
|
|
134
|
-
* {
|
|
135
|
-
* "Authorization": "Bearer 1234"
|
|
136
|
-
* }
|
|
137
|
-
* ```
|
|
138
|
-
*/
|
|
139
|
-
headers?: Record<string, string>;
|
|
140
|
-
/**
|
|
141
|
-
* If `true`, header names won't be automatically normalized to lowercase.
|
|
142
|
-
* This allows for non-http-spec-compliant servers that might expect
|
|
143
|
-
* capitalized header names.
|
|
144
|
-
*
|
|
145
|
-
* @defaultValue false
|
|
146
|
-
*/
|
|
147
|
-
preserveHeaderCase?: boolean;
|
|
148
|
-
/**
|
|
149
|
-
* The credentials policy to use for each `fetch` call.
|
|
150
|
-
*/
|
|
151
|
-
credentials?: RequestCredentials;
|
|
152
|
-
/**
|
|
153
|
-
* Any overrides of the fetch options argument to pass to the fetch call.
|
|
154
|
-
*
|
|
155
|
-
* An object containing options to use for each call to `fetch`. If a
|
|
156
|
-
* particular option is not included in this object, the default value of
|
|
157
|
-
* that option is used.
|
|
158
|
-
*
|
|
159
|
-
* > [!NOTE]
|
|
160
|
-
* > If you set `fetchOptions.method` to `GET`, `HttpLink` follows [standard
|
|
161
|
-
* > GraphQL HTTP GET encoding](http://graphql.org/learn/serving-over-http/#get-request).
|
|
162
|
-
*
|
|
163
|
-
* See [available options](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
|
|
164
|
-
*/
|
|
165
|
-
fetchOptions?: RequestInit;
|
|
166
|
-
/**
|
|
167
|
-
* If `true`, unused variables from the operation will not be stripped from
|
|
168
|
-
* the request and will instead be sent to the GraphQL endpoint.
|
|
169
|
-
*
|
|
170
|
-
* @remarks
|
|
171
|
-
* Unused variables are likely to trigger server-side validation errors,
|
|
172
|
-
* per https://spec.graphql.org/draft/#sec-All-Variables-Used.
|
|
173
|
-
* `includeUnusedVariables` can be useful if your server deviates
|
|
174
|
-
* from the GraphQL specification by not strictly enforcing that rule.
|
|
175
|
-
*
|
|
176
|
-
* @defaultValue false
|
|
177
|
-
*/
|
|
178
|
-
includeUnusedVariables?: boolean;
|
|
179
|
-
/**
|
|
180
|
-
* A function to use when transforming a GraphQL document into a string. It
|
|
181
|
-
* accepts an `ASTNode` (typically a `DocumentNode`) and the original `print`
|
|
182
|
-
* function as arguments, and is expected to return a string. This option
|
|
183
|
-
* enables you to, for example, use `stripIgnoredCharacters` to remove
|
|
184
|
-
* whitespace from queries.
|
|
185
|
-
*
|
|
186
|
-
* By default the [GraphQL `print` function](https://graphql.org/graphql-js/language/#print) is used.
|
|
187
|
-
*
|
|
188
|
-
* @example
|
|
189
|
-
*
|
|
190
|
-
* ```ts
|
|
191
|
-
* import { stripIgnoredCharacters } from "graphql";
|
|
192
|
-
*
|
|
193
|
-
* const httpLink = new HttpLink({
|
|
194
|
-
* uri: "/graphql",
|
|
195
|
-
* print: (ast, originalPrint) => stripIgnoredCharacters(originalPrint(ast)),
|
|
196
|
-
* });
|
|
197
|
-
* ```
|
|
198
|
-
*/
|
|
199
|
-
print?: HttpLink.Printer;
|
|
200
|
-
}
|
|
14
|
+
interface ContextOptions extends BaseHttpLink.ContextOptions, ClientAwarenessLink.ContextOptions {
|
|
201
15
|
}
|
|
202
16
|
/**
|
|
203
17
|
* Options provided to the `HttpLink` constructor.
|
|
@@ -208,25 +22,8 @@ export declare namespace HttpLink {
|
|
|
208
22
|
* > these options as default values that are used when the request context
|
|
209
23
|
* > does not override the value.
|
|
210
24
|
*/
|
|
211
|
-
interface Options extends
|
|
212
|
-
/**
|
|
213
|
-
* If `true`, the link uses an HTTP `GET` request when sending query
|
|
214
|
-
* operations to your GraphQL endpoint. Mutation operations continue to use
|
|
215
|
-
* `POST` requests. If you want all operations to use `GET` requests,
|
|
216
|
-
* set `fetchOptions.method` instead.
|
|
217
|
-
*
|
|
218
|
-
* @defaultValue false
|
|
219
|
-
*/
|
|
220
|
-
useGETForQueries?: boolean;
|
|
221
|
-
}
|
|
222
|
-
interface Body {
|
|
223
|
-
query?: string;
|
|
224
|
-
operationName?: string;
|
|
225
|
-
variables?: Record<string, any>;
|
|
226
|
-
extensions?: Record<string, any>;
|
|
25
|
+
interface Options extends BaseHttpLink.Options, ClientAwarenessLink.Options {
|
|
227
26
|
}
|
|
228
|
-
type Printer = (node: ASTNode, originalPrint: typeof print) => string;
|
|
229
|
-
type UriFunction = (operation: ApolloLink.Operation) => string;
|
|
230
27
|
}
|
|
231
28
|
/**
|
|
232
29
|
* `HttpLink` is a terminating link that sends a GraphQL operation to a remote
|
|
@@ -251,11 +48,11 @@ export declare namespace HttpLink {
|
|
|
251
48
|
* ```
|
|
252
49
|
*/
|
|
253
50
|
export declare class HttpLink extends ApolloLink {
|
|
254
|
-
constructor(options?: HttpLink.Options
|
|
51
|
+
constructor(options?: HttpLink.Options);
|
|
255
52
|
}
|
|
256
53
|
/**
|
|
257
54
|
* @deprecated
|
|
258
55
|
* Use `HttpLink` from `@apollo/client/link/http` instead.
|
|
259
56
|
*/
|
|
260
|
-
export declare const createHttpLink: (
|
|
261
|
-
//# sourceMappingURL=HttpLink.d.ts.map
|
|
57
|
+
export declare const createHttpLink: (options?: HttpLink.Options) => HttpLink;
|
|
58
|
+
//# sourceMappingURL=HttpLink.d.ts.map
|
package/link/http/HttpLink.js
CHANGED
|
@@ -37,5 +37,5 @@ export class HttpLink extends ApolloLink {
|
|
|
37
37
|
* @deprecated
|
|
38
38
|
* Use `HttpLink` from `@apollo/client/link/http` instead.
|
|
39
39
|
*/
|
|
40
|
-
export const createHttpLink = (
|
|
40
|
+
export const createHttpLink = (options = {}) => new HttpLink(options);
|
|
41
41
|
//# sourceMappingURL=HttpLink.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpLink.js","sourceRoot":"","sources":["../../../src/link/http/HttpLink.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"HttpLink.js","sourceRoot":"","sources":["../../../src/link/http/HttpLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAE3E,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AA4BjD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,QAAS,SAAQ,UAAU;IACtC,YAAY,UAA4B,EAAE;QACxC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC,IAAI,CAAC;YAC/C,IAAI,mBAAmB,CAAC,OAAO,CAAC;YAChC,IAAI,YAAY,CAAC,OAAO,CAAC;SAC1B,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;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,UAA4B,EAAE,EAAE,EAAE,CAC/D,IAAI,QAAQ,CAAC,OAAO,CAAC,CAAC","sourcesContent":["import { ApolloLink } from \"@apollo/client/link\";\nimport { ClientAwarenessLink } from \"@apollo/client/link/client-awareness\";\n\nimport { BaseHttpLink } from \"./BaseHttpLink.js\";\n\nexport declare namespace HttpLink {\n /**\n * Options passed to `HttpLink` 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 `HttpLink` for each operation.\n *\n * > [!NOTE]\n * > Some of these values can also be provided to the `HttpLink` constructor.\n * > If a value is provided to both, the value in `context` takes precedence.\n */\n interface ContextOptions\n extends BaseHttpLink.ContextOptions,\n ClientAwarenessLink.ContextOptions {}\n\n /**\n * Options provided to the `HttpLink` constructor.\n *\n * > [!NOTE]\n * > Some of these options are also available to override in [request context](https://apollographql.com/docs/react/api/link/introduction#managing-context).\n * > Context options override the options passed to the constructor. Treat\n * > these options as default values that are used when the request context\n * > does not override the value.\n */\n interface Options extends BaseHttpLink.Options, ClientAwarenessLink.Options {}\n}\n\n/**\n * `HttpLink` is a terminating link that sends a GraphQL operation to a remote\n * endpoint over HTTP. It combines the functionality of `BaseHttpLink` and\n * `ClientAwarenessLink` into a single link.\n *\n * @remarks\n *\n * `HttpLink` supports both POST and GET requests, and you can configure HTTP\n * options on a per-operation basis. You can use these options for\n * authentication, persisted queries, dynamic URIs, and other granular updates.\n *\n * @example\n *\n * ```ts\n * import { HttpLink } from \"@apollo/client\";\n *\n * const link = new HttpLink({\n * uri: \"http://localhost:4000/graphql\",\n * // Additional options\n * });\n * ```\n */\nexport class HttpLink extends ApolloLink {\n constructor(options: HttpLink.Options = {}) {\n const { left, right, request } = ApolloLink.from([\n new ClientAwarenessLink(options),\n new BaseHttpLink(options),\n ]);\n super(request);\n Object.assign(this, { left, right });\n }\n}\n\n/**\n * @deprecated\n * Use `HttpLink` from `@apollo/client/link/http` instead.\n */\nexport const createHttpLink = (options: HttpLink.Options = {}) =>\n new HttpLink(options);\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function rewriteURIForGET(chosenURI: string, body:
|
|
1
|
+
import type { BaseHttpLink } from "./BaseHttpLink.js";
|
|
2
|
+
export declare function rewriteURIForGET(chosenURI: string, body: BaseHttpLink.Body): {
|
|
3
3
|
parseError: unknown;
|
|
4
4
|
newURI?: undefined;
|
|
5
5
|
} | {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rewriteURIForGET.js","sourceRoot":"","sources":["../../../src/link/http/rewriteURIForGET.ts"],"names":[],"mappings":"AAEA,4EAA4E;AAC5E,eAAe;AACf,MAAM,UAAU,gBAAgB,CAAC,SAAiB,EAAE,
|
|
1
|
+
{"version":3,"file":"rewriteURIForGET.js","sourceRoot":"","sources":["../../../src/link/http/rewriteURIForGET.ts"],"names":[],"mappings":"AAEA,4EAA4E;AAC5E,eAAe;AACf,MAAM,UAAU,gBAAgB,CAAC,SAAiB,EAAE,IAAuB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C;IAC1B,MAAM,aAAa,GAAG,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC7C,IAAI,aAAa,KAAK,CAAC,CAAC,EAAE,CAAC;QACzB,QAAQ,GAAG,SAAS,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;QAC3C,WAAW,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC;IACnD,CAAC;IACD,MAAM,iBAAiB,GAAG,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;IACtE,MAAM,MAAM,GACV,WAAW,GAAG,iBAAiB,GAAG,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;IACrE,OAAO,EAAE,MAAM,EAAE,CAAC;AACpB,CAAC","sourcesContent":["import type { BaseHttpLink } from \"./BaseHttpLink.js\";\n\n// For GET operations, returns the given URI rewritten with parameters, or a\n// parse error.\nexport function rewriteURIForGET(chosenURI: string, body: BaseHttpLink.Body) {\n // Implement the standard HTTP GET serialization, plus 'extensions'. Note\n // the extra level of JSON serialization!\n const queryParams: string[] = [];\n const addQueryParam = (key: string, value: string) => {\n queryParams.push(`${key}=${encodeURIComponent(value)}`);\n };\n\n if (\"query\" in body) {\n addQueryParam(\"query\", body.query!);\n }\n if (body.operationName) {\n addQueryParam(\"operationName\", body.operationName);\n }\n if (body.variables) {\n let serializedVariables;\n try {\n serializedVariables = JSON.stringify(body.variables);\n } catch (parseError) {\n return { parseError };\n }\n addQueryParam(\"variables\", serializedVariables);\n }\n if (body.extensions) {\n let serializedExtensions;\n try {\n serializedExtensions = JSON.stringify(body.extensions);\n } catch (parseError) {\n return { parseError };\n }\n addQueryParam(\"extensions\", serializedExtensions);\n }\n\n // Reconstruct the URI with added query params.\n // XXX This assumes that the URI is well-formed and that it doesn't\n // already contain any of these query params. We could instead use the\n // URL API and take a polyfill (whatwg-url@6) for older browsers that\n // don't support URLSearchParams. Note that some browsers (and\n // versions of whatwg-url) support URL but not URLSearchParams!\n let fragment = \"\",\n preFragment = chosenURI;\n const fragmentStart = chosenURI.indexOf(\"#\");\n if (fragmentStart !== -1) {\n fragment = chosenURI.substr(fragmentStart);\n preFragment = chosenURI.substr(0, fragmentStart);\n }\n const queryParamsPrefix = preFragment.indexOf(\"?\") === -1 ? \"?\" : \"&\";\n const newURI =\n preFragment + queryParamsPrefix + queryParams.join(\"&\") + fragment;\n return { newURI };\n}\n"]}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { ApolloLink } from "@apollo/client/link";
|
|
2
|
-
import type {
|
|
2
|
+
import type { BaseHttpLink } from "./BaseHttpLink.js";
|
|
3
3
|
interface HttpConfig {
|
|
4
|
-
http?:
|
|
4
|
+
http?: BaseHttpLink.HttpOptions;
|
|
5
5
|
options?: any;
|
|
6
6
|
headers?: Record<string, string>;
|
|
7
7
|
credentials?: any;
|
|
8
8
|
}
|
|
9
9
|
export declare const fallbackHttpConfig: {
|
|
10
|
-
http:
|
|
10
|
+
http: BaseHttpLink.HttpOptions;
|
|
11
11
|
headers: {
|
|
12
12
|
accept: string;
|
|
13
13
|
"content-type": string;
|
|
@@ -16,14 +16,14 @@ export declare const fallbackHttpConfig: {
|
|
|
16
16
|
method: string;
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
|
-
export declare const defaultPrinter:
|
|
19
|
+
export declare const defaultPrinter: BaseHttpLink.Printer;
|
|
20
20
|
export declare function selectHttpOptionsAndBody(operation: ApolloLink.Operation, fallbackConfig: HttpConfig, ...configs: Array<HttpConfig>): {
|
|
21
21
|
options: HttpConfig & Record<string, any>;
|
|
22
|
-
body:
|
|
22
|
+
body: BaseHttpLink.Body;
|
|
23
23
|
};
|
|
24
|
-
export declare function selectHttpOptionsAndBodyInternal(operation: ApolloLink.Operation, printer:
|
|
24
|
+
export declare function selectHttpOptionsAndBodyInternal(operation: ApolloLink.Operation, printer: BaseHttpLink.Printer, ...configs: HttpConfig[]): {
|
|
25
25
|
options: HttpConfig & Record<string, any>;
|
|
26
|
-
body:
|
|
26
|
+
body: BaseHttpLink.Body;
|
|
27
27
|
};
|
|
28
28
|
export {};
|
|
29
29
|
//# sourceMappingURL=selectHttpOptionsAndBody.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectHttpOptionsAndBody.js","sourceRoot":"","sources":["../../../src/link/http/selectHttpOptionsAndBody.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAWjD,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"selectHttpOptionsAndBody.js","sourceRoot":"","sources":["../../../src/link/http/selectHttpOptionsAndBody.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAWjD,MAAM,kBAAkB,GAA6B;IACnD,YAAY,EAAE,IAAI;IAClB,iBAAiB,EAAE,IAAI;IACvB,kBAAkB,EAAE,KAAK;CAC1B,CAAC;AAEF,MAAM,cAAc,GAAG;IACrB,qEAAqE;IACrE,MAAM,EAAE,0DAA0D;IAClE,6EAA6E;IAC7E,4EAA4E;IAC5E,8EAA8E;IAC9E,6EAA6E;IAC7E,2EAA2E;IAC3E,wEAAwE;IACxE,4EAA4E;IAC5E,6EAA6E;IAC7E,2EAA2E;IAC3E,iEAAiE;IACjE,6GAA6G;IAC7G,oBAAoB;IACpB,cAAc,EAAE,kBAAkB;CACnC,CAAC;AAEF,MAAM,cAAc,GAAG;IACrB,MAAM,EAAE,MAAM;CACf,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,IAAI,EAAE,kBAAkB;IACxB,OAAO,EAAE,cAAc;IACvB,OAAO,EAAE,cAAc;CACxB,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAyB,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CACnE,OAAO,CAAC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AC,IAAI,EAAE,EAAE;QACvC,iBAAiB,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC;IAC5E,CAAC,CAAC,CAAC;IACH,OAAO,iBAAiB,CAAC;AAC3B,CAAC","sourcesContent":["import type { ApolloLink } from \"@apollo/client/link\";\nimport { print } from \"@apollo/client/utilities\";\n\nimport type { BaseHttpLink } from \"./BaseHttpLink.js\";\n\ninterface HttpConfig {\n http?: BaseHttpLink.HttpOptions;\n options?: any;\n headers?: Record<string, string>;\n credentials?: any;\n}\n\nconst defaultHttpOptions: BaseHttpLink.HttpOptions = {\n includeQuery: true,\n includeExtensions: true,\n preserveHeaderCase: false,\n};\n\nconst defaultHeaders = {\n // headers are case insensitive (https://stackoverflow.com/a/5259004)\n accept: \"application/graphql-response+json,application/json;q=0.9\",\n // The content-type header describes the type of the body of the request, and\n // so it typically only is sent with requests that actually have bodies. One\n // could imagine that Apollo Client would remove this header when constructing\n // a GET request (which has no body), but we historically have not done that.\n // This means that browsers will preflight all Apollo Client requests (even\n // GET requests). Apollo Server's CSRF prevention feature (introduced in\n // AS3.7) takes advantage of this fact and does not block requests with this\n // header. If you want to drop this header from GET requests, then you should\n // probably replace it with a `apollo-require-preflight` header, or servers\n // with CSRF prevention enabled might block your GET request. See\n // https://www.apollographql.com/docs/apollo-server/security/cors/#preventing-cross-site-request-forgery-csrf\n // for more details.\n \"content-type\": \"application/json\",\n};\n\nconst defaultOptions = {\n method: \"POST\",\n};\n\nexport const fallbackHttpConfig = {\n http: defaultHttpOptions,\n headers: defaultHeaders,\n options: defaultOptions,\n};\n\nexport const defaultPrinter: BaseHttpLink.Printer = (ast, printer) =>\n printer(ast);\n\nexport function selectHttpOptionsAndBody(\n operation: ApolloLink.Operation,\n fallbackConfig: HttpConfig,\n ...configs: Array<HttpConfig>\n) {\n configs.unshift(fallbackConfig);\n return selectHttpOptionsAndBodyInternal(\n operation,\n defaultPrinter,\n ...configs\n );\n}\n\nexport function selectHttpOptionsAndBodyInternal(\n operation: ApolloLink.Operation,\n printer: BaseHttpLink.Printer,\n ...configs: HttpConfig[]\n) {\n let options = {} as HttpConfig & Record<string, any>;\n let http = {} as BaseHttpLink.HttpOptions;\n\n configs.forEach((config) => {\n options = {\n ...options,\n ...config.options,\n headers: {\n ...options.headers,\n ...config.headers,\n },\n };\n\n if (config.credentials) {\n options.credentials = config.credentials;\n }\n\n options.headers!.accept = (config.http?.accept || [])\n .concat(options.headers!.accept)\n .join(\",\");\n\n http = {\n ...http,\n ...config.http,\n };\n });\n\n options.headers = removeDuplicateHeaders(\n options.headers!,\n http.preserveHeaderCase\n );\n\n //The body depends on the http options\n const { operationName, extensions, variables, query } = operation;\n const body: BaseHttpLink.Body = { operationName, variables };\n\n if (http.includeExtensions && Object.keys(extensions || {}).length)\n (body as any).extensions = extensions;\n\n // not sending the query (i.e persisted queries)\n if (http.includeQuery) (body as any).query = printer(query, print);\n\n return {\n options,\n body,\n };\n}\n\n// Remove potential duplicate header names, preserving last (by insertion order).\n// This is done to prevent unintentionally duplicating a header instead of\n// overwriting it (See #8447 and #8449).\nfunction removeDuplicateHeaders(\n headers: Record<string, string>,\n preserveHeaderCase: boolean | undefined\n): typeof headers {\n // If we're not preserving the case, just remove duplicates w/ normalization.\n if (!preserveHeaderCase) {\n const normalizedHeaders: Record<string, string> = {};\n Object.keys(Object(headers)).forEach((name) => {\n normalizedHeaders[name.toLowerCase()] = headers[name];\n });\n return normalizedHeaders;\n }\n\n // If we are preserving the case, remove duplicates w/ normalization,\n // preserving the original name.\n // This allows for non-http-spec-compliant servers that expect intentionally\n // capitalized header names (See #6741).\n const headerData: Record<string, { originalName: string; value: string }> =\n {};\n Object.keys(Object(headers)).forEach((name) => {\n headerData[name.toLowerCase()] = {\n originalName: name,\n value: headers[name],\n };\n });\n\n const normalizedHeaders: Record<string, string> = {};\n Object.keys(headerData).forEach((name) => {\n normalizedHeaders[headerData[name].originalName] = headerData[name].value;\n });\n return normalizedHeaders;\n}\n"]}
|
|
@@ -3,34 +3,199 @@ import type { ErrorLike } from "@apollo/client";
|
|
|
3
3
|
import { ApolloLink } from "@apollo/client/link";
|
|
4
4
|
export declare const VERSION = 1;
|
|
5
5
|
export declare namespace PersistedQueryLink {
|
|
6
|
+
namespace PersistedQueryLinkDocumentationTypes {
|
|
7
|
+
/**
|
|
8
|
+
* A SHA-256 hash function for hashing query strings.
|
|
9
|
+
*
|
|
10
|
+
* @param queryString - The query string to hash
|
|
11
|
+
* @returns The SHA-256 hash or a promise that resolves to the SHA-256 hash
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { sha256 } from "crypto-hash";
|
|
17
|
+
*
|
|
18
|
+
* const link = new PersistedQueryLink({ sha256 });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
function SHA256Function(queryString: string): string | PromiseLike<string>;
|
|
22
|
+
/**
|
|
23
|
+
* A function that generates a hash for a GraphQL document.
|
|
24
|
+
*
|
|
25
|
+
* @param document - The GraphQL document to hash
|
|
26
|
+
* @returns The hash string or a promise that resolves to the hash string
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { print } from "graphql";
|
|
32
|
+
* import { sha256 } from "crypto-hash";
|
|
33
|
+
*
|
|
34
|
+
* const link = new PersistedQueryLink({
|
|
35
|
+
* generateHash: async (document) => {
|
|
36
|
+
* const query = print(document);
|
|
37
|
+
* return sha256(query);
|
|
38
|
+
* },
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
function GenerateHashFunction(document: DocumentNode): string | PromiseLike<string>;
|
|
43
|
+
}
|
|
6
44
|
namespace Base {
|
|
45
|
+
/**
|
|
46
|
+
* Base options shared between SHA256 and custom hash configurations.
|
|
47
|
+
*/
|
|
7
48
|
interface Options {
|
|
49
|
+
/**
|
|
50
|
+
* A function to disable persisted queries for the current session.
|
|
51
|
+
*
|
|
52
|
+
* This function is called when an error occurs and determines whether
|
|
53
|
+
* to disable persisted queries for all future requests in this session.
|
|
54
|
+
*
|
|
55
|
+
* @defaultValue Disables on `PersistedQueryNotSupported` errors
|
|
56
|
+
*/
|
|
8
57
|
disable?: (options: PersistedQueryLink.DisableFunctionOptions) => boolean;
|
|
58
|
+
/**
|
|
59
|
+
* A function to determine whether to retry a request with the full query.
|
|
60
|
+
*
|
|
61
|
+
* When a persisted query fails, this function determines whether to
|
|
62
|
+
* retry the request with the full query text included.
|
|
63
|
+
*
|
|
64
|
+
* @defaultValue Retries on `PersistedQueryNotSupported` or `PersistedQueryNotFound` errors
|
|
65
|
+
*/
|
|
9
66
|
retry?: (options: PersistedQueryLink.RetryFunctionOptions) => boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Whether to use HTTP GET for hashed queries (excluding mutations).
|
|
69
|
+
*
|
|
70
|
+
* > [!NOTE]
|
|
71
|
+
* > If you want to use `GET` for non-mutation queries whether or not they
|
|
72
|
+
* > are hashed, pass `useGETForQueries: true` option to `HttpLink`
|
|
73
|
+
* > instead. If you want to use GET for all requests, pass `fetchOptions: {method: 'GET'}`
|
|
74
|
+
* > to `HttpLink`.
|
|
75
|
+
*
|
|
76
|
+
* @defaultValue `false`
|
|
77
|
+
*/
|
|
10
78
|
useGETForHashedQueries?: boolean;
|
|
11
79
|
}
|
|
12
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Metadata about persisted query errors extracted from the response.
|
|
83
|
+
*/
|
|
13
84
|
interface ErrorMeta {
|
|
85
|
+
/**
|
|
86
|
+
* Whether the server responded with a "PersistedQueryNotSupported" error.
|
|
87
|
+
*
|
|
88
|
+
* When `true`, indicates the server doesn't support persisted queries
|
|
89
|
+
* or has disabled them for this client.
|
|
90
|
+
*/
|
|
14
91
|
persistedQueryNotSupported: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Whether the server responded with a "PersistedQueryNotFound" error.
|
|
94
|
+
*
|
|
95
|
+
* When `true`, indicates the server doesn't recognize the query hash
|
|
96
|
+
* and needs the full query text.
|
|
97
|
+
*/
|
|
15
98
|
persistedQueryNotFound: boolean;
|
|
16
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* A function that generates a hash for a GraphQL document.
|
|
102
|
+
*
|
|
103
|
+
* @param document - The GraphQL document to hash
|
|
104
|
+
* @returns The hash string or a promise that resolves to the hash string
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
*
|
|
108
|
+
* ```ts
|
|
109
|
+
* import { print } from "graphql";
|
|
110
|
+
* import { sha256 } from "crypto-hash";
|
|
111
|
+
*
|
|
112
|
+
* const link = new PersistedQueryLink({
|
|
113
|
+
* generateHash: async (document) => {
|
|
114
|
+
* const query = print(document);
|
|
115
|
+
* return sha256(query);
|
|
116
|
+
* },
|
|
117
|
+
* });
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
17
120
|
type GenerateHashFunction = (document: DocumentNode) => string | PromiseLike<string>;
|
|
121
|
+
/**
|
|
122
|
+
* A SHA-256 hash function for hashing query strings.
|
|
123
|
+
*
|
|
124
|
+
* @param queryString - The query string to hash
|
|
125
|
+
* @returns The SHA-256 hash or a promise that resolves to the SHA-256 hash
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
*
|
|
129
|
+
* ```ts
|
|
130
|
+
* import { sha256 } from "crypto-hash";
|
|
131
|
+
*
|
|
132
|
+
* const link = new PersistedQueryLink({ sha256 });
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
18
135
|
type SHA256Function = (queryString: string) => string | PromiseLike<string>;
|
|
136
|
+
/**
|
|
137
|
+
* Options for using SHA-256 hashing with persisted queries.
|
|
138
|
+
*
|
|
139
|
+
* Use this configuration when you want the link to handle query
|
|
140
|
+
* printing and hashing using a SHA-256 function.
|
|
141
|
+
*/
|
|
19
142
|
interface SHA256Options extends Base.Options {
|
|
143
|
+
/**
|
|
144
|
+
* The SHA-256 hash function to use for hashing queries. This function
|
|
145
|
+
* receives the printed query string and should return a SHA-256 hash. Can
|
|
146
|
+
* be synchronous or asynchronous.
|
|
147
|
+
*/
|
|
20
148
|
sha256: PersistedQueryLink.SHA256Function;
|
|
21
149
|
generateHash?: never;
|
|
22
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Options for using custom hash generation with persisted queries.
|
|
153
|
+
*
|
|
154
|
+
* Use this configuration when you need custom control over how
|
|
155
|
+
* query hashes are generated (e.g., using pre-computed hashes).
|
|
156
|
+
*/
|
|
23
157
|
interface GenerateHashOptions extends Base.Options {
|
|
24
158
|
sha256?: never;
|
|
159
|
+
/**
|
|
160
|
+
* A custom function for generating query hashes. This function receives
|
|
161
|
+
* the GraphQL document and should return a hash. Useful for custom hashing
|
|
162
|
+
* strategies or when using build-time generated hashes.
|
|
163
|
+
*/
|
|
25
164
|
generateHash: PersistedQueryLink.GenerateHashFunction;
|
|
26
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Configuration options for creating a `PersistedQueryLink`.
|
|
168
|
+
*
|
|
169
|
+
* You must provide either a `sha256` function or a custom `generateHash`
|
|
170
|
+
* function, but not both.
|
|
171
|
+
*/
|
|
27
172
|
type Options = PersistedQueryLink.SHA256Options | PersistedQueryLink.GenerateHashOptions;
|
|
173
|
+
/**
|
|
174
|
+
* Options passed to the `retry` function when a persisted query request
|
|
175
|
+
* fails.
|
|
176
|
+
*/
|
|
28
177
|
interface RetryFunctionOptions {
|
|
178
|
+
/**
|
|
179
|
+
* The error that occurred during the request.
|
|
180
|
+
*/
|
|
29
181
|
error: ErrorLike;
|
|
182
|
+
/**
|
|
183
|
+
* The GraphQL operation that failed.
|
|
184
|
+
*/
|
|
30
185
|
operation: ApolloLink.Operation;
|
|
186
|
+
/**
|
|
187
|
+
* Metadata about the persisted query error.
|
|
188
|
+
*/
|
|
31
189
|
meta: PersistedQueryLink.ErrorMeta;
|
|
190
|
+
/**
|
|
191
|
+
* The GraphQL result, if available.
|
|
192
|
+
*/
|
|
32
193
|
result?: FormattedExecutionResult;
|
|
33
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* Options passed to the `disable` function when a persisted query request
|
|
197
|
+
* fails.
|
|
198
|
+
*/
|
|
34
199
|
interface DisableFunctionOptions extends PersistedQueryLink.RetryFunctionOptions {
|
|
35
200
|
}
|
|
36
201
|
}
|
|
@@ -39,8 +204,24 @@ export declare namespace PersistedQueryLink {
|
|
|
39
204
|
* Use `PersistedQueryLink` from `@apollo/client/link/persisted-queries` instead.
|
|
40
205
|
*/
|
|
41
206
|
export declare const createPersistedQueryLink: (options: PersistedQueryLink.Options) => PersistedQueryLink;
|
|
207
|
+
/**
|
|
208
|
+
* `PersistedQueryLink` is a non-terminating link that enables the use of
|
|
209
|
+
* persisted queries, a technique that reduces bandwidth by sending query hashes
|
|
210
|
+
* instead of full query strings.
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
*
|
|
214
|
+
* ```ts
|
|
215
|
+
* import { PersistedQueryLink } from "@apollo/client/link/persisted-queries";
|
|
216
|
+
* import { sha256 } from "crypto-hash";
|
|
217
|
+
*
|
|
218
|
+
* const link = new PersistedQueryLink({
|
|
219
|
+
* sha256: (queryString) => sha256(queryString),
|
|
220
|
+
* });
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
42
223
|
export declare class PersistedQueryLink extends ApolloLink {
|
|
43
224
|
constructor(options: PersistedQueryLink.Options);
|
|
44
225
|
resetHashCache: () => void;
|
|
45
226
|
}
|
|
46
|
-
//# sourceMappingURL=index.d.ts.map
|
|
227
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -35,6 +35,22 @@ function operationDefinesMutation(operation) {
|
|
|
35
35
|
* Use `PersistedQueryLink` from `@apollo/client/link/persisted-queries` instead.
|
|
36
36
|
*/
|
|
37
37
|
export const createPersistedQueryLink = (options) => new PersistedQueryLink(options);
|
|
38
|
+
/**
|
|
39
|
+
* `PersistedQueryLink` is a non-terminating link that enables the use of
|
|
40
|
+
* persisted queries, a technique that reduces bandwidth by sending query hashes
|
|
41
|
+
* instead of full query strings.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
*
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { PersistedQueryLink } from "@apollo/client/link/persisted-queries";
|
|
47
|
+
* import { sha256 } from "crypto-hash";
|
|
48
|
+
*
|
|
49
|
+
* const link = new PersistedQueryLink({
|
|
50
|
+
* sha256: (queryString) => sha256(queryString),
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
38
54
|
export class PersistedQueryLink extends ApolloLink {
|
|
39
55
|
constructor(options) {
|
|
40
56
|
let hashesByQuery;
|