@graphql-tools/executor-http 1.2.8 → 1.2.9-alpha-3b2000e3a6b9e871ed2700b7795f23d2a15358ce
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 +8 -0
- package/dist/index.cjs +54 -44
- package/dist/index.js +54 -44
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @graphql-tools/executor-http
|
|
2
2
|
|
|
3
|
+
## 1.2.9-alpha-3b2000e3a6b9e871ed2700b7795f23d2a15358ce
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#726](https://github.com/graphql-hive/gateway/pull/726) [`3b2000e`](https://github.com/graphql-hive/gateway/commit/3b2000e3a6b9e871ed2700b7795f23d2a15358ce) Thanks [@ardatan](https://github.com/ardatan)! - dependencies updates:
|
|
8
|
+
|
|
9
|
+
- Added dependency [`@whatwg-node/promise-helpers@^1.0.0` ↗︎](https://www.npmjs.com/package/@whatwg-node/promise-helpers/v/1.0.0) (to `dependencies`)
|
|
10
|
+
|
|
3
11
|
## 1.2.8
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -4,6 +4,7 @@ var executorCommon = require('@graphql-tools/executor-common');
|
|
|
4
4
|
var utils = require('@graphql-tools/utils');
|
|
5
5
|
var disposablestack = require('@whatwg-node/disposablestack');
|
|
6
6
|
var fetch = require('@whatwg-node/fetch');
|
|
7
|
+
var promiseHelpers = require('@whatwg-node/promise-helpers');
|
|
7
8
|
var valueOrPromise = require('value-or-promise');
|
|
8
9
|
var extractFiles = require('extract-files');
|
|
9
10
|
var repeater = require('@repeaterjs/repeater');
|
|
@@ -19,15 +20,18 @@ function collectAsyncIterableValues(asyncIterable) {
|
|
|
19
20
|
const values = [];
|
|
20
21
|
const iterator = asyncIterable[Symbol.asyncIterator]();
|
|
21
22
|
function iterate() {
|
|
22
|
-
return
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
return promiseHelpers.handleMaybePromise(
|
|
24
|
+
() => iterator.next(),
|
|
25
|
+
({ value, done }) => {
|
|
26
|
+
if (value != null) {
|
|
27
|
+
values.push(value);
|
|
28
|
+
}
|
|
29
|
+
if (done) {
|
|
30
|
+
return values;
|
|
31
|
+
}
|
|
32
|
+
return iterate();
|
|
28
33
|
}
|
|
29
|
-
|
|
30
|
-
});
|
|
34
|
+
);
|
|
31
35
|
}
|
|
32
36
|
return iterate();
|
|
33
37
|
}
|
|
@@ -67,15 +71,15 @@ function createFormDataFromVariables(body, {
|
|
|
67
71
|
function handleUpload(upload, i) {
|
|
68
72
|
const indexStr = i.toString();
|
|
69
73
|
if (upload != null) {
|
|
70
|
-
return
|
|
71
|
-
upload?.promise || upload,
|
|
74
|
+
return promiseHelpers.handleMaybePromise(
|
|
75
|
+
() => upload?.promise || upload,
|
|
72
76
|
(upload2) => {
|
|
73
77
|
const filename = upload2.filename || upload2.name || upload2.path || `blob-${indexStr}`;
|
|
74
78
|
if (isBlob(upload2)) {
|
|
75
79
|
form.append(indexStr, upload2, filename);
|
|
76
80
|
} else if (utils.isAsyncIterable(upload2)) {
|
|
77
|
-
return
|
|
78
|
-
collectAsyncIterableValues(upload2),
|
|
81
|
+
return promiseHelpers.handleMaybePromise(
|
|
82
|
+
() => collectAsyncIterableValues(upload2),
|
|
79
83
|
(chunks) => {
|
|
80
84
|
const blobPart = new Uint8Array(chunks);
|
|
81
85
|
form.append(
|
|
@@ -86,8 +90,8 @@ function createFormDataFromVariables(body, {
|
|
|
86
90
|
}
|
|
87
91
|
);
|
|
88
92
|
} else if (isGraphQLUpload(upload2)) {
|
|
89
|
-
return
|
|
90
|
-
collectAsyncIterableValues(upload2.createReadStream()),
|
|
93
|
+
return promiseHelpers.handleMaybePromise(
|
|
94
|
+
() => collectAsyncIterableValues(upload2.createReadStream()),
|
|
91
95
|
(chunks) => {
|
|
92
96
|
const blobPart = new Uint8Array(chunks);
|
|
93
97
|
form.append(
|
|
@@ -108,7 +112,7 @@ function createFormDataFromVariables(body, {
|
|
|
108
112
|
for (const i in uploads) {
|
|
109
113
|
const upload = uploads[i];
|
|
110
114
|
const job = handleUpload(upload, Number(i));
|
|
111
|
-
if (
|
|
115
|
+
if (promiseHelpers.isPromise(job)) {
|
|
112
116
|
jobs.push(job);
|
|
113
117
|
}
|
|
114
118
|
}
|
|
@@ -151,8 +155,8 @@ function createResultForAbort(reason, extensions) {
|
|
|
151
155
|
function hashSHA256(str) {
|
|
152
156
|
const textEncoder = new fetch.TextEncoder();
|
|
153
157
|
const utf8 = textEncoder.encode(str);
|
|
154
|
-
return
|
|
155
|
-
fetch.crypto.subtle.digest("SHA-256", utf8),
|
|
158
|
+
return promiseHelpers.handleMaybePromise(
|
|
159
|
+
() => fetch.crypto.subtle.digest("SHA-256", utf8),
|
|
156
160
|
(hashBuffer) => {
|
|
157
161
|
let hashHex = "";
|
|
158
162
|
for (const bytes of new Uint8Array(hashBuffer)) {
|
|
@@ -356,25 +360,28 @@ function buildHTTPExecutor(options) {
|
|
|
356
360
|
};
|
|
357
361
|
if (options?.apq) {
|
|
358
362
|
serializeFn = function serializeWithAPQ() {
|
|
359
|
-
return
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
363
|
+
return promiseHelpers.handleMaybePromise(
|
|
364
|
+
() => hashSHA256(query),
|
|
365
|
+
(sha256Hash) => {
|
|
366
|
+
const extensions = request.extensions || {};
|
|
367
|
+
extensions["persistedQuery"] = {
|
|
368
|
+
version: 1,
|
|
369
|
+
sha256Hash
|
|
370
|
+
};
|
|
371
|
+
return executorCommon.serializeExecutionRequest({
|
|
372
|
+
executionRequest: {
|
|
373
|
+
...request,
|
|
374
|
+
extensions
|
|
375
|
+
},
|
|
376
|
+
excludeQuery,
|
|
377
|
+
printFn
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
);
|
|
374
381
|
};
|
|
375
382
|
}
|
|
376
|
-
return
|
|
377
|
-
serializeFn(),
|
|
383
|
+
return promiseHelpers.handleMaybePromise(
|
|
384
|
+
() => serializeFn(),
|
|
378
385
|
(body) => new valueOrPromise.ValueOrPromise(() => {
|
|
379
386
|
switch (method) {
|
|
380
387
|
case "GET": {
|
|
@@ -400,8 +407,8 @@ function buildHTTPExecutor(options) {
|
|
|
400
407
|
}
|
|
401
408
|
case "POST": {
|
|
402
409
|
upstreamErrorExtensions.request.body = body;
|
|
403
|
-
return
|
|
404
|
-
createFormDataFromVariables(body, {
|
|
410
|
+
return promiseHelpers.handleMaybePromise(
|
|
411
|
+
() => createFormDataFromVariables(body, {
|
|
405
412
|
File: options?.File,
|
|
406
413
|
FormData: options?.FormData
|
|
407
414
|
}),
|
|
@@ -536,8 +543,8 @@ function buildHTTPExecutor(options) {
|
|
|
536
543
|
let executor = baseExecutor;
|
|
537
544
|
if (options?.apq != null) {
|
|
538
545
|
executor = function apqExecutor(request) {
|
|
539
|
-
return
|
|
540
|
-
baseExecutor(request, true),
|
|
546
|
+
return promiseHelpers.handleMaybePromise(
|
|
547
|
+
() => baseExecutor(request, true),
|
|
541
548
|
(res) => {
|
|
542
549
|
if (res.errors?.some(
|
|
543
550
|
(error) => error.extensions["code"] === "PERSISTED_QUERY_NOT_FOUND" || error.message === "PersistedQueryNotFound"
|
|
@@ -567,13 +574,16 @@ function buildHTTPExecutor(options) {
|
|
|
567
574
|
errors: [utils.createGraphQLError("No response returned from fetch")]
|
|
568
575
|
};
|
|
569
576
|
}
|
|
570
|
-
return
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
577
|
+
return promiseHelpers.handleMaybePromise(
|
|
578
|
+
() => prevExecutor(request),
|
|
579
|
+
(res) => {
|
|
580
|
+
result = res;
|
|
581
|
+
if (result?.errors?.length) {
|
|
582
|
+
return retryAttempt();
|
|
583
|
+
}
|
|
584
|
+
return result;
|
|
574
585
|
}
|
|
575
|
-
|
|
576
|
-
});
|
|
586
|
+
);
|
|
577
587
|
}
|
|
578
588
|
return retryAttempt();
|
|
579
589
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { defaultPrintFn, serializeExecutionRequest } from '@graphql-tools/executor-common';
|
|
2
|
-
import { isAsyncIterable,
|
|
2
|
+
import { isAsyncIterable, createGraphQLError, inspect, mapAsyncIterator, mergeIncrementalResult, memoize1, getOperationASTFromRequest } from '@graphql-tools/utils';
|
|
3
3
|
import { DisposableSymbols } from '@whatwg-node/disposablestack';
|
|
4
4
|
import { FormData, File, TextEncoder, crypto, TextDecoder, fetch } from '@whatwg-node/fetch';
|
|
5
|
+
import { isPromise, handleMaybePromise } from '@whatwg-node/promise-helpers';
|
|
5
6
|
import { ValueOrPromise } from 'value-or-promise';
|
|
6
7
|
import { extractFiles, isExtractableFile } from 'extract-files';
|
|
7
8
|
import { Repeater } from '@repeaterjs/repeater';
|
|
@@ -17,15 +18,18 @@ function collectAsyncIterableValues(asyncIterable) {
|
|
|
17
18
|
const values = [];
|
|
18
19
|
const iterator = asyncIterable[Symbol.asyncIterator]();
|
|
19
20
|
function iterate() {
|
|
20
|
-
return
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
return handleMaybePromise(
|
|
22
|
+
() => iterator.next(),
|
|
23
|
+
({ value, done }) => {
|
|
24
|
+
if (value != null) {
|
|
25
|
+
values.push(value);
|
|
26
|
+
}
|
|
27
|
+
if (done) {
|
|
28
|
+
return values;
|
|
29
|
+
}
|
|
30
|
+
return iterate();
|
|
26
31
|
}
|
|
27
|
-
|
|
28
|
-
});
|
|
32
|
+
);
|
|
29
33
|
}
|
|
30
34
|
return iterate();
|
|
31
35
|
}
|
|
@@ -65,15 +69,15 @@ function createFormDataFromVariables(body, {
|
|
|
65
69
|
function handleUpload(upload, i) {
|
|
66
70
|
const indexStr = i.toString();
|
|
67
71
|
if (upload != null) {
|
|
68
|
-
return
|
|
69
|
-
upload?.promise || upload,
|
|
72
|
+
return handleMaybePromise(
|
|
73
|
+
() => upload?.promise || upload,
|
|
70
74
|
(upload2) => {
|
|
71
75
|
const filename = upload2.filename || upload2.name || upload2.path || `blob-${indexStr}`;
|
|
72
76
|
if (isBlob(upload2)) {
|
|
73
77
|
form.append(indexStr, upload2, filename);
|
|
74
78
|
} else if (isAsyncIterable(upload2)) {
|
|
75
|
-
return
|
|
76
|
-
collectAsyncIterableValues(upload2),
|
|
79
|
+
return handleMaybePromise(
|
|
80
|
+
() => collectAsyncIterableValues(upload2),
|
|
77
81
|
(chunks) => {
|
|
78
82
|
const blobPart = new Uint8Array(chunks);
|
|
79
83
|
form.append(
|
|
@@ -84,8 +88,8 @@ function createFormDataFromVariables(body, {
|
|
|
84
88
|
}
|
|
85
89
|
);
|
|
86
90
|
} else if (isGraphQLUpload(upload2)) {
|
|
87
|
-
return
|
|
88
|
-
collectAsyncIterableValues(upload2.createReadStream()),
|
|
91
|
+
return handleMaybePromise(
|
|
92
|
+
() => collectAsyncIterableValues(upload2.createReadStream()),
|
|
89
93
|
(chunks) => {
|
|
90
94
|
const blobPart = new Uint8Array(chunks);
|
|
91
95
|
form.append(
|
|
@@ -149,8 +153,8 @@ function createResultForAbort(reason, extensions) {
|
|
|
149
153
|
function hashSHA256(str) {
|
|
150
154
|
const textEncoder = new TextEncoder();
|
|
151
155
|
const utf8 = textEncoder.encode(str);
|
|
152
|
-
return
|
|
153
|
-
crypto.subtle.digest("SHA-256", utf8),
|
|
156
|
+
return handleMaybePromise(
|
|
157
|
+
() => crypto.subtle.digest("SHA-256", utf8),
|
|
154
158
|
(hashBuffer) => {
|
|
155
159
|
let hashHex = "";
|
|
156
160
|
for (const bytes of new Uint8Array(hashBuffer)) {
|
|
@@ -354,25 +358,28 @@ function buildHTTPExecutor(options) {
|
|
|
354
358
|
};
|
|
355
359
|
if (options?.apq) {
|
|
356
360
|
serializeFn = function serializeWithAPQ() {
|
|
357
|
-
return
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
361
|
+
return handleMaybePromise(
|
|
362
|
+
() => hashSHA256(query),
|
|
363
|
+
(sha256Hash) => {
|
|
364
|
+
const extensions = request.extensions || {};
|
|
365
|
+
extensions["persistedQuery"] = {
|
|
366
|
+
version: 1,
|
|
367
|
+
sha256Hash
|
|
368
|
+
};
|
|
369
|
+
return serializeExecutionRequest({
|
|
370
|
+
executionRequest: {
|
|
371
|
+
...request,
|
|
372
|
+
extensions
|
|
373
|
+
},
|
|
374
|
+
excludeQuery,
|
|
375
|
+
printFn
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
);
|
|
372
379
|
};
|
|
373
380
|
}
|
|
374
|
-
return
|
|
375
|
-
serializeFn(),
|
|
381
|
+
return handleMaybePromise(
|
|
382
|
+
() => serializeFn(),
|
|
376
383
|
(body) => new ValueOrPromise(() => {
|
|
377
384
|
switch (method) {
|
|
378
385
|
case "GET": {
|
|
@@ -398,8 +405,8 @@ function buildHTTPExecutor(options) {
|
|
|
398
405
|
}
|
|
399
406
|
case "POST": {
|
|
400
407
|
upstreamErrorExtensions.request.body = body;
|
|
401
|
-
return
|
|
402
|
-
createFormDataFromVariables(body, {
|
|
408
|
+
return handleMaybePromise(
|
|
409
|
+
() => createFormDataFromVariables(body, {
|
|
403
410
|
File: options?.File,
|
|
404
411
|
FormData: options?.FormData
|
|
405
412
|
}),
|
|
@@ -534,8 +541,8 @@ function buildHTTPExecutor(options) {
|
|
|
534
541
|
let executor = baseExecutor;
|
|
535
542
|
if (options?.apq != null) {
|
|
536
543
|
executor = function apqExecutor(request) {
|
|
537
|
-
return
|
|
538
|
-
baseExecutor(request, true),
|
|
544
|
+
return handleMaybePromise(
|
|
545
|
+
() => baseExecutor(request, true),
|
|
539
546
|
(res) => {
|
|
540
547
|
if (res.errors?.some(
|
|
541
548
|
(error) => error.extensions["code"] === "PERSISTED_QUERY_NOT_FOUND" || error.message === "PersistedQueryNotFound"
|
|
@@ -565,13 +572,16 @@ function buildHTTPExecutor(options) {
|
|
|
565
572
|
errors: [createGraphQLError("No response returned from fetch")]
|
|
566
573
|
};
|
|
567
574
|
}
|
|
568
|
-
return
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
575
|
+
return handleMaybePromise(
|
|
576
|
+
() => prevExecutor(request),
|
|
577
|
+
(res) => {
|
|
578
|
+
result = res;
|
|
579
|
+
if (result?.errors?.length) {
|
|
580
|
+
return retryAttempt();
|
|
581
|
+
}
|
|
582
|
+
return result;
|
|
572
583
|
}
|
|
573
|
-
|
|
574
|
-
});
|
|
584
|
+
);
|
|
575
585
|
}
|
|
576
586
|
return retryAttempt();
|
|
577
587
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/executor-http",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.9-alpha-3b2000e3a6b9e871ed2700b7795f23d2a15358ce",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A set of utils for faster development of GraphQL tools",
|
|
6
6
|
"repository": {
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"@repeaterjs/repeater": "^3.0.4",
|
|
45
45
|
"@whatwg-node/disposablestack": "^0.0.5",
|
|
46
46
|
"@whatwg-node/fetch": "^0.10.4",
|
|
47
|
+
"@whatwg-node/promise-helpers": "^1.0.0",
|
|
47
48
|
"extract-files": "^11.0.0",
|
|
48
49
|
"meros": "^1.2.1",
|
|
49
50
|
"tslib": "^2.8.1",
|