@graphql-tools/executor-http 1.2.0-alpha-66d4b92ec6c93cfa4098b6caf98cffd89e210038 → 1.2.0
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 +2 -2
- package/dist/index.cjs +33 -62
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +35 -64
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# @graphql-tools/executor-http
|
|
2
2
|
|
|
3
|
-
## 1.2.0
|
|
3
|
+
## 1.2.0
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
7
|
-
- [#313](https://github.com/graphql-hive/gateway/pull/313) [`
|
|
7
|
+
- [#313](https://github.com/graphql-hive/gateway/pull/313) [`367b359`](https://github.com/graphql-hive/gateway/commit/367b3593cb7fd51c42ef4a13ab4adac202845734) Thanks [@ardatan](https://github.com/ardatan)! - Automatic Persisted Queries support for upstream requests
|
|
8
8
|
|
|
9
9
|
For HTTP Executor;
|
|
10
10
|
|
package/dist/index.cjs
CHANGED
|
@@ -14,64 +14,6 @@ function isGraphQLUpload(upload) {
|
|
|
14
14
|
return typeof upload.createReadStream === "function";
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
function createAbortErrorReason() {
|
|
18
|
-
return new Error("Executor was disposed.");
|
|
19
|
-
}
|
|
20
|
-
function createGraphQLErrorForAbort(reason, extensions) {
|
|
21
|
-
return utils.createGraphQLError("The operation was aborted. reason: " + reason, {
|
|
22
|
-
extensions
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
function createResultForAbort(reason, extensions) {
|
|
26
|
-
return {
|
|
27
|
-
errors: [createGraphQLErrorForAbort(reason, extensions)]
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function hashSHA256(str) {
|
|
31
|
-
const textEncoder = new fetch.TextEncoder();
|
|
32
|
-
const utf8 = textEncoder.encode(str);
|
|
33
|
-
return utils.mapMaybePromise(
|
|
34
|
-
fetch.crypto.subtle.digest("SHA-256", utf8),
|
|
35
|
-
(hashBuffer) => {
|
|
36
|
-
let hashHex = "";
|
|
37
|
-
for (const bytes of new Uint8Array(hashBuffer)) {
|
|
38
|
-
hashHex += bytes.toString(16).padStart(2, "0");
|
|
39
|
-
}
|
|
40
|
-
return hashHex;
|
|
41
|
-
}
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
function jsonStringifyBody(body) {
|
|
45
|
-
let str = "{";
|
|
46
|
-
let prev = false;
|
|
47
|
-
if (body.query) {
|
|
48
|
-
str += `"query":"${body.query.replaceAll('"', '\\"')}"`;
|
|
49
|
-
prev = true;
|
|
50
|
-
}
|
|
51
|
-
if (body.variables) {
|
|
52
|
-
if (prev) {
|
|
53
|
-
str += ",";
|
|
54
|
-
}
|
|
55
|
-
str += `"variables":${JSON.stringify(body.variables)}`;
|
|
56
|
-
prev = true;
|
|
57
|
-
}
|
|
58
|
-
if (body.operationName) {
|
|
59
|
-
if (prev) {
|
|
60
|
-
str += ",";
|
|
61
|
-
}
|
|
62
|
-
str += `"operationName":"${body.operationName}"`;
|
|
63
|
-
prev = true;
|
|
64
|
-
}
|
|
65
|
-
if (body.extensions) {
|
|
66
|
-
if (prev) {
|
|
67
|
-
str += ",";
|
|
68
|
-
}
|
|
69
|
-
str += `"extensions":${JSON.stringify(body.extensions)}`;
|
|
70
|
-
}
|
|
71
|
-
str += "}";
|
|
72
|
-
return str;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
17
|
function collectAsyncIterableValues(asyncIterable) {
|
|
76
18
|
const values = [];
|
|
77
19
|
const iterator = asyncIterable[Symbol.asyncIterator]();
|
|
@@ -93,15 +35,16 @@ function createFormDataFromVariables(body, {
|
|
|
93
35
|
FormData: FormDataCtor = fetch.FormData
|
|
94
36
|
}) {
|
|
95
37
|
if (!body.variables) {
|
|
96
|
-
return
|
|
38
|
+
return JSON.stringify(body);
|
|
97
39
|
}
|
|
40
|
+
const vars = Object.assign({}, body.variables);
|
|
98
41
|
const { clone, files } = extractFiles.extractFiles(
|
|
99
|
-
|
|
42
|
+
vars,
|
|
100
43
|
"variables",
|
|
101
44
|
(v) => extractFiles.isExtractableFile(v) || v?.promise || utils.isAsyncIterable(v) || v?.then || typeof v?.arrayBuffer === "function"
|
|
102
45
|
);
|
|
103
46
|
if (files.size === 0) {
|
|
104
|
-
return
|
|
47
|
+
return JSON.stringify(body);
|
|
105
48
|
}
|
|
106
49
|
const map = {};
|
|
107
50
|
const uploads = [];
|
|
@@ -114,7 +57,7 @@ function createFormDataFromVariables(body, {
|
|
|
114
57
|
const form = new FormDataCtor();
|
|
115
58
|
form.append(
|
|
116
59
|
"operations",
|
|
117
|
-
|
|
60
|
+
JSON.stringify({
|
|
118
61
|
...body,
|
|
119
62
|
variables: clone
|
|
120
63
|
})
|
|
@@ -181,6 +124,34 @@ const defaultPrintFn = utils.memoize1(function defaultPrintFn2(document) {
|
|
|
181
124
|
return graphql.stripIgnoredCharacters(graphql.print(document));
|
|
182
125
|
});
|
|
183
126
|
|
|
127
|
+
function createAbortErrorReason() {
|
|
128
|
+
return new Error("Executor was disposed.");
|
|
129
|
+
}
|
|
130
|
+
function createGraphQLErrorForAbort(reason, extensions) {
|
|
131
|
+
return utils.createGraphQLError("The operation was aborted. reason: " + reason, {
|
|
132
|
+
extensions
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
function createResultForAbort(reason, extensions) {
|
|
136
|
+
return {
|
|
137
|
+
errors: [createGraphQLErrorForAbort(reason, extensions)]
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function hashSHA256(str) {
|
|
141
|
+
const textEncoder = new fetch.TextEncoder();
|
|
142
|
+
const utf8 = textEncoder.encode(str);
|
|
143
|
+
return utils.mapMaybePromise(
|
|
144
|
+
fetch.crypto.subtle.digest("SHA-256", utf8),
|
|
145
|
+
(hashBuffer) => {
|
|
146
|
+
let hashHex = "";
|
|
147
|
+
for (const bytes of new Uint8Array(hashBuffer)) {
|
|
148
|
+
hashHex += bytes.toString(16).padStart(2, "0");
|
|
149
|
+
}
|
|
150
|
+
return hashHex;
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
184
155
|
const DELIM = "\n\n";
|
|
185
156
|
function isReadableStream(value) {
|
|
186
157
|
return value && typeof value.getReader === "function";
|
package/dist/index.d.cts
CHANGED
|
@@ -80,6 +80,12 @@ interface HTTPExecutorOptions {
|
|
|
80
80
|
*/
|
|
81
81
|
disposable?: boolean;
|
|
82
82
|
}
|
|
83
|
+
type SerializedRequest = {
|
|
84
|
+
query?: string;
|
|
85
|
+
variables?: Record<string, any>;
|
|
86
|
+
operationName?: string;
|
|
87
|
+
extensions?: any;
|
|
88
|
+
};
|
|
83
89
|
type HeadersConfig = Record<string, string>;
|
|
84
90
|
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch'> & {
|
|
85
91
|
fetch: SyncFetchFn;
|
|
@@ -92,4 +98,4 @@ declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch'>
|
|
|
92
98
|
}): DisposableAsyncExecutor<any, HTTPExecutorOptions>;
|
|
93
99
|
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch'>): DisposableAsyncExecutor<any, HTTPExecutorOptions>;
|
|
94
100
|
|
|
95
|
-
export { type AsyncFetchFn, type AsyncImportFn, type FetchFn, type HTTPExecutorOptions, type HeadersConfig, type RegularFetchFn, type SyncFetchFn, type SyncImportFn, type SyncResponse, buildHTTPExecutor, isLiveQueryOperationDefinitionNode };
|
|
101
|
+
export { type AsyncFetchFn, type AsyncImportFn, type FetchFn, type HTTPExecutorOptions, type HeadersConfig, type RegularFetchFn, type SerializedRequest, type SyncFetchFn, type SyncImportFn, type SyncResponse, buildHTTPExecutor, isLiveQueryOperationDefinitionNode };
|
package/dist/index.d.ts
CHANGED
|
@@ -80,6 +80,12 @@ interface HTTPExecutorOptions {
|
|
|
80
80
|
*/
|
|
81
81
|
disposable?: boolean;
|
|
82
82
|
}
|
|
83
|
+
type SerializedRequest = {
|
|
84
|
+
query?: string;
|
|
85
|
+
variables?: Record<string, any>;
|
|
86
|
+
operationName?: string;
|
|
87
|
+
extensions?: any;
|
|
88
|
+
};
|
|
83
89
|
type HeadersConfig = Record<string, string>;
|
|
84
90
|
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch'> & {
|
|
85
91
|
fetch: SyncFetchFn;
|
|
@@ -92,4 +98,4 @@ declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch'>
|
|
|
92
98
|
}): DisposableAsyncExecutor<any, HTTPExecutorOptions>;
|
|
93
99
|
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch'>): DisposableAsyncExecutor<any, HTTPExecutorOptions>;
|
|
94
100
|
|
|
95
|
-
export { type AsyncFetchFn, type AsyncImportFn, type FetchFn, type HTTPExecutorOptions, type HeadersConfig, type RegularFetchFn, type SyncFetchFn, type SyncImportFn, type SyncResponse, buildHTTPExecutor, isLiveQueryOperationDefinitionNode };
|
|
101
|
+
export { type AsyncFetchFn, type AsyncImportFn, type FetchFn, type HTTPExecutorOptions, type HeadersConfig, type RegularFetchFn, type SerializedRequest, type SyncFetchFn, type SyncImportFn, type SyncResponse, buildHTTPExecutor, isLiveQueryOperationDefinitionNode };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isAsyncIterable, isPromise, mapMaybePromise, memoize1, createGraphQLError, inspect, mapAsyncIterator, mergeIncrementalResult, getOperationASTFromRequest } from '@graphql-tools/utils';
|
|
2
2
|
import { DisposableSymbols } from '@whatwg-node/disposablestack';
|
|
3
|
-
import {
|
|
3
|
+
import { File, FormData, TextEncoder, crypto, TextDecoder, fetch } from '@whatwg-node/fetch';
|
|
4
4
|
import { ValueOrPromise } from 'value-or-promise';
|
|
5
5
|
import { extractFiles, isExtractableFile } from 'extract-files';
|
|
6
6
|
import { stripIgnoredCharacters, print } from 'graphql';
|
|
@@ -12,64 +12,6 @@ function isGraphQLUpload(upload) {
|
|
|
12
12
|
return typeof upload.createReadStream === "function";
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
function createAbortErrorReason() {
|
|
16
|
-
return new Error("Executor was disposed.");
|
|
17
|
-
}
|
|
18
|
-
function createGraphQLErrorForAbort(reason, extensions) {
|
|
19
|
-
return createGraphQLError("The operation was aborted. reason: " + reason, {
|
|
20
|
-
extensions
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
function createResultForAbort(reason, extensions) {
|
|
24
|
-
return {
|
|
25
|
-
errors: [createGraphQLErrorForAbort(reason, extensions)]
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
function hashSHA256(str) {
|
|
29
|
-
const textEncoder = new TextEncoder();
|
|
30
|
-
const utf8 = textEncoder.encode(str);
|
|
31
|
-
return mapMaybePromise(
|
|
32
|
-
crypto.subtle.digest("SHA-256", utf8),
|
|
33
|
-
(hashBuffer) => {
|
|
34
|
-
let hashHex = "";
|
|
35
|
-
for (const bytes of new Uint8Array(hashBuffer)) {
|
|
36
|
-
hashHex += bytes.toString(16).padStart(2, "0");
|
|
37
|
-
}
|
|
38
|
-
return hashHex;
|
|
39
|
-
}
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
function jsonStringifyBody(body) {
|
|
43
|
-
let str = "{";
|
|
44
|
-
let prev = false;
|
|
45
|
-
if (body.query) {
|
|
46
|
-
str += `"query":"${body.query.replaceAll('"', '\\"')}"`;
|
|
47
|
-
prev = true;
|
|
48
|
-
}
|
|
49
|
-
if (body.variables) {
|
|
50
|
-
if (prev) {
|
|
51
|
-
str += ",";
|
|
52
|
-
}
|
|
53
|
-
str += `"variables":${JSON.stringify(body.variables)}`;
|
|
54
|
-
prev = true;
|
|
55
|
-
}
|
|
56
|
-
if (body.operationName) {
|
|
57
|
-
if (prev) {
|
|
58
|
-
str += ",";
|
|
59
|
-
}
|
|
60
|
-
str += `"operationName":"${body.operationName}"`;
|
|
61
|
-
prev = true;
|
|
62
|
-
}
|
|
63
|
-
if (body.extensions) {
|
|
64
|
-
if (prev) {
|
|
65
|
-
str += ",";
|
|
66
|
-
}
|
|
67
|
-
str += `"extensions":${JSON.stringify(body.extensions)}`;
|
|
68
|
-
}
|
|
69
|
-
str += "}";
|
|
70
|
-
return str;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
15
|
function collectAsyncIterableValues(asyncIterable) {
|
|
74
16
|
const values = [];
|
|
75
17
|
const iterator = asyncIterable[Symbol.asyncIterator]();
|
|
@@ -91,15 +33,16 @@ function createFormDataFromVariables(body, {
|
|
|
91
33
|
FormData: FormDataCtor = FormData
|
|
92
34
|
}) {
|
|
93
35
|
if (!body.variables) {
|
|
94
|
-
return
|
|
36
|
+
return JSON.stringify(body);
|
|
95
37
|
}
|
|
38
|
+
const vars = Object.assign({}, body.variables);
|
|
96
39
|
const { clone, files } = extractFiles(
|
|
97
|
-
|
|
40
|
+
vars,
|
|
98
41
|
"variables",
|
|
99
42
|
(v) => isExtractableFile(v) || v?.promise || isAsyncIterable(v) || v?.then || typeof v?.arrayBuffer === "function"
|
|
100
43
|
);
|
|
101
44
|
if (files.size === 0) {
|
|
102
|
-
return
|
|
45
|
+
return JSON.stringify(body);
|
|
103
46
|
}
|
|
104
47
|
const map = {};
|
|
105
48
|
const uploads = [];
|
|
@@ -112,7 +55,7 @@ function createFormDataFromVariables(body, {
|
|
|
112
55
|
const form = new FormDataCtor();
|
|
113
56
|
form.append(
|
|
114
57
|
"operations",
|
|
115
|
-
|
|
58
|
+
JSON.stringify({
|
|
116
59
|
...body,
|
|
117
60
|
variables: clone
|
|
118
61
|
})
|
|
@@ -179,6 +122,34 @@ const defaultPrintFn = memoize1(function defaultPrintFn2(document) {
|
|
|
179
122
|
return stripIgnoredCharacters(print(document));
|
|
180
123
|
});
|
|
181
124
|
|
|
125
|
+
function createAbortErrorReason() {
|
|
126
|
+
return new Error("Executor was disposed.");
|
|
127
|
+
}
|
|
128
|
+
function createGraphQLErrorForAbort(reason, extensions) {
|
|
129
|
+
return createGraphQLError("The operation was aborted. reason: " + reason, {
|
|
130
|
+
extensions
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
function createResultForAbort(reason, extensions) {
|
|
134
|
+
return {
|
|
135
|
+
errors: [createGraphQLErrorForAbort(reason, extensions)]
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function hashSHA256(str) {
|
|
139
|
+
const textEncoder = new TextEncoder();
|
|
140
|
+
const utf8 = textEncoder.encode(str);
|
|
141
|
+
return mapMaybePromise(
|
|
142
|
+
crypto.subtle.digest("SHA-256", utf8),
|
|
143
|
+
(hashBuffer) => {
|
|
144
|
+
let hashHex = "";
|
|
145
|
+
for (const bytes of new Uint8Array(hashBuffer)) {
|
|
146
|
+
hashHex += bytes.toString(16).padStart(2, "0");
|
|
147
|
+
}
|
|
148
|
+
return hashHex;
|
|
149
|
+
}
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
182
153
|
const DELIM = "\n\n";
|
|
183
154
|
function isReadableStream(value) {
|
|
184
155
|
return value && typeof value.getReader === "function";
|
package/package.json
CHANGED