@graphql-tools/batch-execute 9.0.16 → 9.0.17-alpha-4d5a0ca595853d5d8267c802036387b9c80e7af9
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 +6 -0
- package/dist/index.cjs +31 -35
- package/dist/index.js +33 -37
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @graphql-tools/batch-execute
|
|
2
2
|
|
|
3
|
+
## 9.0.17-alpha-4d5a0ca595853d5d8267c802036387b9c80e7af9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1134](https://github.com/graphql-hive/gateway/pull/1134) [`071d64e`](https://github.com/graphql-hive/gateway/commit/071d64e79465dc9de058cc16c99ec1a5472d2bc1) Thanks [@ardatan](https://github.com/ardatan)! - Small improvements on usage of promise helpers
|
|
8
|
+
|
|
3
9
|
## 9.0.16
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -238,18 +238,18 @@ function isFragmentDefinition(def) {
|
|
|
238
238
|
}
|
|
239
239
|
|
|
240
240
|
function splitResult({ data, errors }, numResults) {
|
|
241
|
-
const splitResults =
|
|
242
|
-
for (let i = 0; i < numResults; i++) {
|
|
243
|
-
splitResults.push({});
|
|
244
|
-
}
|
|
241
|
+
const splitResults = new Array(numResults);
|
|
245
242
|
if (data) {
|
|
246
243
|
for (const prefixedKey in data) {
|
|
247
244
|
const { index, originalKey } = parseKey(prefixedKey);
|
|
248
245
|
const result = splitResults[index];
|
|
249
246
|
if (result == null) {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
247
|
+
splitResults[index] = {
|
|
248
|
+
data: {
|
|
249
|
+
[originalKey]: data[prefixedKey]
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
} else if (result.data == null) {
|
|
253
253
|
result.data = { [originalKey]: data[prefixedKey] };
|
|
254
254
|
} else {
|
|
255
255
|
result.data[originalKey] = data[prefixedKey];
|
|
@@ -265,15 +265,28 @@ function splitResult({ data, errors }, numResults) {
|
|
|
265
265
|
...error.path.slice(keyOffset)
|
|
266
266
|
]);
|
|
267
267
|
const splittedResult = splitResults[index];
|
|
268
|
-
if (splittedResult) {
|
|
269
|
-
|
|
270
|
-
|
|
268
|
+
if (splittedResult == null) {
|
|
269
|
+
splitResults[index] = { errors: [newError] };
|
|
270
|
+
continue;
|
|
271
|
+
} else if (splittedResult.errors == null) {
|
|
272
|
+
splittedResult.errors = [newError];
|
|
273
|
+
continue;
|
|
274
|
+
} else {
|
|
275
|
+
splittedResult.errors.push(newError);
|
|
271
276
|
}
|
|
272
277
|
} else {
|
|
273
|
-
|
|
274
|
-
const
|
|
275
|
-
|
|
276
|
-
|
|
278
|
+
for (let i = 0; i < numResults; i++) {
|
|
279
|
+
const splittedResult = splitResults[i];
|
|
280
|
+
if (splittedResult == null) {
|
|
281
|
+
splitResults[i] = { errors: [error] };
|
|
282
|
+
continue;
|
|
283
|
+
} else if (splittedResult.errors == null) {
|
|
284
|
+
splittedResult.errors = [error];
|
|
285
|
+
continue;
|
|
286
|
+
} else {
|
|
287
|
+
splittedResult.errors.push(error);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
277
290
|
}
|
|
278
291
|
}
|
|
279
292
|
}
|
|
@@ -302,29 +315,12 @@ function createLoadFn(executor, extensionsReducer) {
|
|
|
302
315
|
return function batchExecuteLoadFn(requests) {
|
|
303
316
|
if (requests.length === 1 && requests[0]) {
|
|
304
317
|
const request = requests[0];
|
|
305
|
-
return promiseHelpers.fakePromise(
|
|
306
|
-
promiseHelpers.handleMaybePromise(
|
|
307
|
-
() => executor(request),
|
|
308
|
-
(result) => [result],
|
|
309
|
-
(err) => [err]
|
|
310
|
-
)
|
|
311
|
-
);
|
|
318
|
+
return promiseHelpers.fakePromise().then(() => executor(request)).catch((err) => err).then((res) => [res]);
|
|
312
319
|
}
|
|
313
320
|
const mergedRequests = mergeRequests(requests, extensionsReducer);
|
|
314
|
-
return promiseHelpers.fakePromise(
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
(resultBatches) => {
|
|
318
|
-
if (utils.isAsyncIterable(resultBatches)) {
|
|
319
|
-
throw new Error(
|
|
320
|
-
"Executor must not return incremental results for batching"
|
|
321
|
-
);
|
|
322
|
-
}
|
|
323
|
-
return splitResult(resultBatches, requests.length);
|
|
324
|
-
},
|
|
325
|
-
(err) => requests.map(() => err)
|
|
326
|
-
)
|
|
327
|
-
);
|
|
321
|
+
return promiseHelpers.fakePromise().then(() => executor(mergedRequests)).then(
|
|
322
|
+
(resultBatches) => splitResult(resultBatches, requests.length)
|
|
323
|
+
).catch((err) => requests.map(() => err));
|
|
328
324
|
};
|
|
329
325
|
}
|
|
330
326
|
function defaultExtensionsReducer(mergedExtensions, request) {
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getOperationASTFromRequest, relocatedError,
|
|
2
|
-
import { fakePromise
|
|
1
|
+
import { getOperationASTFromRequest, relocatedError, memoize2of4 } from '@graphql-tools/utils';
|
|
2
|
+
import { fakePromise } from '@whatwg-node/promise-helpers';
|
|
3
3
|
import DataLoader from 'dataloader';
|
|
4
4
|
import { Kind, visit } from 'graphql';
|
|
5
5
|
|
|
@@ -232,18 +232,18 @@ function isFragmentDefinition(def) {
|
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
function splitResult({ data, errors }, numResults) {
|
|
235
|
-
const splitResults =
|
|
236
|
-
for (let i = 0; i < numResults; i++) {
|
|
237
|
-
splitResults.push({});
|
|
238
|
-
}
|
|
235
|
+
const splitResults = new Array(numResults);
|
|
239
236
|
if (data) {
|
|
240
237
|
for (const prefixedKey in data) {
|
|
241
238
|
const { index, originalKey } = parseKey(prefixedKey);
|
|
242
239
|
const result = splitResults[index];
|
|
243
240
|
if (result == null) {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
241
|
+
splitResults[index] = {
|
|
242
|
+
data: {
|
|
243
|
+
[originalKey]: data[prefixedKey]
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
} else if (result.data == null) {
|
|
247
247
|
result.data = { [originalKey]: data[prefixedKey] };
|
|
248
248
|
} else {
|
|
249
249
|
result.data[originalKey] = data[prefixedKey];
|
|
@@ -259,15 +259,28 @@ function splitResult({ data, errors }, numResults) {
|
|
|
259
259
|
...error.path.slice(keyOffset)
|
|
260
260
|
]);
|
|
261
261
|
const splittedResult = splitResults[index];
|
|
262
|
-
if (splittedResult) {
|
|
263
|
-
|
|
264
|
-
|
|
262
|
+
if (splittedResult == null) {
|
|
263
|
+
splitResults[index] = { errors: [newError] };
|
|
264
|
+
continue;
|
|
265
|
+
} else if (splittedResult.errors == null) {
|
|
266
|
+
splittedResult.errors = [newError];
|
|
267
|
+
continue;
|
|
268
|
+
} else {
|
|
269
|
+
splittedResult.errors.push(newError);
|
|
265
270
|
}
|
|
266
271
|
} else {
|
|
267
|
-
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
|
|
272
|
+
for (let i = 0; i < numResults; i++) {
|
|
273
|
+
const splittedResult = splitResults[i];
|
|
274
|
+
if (splittedResult == null) {
|
|
275
|
+
splitResults[i] = { errors: [error] };
|
|
276
|
+
continue;
|
|
277
|
+
} else if (splittedResult.errors == null) {
|
|
278
|
+
splittedResult.errors = [error];
|
|
279
|
+
continue;
|
|
280
|
+
} else {
|
|
281
|
+
splittedResult.errors.push(error);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
271
284
|
}
|
|
272
285
|
}
|
|
273
286
|
}
|
|
@@ -296,29 +309,12 @@ function createLoadFn(executor, extensionsReducer) {
|
|
|
296
309
|
return function batchExecuteLoadFn(requests) {
|
|
297
310
|
if (requests.length === 1 && requests[0]) {
|
|
298
311
|
const request = requests[0];
|
|
299
|
-
return fakePromise(
|
|
300
|
-
handleMaybePromise(
|
|
301
|
-
() => executor(request),
|
|
302
|
-
(result) => [result],
|
|
303
|
-
(err) => [err]
|
|
304
|
-
)
|
|
305
|
-
);
|
|
312
|
+
return fakePromise().then(() => executor(request)).catch((err) => err).then((res) => [res]);
|
|
306
313
|
}
|
|
307
314
|
const mergedRequests = mergeRequests(requests, extensionsReducer);
|
|
308
|
-
return fakePromise(
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
(resultBatches) => {
|
|
312
|
-
if (isAsyncIterable(resultBatches)) {
|
|
313
|
-
throw new Error(
|
|
314
|
-
"Executor must not return incremental results for batching"
|
|
315
|
-
);
|
|
316
|
-
}
|
|
317
|
-
return splitResult(resultBatches, requests.length);
|
|
318
|
-
},
|
|
319
|
-
(err) => requests.map(() => err)
|
|
320
|
-
)
|
|
321
|
-
);
|
|
315
|
+
return fakePromise().then(() => executor(mergedRequests)).then(
|
|
316
|
+
(resultBatches) => splitResult(resultBatches, requests.length)
|
|
317
|
+
).catch((err) => requests.map(() => err));
|
|
322
318
|
};
|
|
323
319
|
}
|
|
324
320
|
function defaultExtensionsReducer(mergedExtensions, request) {
|
package/package.json
CHANGED