@graphql-tools/executor-http 1.1.12 → 1.1.13-alpha-2c5a1206ce55aeec957970191cd912d09d901867

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @graphql-tools/executor-http
2
2
 
3
+ ## 1.1.13-alpha-2c5a1206ce55aeec957970191cd912d09d901867
4
+
5
+ ### Patch Changes
6
+
7
+ - [#274](https://github.com/graphql-hive/gateway/pull/274) [`2c5a120`](https://github.com/graphql-hive/gateway/commit/2c5a1206ce55aeec957970191cd912d09d901867) Thanks [@ardatan](https://github.com/ardatan)! - Improve multipart support
8
+
3
9
  ## 1.1.12
4
10
 
5
11
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -14,6 +14,22 @@ function isGraphQLUpload(upload) {
14
14
  return typeof upload.createReadStream === "function";
15
15
  }
16
16
 
17
+ function collectAsyncIterableValues(asyncIterable) {
18
+ const values = [];
19
+ const iterator = asyncIterable[Symbol.asyncIterator]();
20
+ function iterate() {
21
+ return utils.mapMaybePromise(iterator.next(), ({ value, done }) => {
22
+ if (value != null) {
23
+ values.push(value);
24
+ }
25
+ if (done) {
26
+ return values;
27
+ }
28
+ return iterate();
29
+ });
30
+ }
31
+ return iterate();
32
+ }
17
33
  function createFormDataFromVariables({
18
34
  query,
19
35
  variables,
@@ -63,32 +79,38 @@ function createFormDataFromVariables({
63
79
  function handleUpload(upload, i) {
64
80
  const indexStr = i.toString();
65
81
  if (upload != null) {
66
- const filename = upload.filename || upload.name || upload.path || `blob-${indexStr}`;
67
- if (utils.isPromise(upload)) {
68
- return upload.then(
69
- (resolvedUpload) => handleUpload(resolvedUpload, i)
70
- );
71
- } else if (isBlob(upload)) {
72
- form.append(indexStr, upload, filename);
73
- } else if (isGraphQLUpload(upload)) {
74
- const stream = upload.createReadStream();
75
- const chunks = [];
76
- return utils.fakePromise(void 0).then(async () => {
77
- for await (const chunk of stream) {
78
- if (chunk) {
79
- chunks.push(...chunk);
82
+ return utils.mapMaybePromise(upload?.promise || upload, (upload2) => {
83
+ const filename = upload2.filename || upload2.name || upload2.path || `blob-${indexStr}`;
84
+ if (isBlob(upload2)) {
85
+ form.append(indexStr, upload2, filename);
86
+ } else if (utils.isAsyncIterable(upload2)) {
87
+ return utils.mapMaybePromise(
88
+ collectAsyncIterableValues(upload2),
89
+ (chunks) => {
90
+ const blobPart = new Uint8Array(chunks);
91
+ form.append(
92
+ indexStr,
93
+ new FileCtor([blobPart], filename),
94
+ filename
95
+ );
80
96
  }
81
- }
82
- const blobPart = new Uint8Array(chunks);
83
- form.append(
84
- indexStr,
85
- new FileCtor([blobPart], filename, { type: upload.mimetype }),
86
- filename
87
97
  );
88
- });
89
- } else {
90
- form.append(indexStr, new FileCtor([upload], filename), filename);
91
- }
98
+ } else if (isGraphQLUpload(upload2)) {
99
+ return utils.mapMaybePromise(
100
+ collectAsyncIterableValues(upload2.createReadStream()),
101
+ (chunks) => {
102
+ const blobPart = new Uint8Array(chunks);
103
+ form.append(
104
+ indexStr,
105
+ new FileCtor([blobPart], filename, { type: upload2.mimetype }),
106
+ filename
107
+ );
108
+ }
109
+ );
110
+ } else {
111
+ form.append(indexStr, new FileCtor([upload2], filename), filename);
112
+ }
113
+ });
92
114
  }
93
115
  }
94
116
  const jobs = [];
@@ -108,15 +130,9 @@ function isBlob(obj) {
108
130
  return typeof obj.arrayBuffer === "function";
109
131
  }
110
132
 
111
- const printCache = /* @__PURE__ */ new WeakMap();
112
- function defaultPrintFn(document) {
113
- let printed = printCache.get(document);
114
- if (!printed) {
115
- printed = graphql.stripIgnoredCharacters(graphql.print(document));
116
- printCache.set(document, printed);
117
- }
118
- return printed;
119
- }
133
+ const defaultPrintFn = utils.memoize1(function defaultPrintFn2(document) {
134
+ return graphql.stripIgnoredCharacters(graphql.print(document));
135
+ });
120
136
 
121
137
  function createAbortErrorReason() {
122
138
  return new Error("Executor was disposed.");
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { isAsyncIterable, isPromise, fakePromise, createGraphQLError, inspect, mapAsyncIterator, mergeIncrementalResult, memoize1, getOperationASTFromRequest, mapMaybePromise } from '@graphql-tools/utils';
1
+ import { isAsyncIterable, isPromise, mapMaybePromise, memoize1, createGraphQLError, inspect, mapAsyncIterator, mergeIncrementalResult, getOperationASTFromRequest } from '@graphql-tools/utils';
2
2
  import { DisposableSymbols } from '@whatwg-node/disposablestack';
3
3
  import { File, FormData, TextDecoder, fetch } from '@whatwg-node/fetch';
4
4
  import { ValueOrPromise } from 'value-or-promise';
@@ -12,6 +12,22 @@ function isGraphQLUpload(upload) {
12
12
  return typeof upload.createReadStream === "function";
13
13
  }
14
14
 
15
+ function collectAsyncIterableValues(asyncIterable) {
16
+ const values = [];
17
+ const iterator = asyncIterable[Symbol.asyncIterator]();
18
+ function iterate() {
19
+ return mapMaybePromise(iterator.next(), ({ value, done }) => {
20
+ if (value != null) {
21
+ values.push(value);
22
+ }
23
+ if (done) {
24
+ return values;
25
+ }
26
+ return iterate();
27
+ });
28
+ }
29
+ return iterate();
30
+ }
15
31
  function createFormDataFromVariables({
16
32
  query,
17
33
  variables,
@@ -61,32 +77,38 @@ function createFormDataFromVariables({
61
77
  function handleUpload(upload, i) {
62
78
  const indexStr = i.toString();
63
79
  if (upload != null) {
64
- const filename = upload.filename || upload.name || upload.path || `blob-${indexStr}`;
65
- if (isPromise(upload)) {
66
- return upload.then(
67
- (resolvedUpload) => handleUpload(resolvedUpload, i)
68
- );
69
- } else if (isBlob(upload)) {
70
- form.append(indexStr, upload, filename);
71
- } else if (isGraphQLUpload(upload)) {
72
- const stream = upload.createReadStream();
73
- const chunks = [];
74
- return fakePromise(void 0).then(async () => {
75
- for await (const chunk of stream) {
76
- if (chunk) {
77
- chunks.push(...chunk);
80
+ return mapMaybePromise(upload?.promise || upload, (upload2) => {
81
+ const filename = upload2.filename || upload2.name || upload2.path || `blob-${indexStr}`;
82
+ if (isBlob(upload2)) {
83
+ form.append(indexStr, upload2, filename);
84
+ } else if (isAsyncIterable(upload2)) {
85
+ return mapMaybePromise(
86
+ collectAsyncIterableValues(upload2),
87
+ (chunks) => {
88
+ const blobPart = new Uint8Array(chunks);
89
+ form.append(
90
+ indexStr,
91
+ new FileCtor([blobPart], filename),
92
+ filename
93
+ );
78
94
  }
79
- }
80
- const blobPart = new Uint8Array(chunks);
81
- form.append(
82
- indexStr,
83
- new FileCtor([blobPart], filename, { type: upload.mimetype }),
84
- filename
85
95
  );
86
- });
87
- } else {
88
- form.append(indexStr, new FileCtor([upload], filename), filename);
89
- }
96
+ } else if (isGraphQLUpload(upload2)) {
97
+ return mapMaybePromise(
98
+ collectAsyncIterableValues(upload2.createReadStream()),
99
+ (chunks) => {
100
+ const blobPart = new Uint8Array(chunks);
101
+ form.append(
102
+ indexStr,
103
+ new FileCtor([blobPart], filename, { type: upload2.mimetype }),
104
+ filename
105
+ );
106
+ }
107
+ );
108
+ } else {
109
+ form.append(indexStr, new FileCtor([upload2], filename), filename);
110
+ }
111
+ });
90
112
  }
91
113
  }
92
114
  const jobs = [];
@@ -106,15 +128,9 @@ function isBlob(obj) {
106
128
  return typeof obj.arrayBuffer === "function";
107
129
  }
108
130
 
109
- const printCache = /* @__PURE__ */ new WeakMap();
110
- function defaultPrintFn(document) {
111
- let printed = printCache.get(document);
112
- if (!printed) {
113
- printed = stripIgnoredCharacters(print(document));
114
- printCache.set(document, printed);
115
- }
116
- return printed;
117
- }
131
+ const defaultPrintFn = memoize1(function defaultPrintFn2(document) {
132
+ return stripIgnoredCharacters(print(document));
133
+ });
118
134
 
119
135
  function createAbortErrorReason() {
120
136
  return new Error("Executor was disposed.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/executor-http",
3
- "version": "1.1.12",
3
+ "version": "1.1.13-alpha-2c5a1206ce55aeec957970191cd912d09d901867",
4
4
  "type": "module",
5
5
  "description": "A set of utils for faster development of GraphQL tools",
6
6
  "repository": {