@graphql-tools/batch-execute 8.0.0-alpha-fa9b61b3.0 → 8.0.2
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/README.md +2 -1
- package/es5/README.md +2 -1
- package/es5/index.js +72 -49
- package/es5/index.mjs +72 -49
- package/es5/package.json +2 -2
- package/index.js +22 -22
- package/index.mjs +22 -22
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
Check API Reference for more information about this package;
|
|
2
|
-
https://www.graphql-tools.com/docs/api/modules/
|
|
2
|
+
https://www.graphql-tools.com/docs/api/modules/batch_execute_src
|
|
3
3
|
|
|
4
4
|
You can also learn more about Batch Delegation in this chapter;
|
|
5
5
|
https://www.graphql-tools.com/docs/stitch-schema-extensions#batch-delegation
|
|
6
|
+
|
package/es5/README.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
Check API Reference for more information about this package;
|
|
2
|
-
https://www.graphql-tools.com/docs/api/modules/
|
|
2
|
+
https://www.graphql-tools.com/docs/api/modules/batch_execute_src
|
|
3
3
|
|
|
4
4
|
You can also learn more about Batch Delegation in this chapter;
|
|
5
5
|
https://www.graphql-tools.com/docs/stitch-schema-extensions#batch-delegation
|
|
6
|
+
|
package/es5/index.js
CHANGED
|
@@ -6,7 +6,6 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
|
|
|
6
6
|
|
|
7
7
|
const tslib = require('tslib');
|
|
8
8
|
const DataLoader = _interopDefault(require('dataloader'));
|
|
9
|
-
const valueOrPromise = require('value-or-promise');
|
|
10
9
|
const graphql = require('graphql');
|
|
11
10
|
const utils = require('@graphql-tools/utils/es5');
|
|
12
11
|
|
|
@@ -113,25 +112,37 @@ function mergeRequests(requests, extensionsReducer) {
|
|
|
113
112
|
};
|
|
114
113
|
}
|
|
115
114
|
function prefixRequest(prefix, request) {
|
|
116
|
-
var _a;
|
|
117
|
-
var
|
|
118
|
-
var
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
115
|
+
var _a, e_2, _b;
|
|
116
|
+
var _c;
|
|
117
|
+
var executionVariables = (_c = request.variables) !== null && _c !== void 0 ? _c : {};
|
|
118
|
+
function prefixNode(node) {
|
|
119
|
+
return prefixNodeName(node, prefix);
|
|
120
|
+
}
|
|
121
|
+
var prefixedDocument = aliasTopLevelFields(prefix, request.document);
|
|
122
|
+
var executionVariableNames = Object.keys(executionVariables);
|
|
123
|
+
if (executionVariableNames.length > 0) {
|
|
124
|
+
prefixedDocument = graphql.visit(prefixedDocument, (_a = {},
|
|
125
|
+
_a[graphql.Kind.VARIABLE] = prefixNode,
|
|
126
|
+
_a[graphql.Kind.FRAGMENT_DEFINITION] = prefixNode,
|
|
127
|
+
_a[graphql.Kind.FRAGMENT_SPREAD] = prefixNode,
|
|
128
|
+
_a));
|
|
129
|
+
}
|
|
130
|
+
var prefixedVariables = {};
|
|
131
|
+
try {
|
|
132
|
+
for (var executionVariableNames_1 = tslib.__values(executionVariableNames), executionVariableNames_1_1 = executionVariableNames_1.next(); !executionVariableNames_1_1.done; executionVariableNames_1_1 = executionVariableNames_1.next()) {
|
|
133
|
+
var variableName = executionVariableNames_1_1.value;
|
|
134
|
+
prefixedVariables[prefix + variableName] = executionVariables[variableName];
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
138
|
+
finally {
|
|
139
|
+
try {
|
|
140
|
+
if (executionVariableNames_1_1 && !executionVariableNames_1_1.done && (_b = executionVariableNames_1.return)) _b.call(executionVariableNames_1);
|
|
141
|
+
}
|
|
142
|
+
finally { if (e_2) throw e_2.error; }
|
|
123
143
|
}
|
|
124
|
-
document = graphql.visit(document, (_a = {},
|
|
125
|
-
_a[graphql.Kind.VARIABLE] = function (node) { return prefixNodeName(node, prefix); },
|
|
126
|
-
_a[graphql.Kind.FRAGMENT_DEFINITION] = function (node) { return prefixNodeName(node, prefix); },
|
|
127
|
-
_a[graphql.Kind.FRAGMENT_SPREAD] = function (node) { return prefixNodeName(node, prefix); },
|
|
128
|
-
_a));
|
|
129
|
-
var prefixedVariables = variableNames.reduce(function (acc, name) {
|
|
130
|
-
acc[prefix + name] = executionVariables[name];
|
|
131
|
-
return acc;
|
|
132
|
-
}, Object.create(null));
|
|
133
144
|
return {
|
|
134
|
-
document:
|
|
145
|
+
document: prefixedDocument,
|
|
135
146
|
variables: prefixedVariables,
|
|
136
147
|
operationType: request.operationType,
|
|
137
148
|
};
|
|
@@ -303,40 +314,52 @@ function createBatchingExecutor(executor, dataLoaderOptions, extensionsReducer)
|
|
|
303
314
|
};
|
|
304
315
|
}
|
|
305
316
|
function createLoadFn(executor, extensionsReducer) {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
317
|
+
return function batchExecuteLoadFn(requests) {
|
|
318
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
319
|
+
var execBatches, index, request, currentBatch, operationType, currentOperationType, results;
|
|
320
|
+
var _this = this;
|
|
321
|
+
return tslib.__generator(this, function (_a) {
|
|
322
|
+
switch (_a.label) {
|
|
323
|
+
case 0:
|
|
324
|
+
execBatches = [];
|
|
325
|
+
index = 0;
|
|
326
|
+
request = requests[index];
|
|
327
|
+
currentBatch = [request];
|
|
328
|
+
execBatches.push(currentBatch);
|
|
329
|
+
operationType = request.operationType;
|
|
330
|
+
while (++index < requests.length) {
|
|
331
|
+
currentOperationType = requests[index].operationType;
|
|
332
|
+
if (operationType == null) {
|
|
333
|
+
throw new Error('Could not identify operation type of document.');
|
|
334
|
+
}
|
|
335
|
+
if (operationType === currentOperationType) {
|
|
336
|
+
currentBatch.push(requests[index]);
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
currentBatch = [requests[index]];
|
|
340
|
+
execBatches.push(currentBatch);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return [4 /*yield*/, Promise.all(execBatches.map(function (execBatch) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
344
|
+
var mergedRequests, resultBatches;
|
|
345
|
+
return tslib.__generator(this, function (_a) {
|
|
346
|
+
switch (_a.label) {
|
|
347
|
+
case 0:
|
|
348
|
+
mergedRequests = mergeRequests(execBatch, extensionsReducer);
|
|
349
|
+
return [4 /*yield*/, executor(mergedRequests)];
|
|
350
|
+
case 1:
|
|
351
|
+
resultBatches = (_a.sent());
|
|
352
|
+
return [2 /*return*/, splitResult(resultBatches, execBatch.length)];
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
}); }))];
|
|
356
|
+
case 1:
|
|
357
|
+
results = _a.sent();
|
|
358
|
+
return [2 /*return*/, results.flat()];
|
|
327
359
|
}
|
|
328
|
-
}
|
|
329
|
-
executionResults = execBatches.map(function (execBatch) {
|
|
330
|
-
var mergedRequests = mergeRequests(execBatch, extensionsReducer);
|
|
331
|
-
return new valueOrPromise.ValueOrPromise(function () { return executor(mergedRequests); });
|
|
332
360
|
});
|
|
333
|
-
return [2 /*return*/, valueOrPromise.ValueOrPromise.all(executionResults)
|
|
334
|
-
.then(function (resultBatches) {
|
|
335
|
-
return resultBatches.reduce(function (results, resultBatch, index) { return results.concat(splitResult(resultBatch, execBatches[index].length)); }, new Array());
|
|
336
|
-
})
|
|
337
|
-
.resolve()];
|
|
338
361
|
});
|
|
339
|
-
}
|
|
362
|
+
};
|
|
340
363
|
}
|
|
341
364
|
function defaultExtensionsReducer(mergedExtensions, request) {
|
|
342
365
|
var newExtensions = request.extensions;
|
package/es5/index.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { __spreadArray, __read, __values, __assign, __awaiter, __generator } from 'tslib';
|
|
2
2
|
import DataLoader from 'dataloader';
|
|
3
|
-
import { ValueOrPromise } from 'value-or-promise';
|
|
4
3
|
import { Kind, visit } from 'graphql';
|
|
5
4
|
import { relocatedError } from '@graphql-tools/utils/es5';
|
|
6
5
|
|
|
@@ -107,25 +106,37 @@ function mergeRequests(requests, extensionsReducer) {
|
|
|
107
106
|
};
|
|
108
107
|
}
|
|
109
108
|
function prefixRequest(prefix, request) {
|
|
110
|
-
var _a;
|
|
111
|
-
var
|
|
112
|
-
var
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
109
|
+
var _a, e_2, _b;
|
|
110
|
+
var _c;
|
|
111
|
+
var executionVariables = (_c = request.variables) !== null && _c !== void 0 ? _c : {};
|
|
112
|
+
function prefixNode(node) {
|
|
113
|
+
return prefixNodeName(node, prefix);
|
|
114
|
+
}
|
|
115
|
+
var prefixedDocument = aliasTopLevelFields(prefix, request.document);
|
|
116
|
+
var executionVariableNames = Object.keys(executionVariables);
|
|
117
|
+
if (executionVariableNames.length > 0) {
|
|
118
|
+
prefixedDocument = visit(prefixedDocument, (_a = {},
|
|
119
|
+
_a[Kind.VARIABLE] = prefixNode,
|
|
120
|
+
_a[Kind.FRAGMENT_DEFINITION] = prefixNode,
|
|
121
|
+
_a[Kind.FRAGMENT_SPREAD] = prefixNode,
|
|
122
|
+
_a));
|
|
123
|
+
}
|
|
124
|
+
var prefixedVariables = {};
|
|
125
|
+
try {
|
|
126
|
+
for (var executionVariableNames_1 = __values(executionVariableNames), executionVariableNames_1_1 = executionVariableNames_1.next(); !executionVariableNames_1_1.done; executionVariableNames_1_1 = executionVariableNames_1.next()) {
|
|
127
|
+
var variableName = executionVariableNames_1_1.value;
|
|
128
|
+
prefixedVariables[prefix + variableName] = executionVariables[variableName];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
132
|
+
finally {
|
|
133
|
+
try {
|
|
134
|
+
if (executionVariableNames_1_1 && !executionVariableNames_1_1.done && (_b = executionVariableNames_1.return)) _b.call(executionVariableNames_1);
|
|
135
|
+
}
|
|
136
|
+
finally { if (e_2) throw e_2.error; }
|
|
117
137
|
}
|
|
118
|
-
document = visit(document, (_a = {},
|
|
119
|
-
_a[Kind.VARIABLE] = function (node) { return prefixNodeName(node, prefix); },
|
|
120
|
-
_a[Kind.FRAGMENT_DEFINITION] = function (node) { return prefixNodeName(node, prefix); },
|
|
121
|
-
_a[Kind.FRAGMENT_SPREAD] = function (node) { return prefixNodeName(node, prefix); },
|
|
122
|
-
_a));
|
|
123
|
-
var prefixedVariables = variableNames.reduce(function (acc, name) {
|
|
124
|
-
acc[prefix + name] = executionVariables[name];
|
|
125
|
-
return acc;
|
|
126
|
-
}, Object.create(null));
|
|
127
138
|
return {
|
|
128
|
-
document:
|
|
139
|
+
document: prefixedDocument,
|
|
129
140
|
variables: prefixedVariables,
|
|
130
141
|
operationType: request.operationType,
|
|
131
142
|
};
|
|
@@ -297,40 +308,52 @@ function createBatchingExecutor(executor, dataLoaderOptions, extensionsReducer)
|
|
|
297
308
|
};
|
|
298
309
|
}
|
|
299
310
|
function createLoadFn(executor, extensionsReducer) {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
311
|
+
return function batchExecuteLoadFn(requests) {
|
|
312
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
313
|
+
var execBatches, index, request, currentBatch, operationType, currentOperationType, results;
|
|
314
|
+
var _this = this;
|
|
315
|
+
return __generator(this, function (_a) {
|
|
316
|
+
switch (_a.label) {
|
|
317
|
+
case 0:
|
|
318
|
+
execBatches = [];
|
|
319
|
+
index = 0;
|
|
320
|
+
request = requests[index];
|
|
321
|
+
currentBatch = [request];
|
|
322
|
+
execBatches.push(currentBatch);
|
|
323
|
+
operationType = request.operationType;
|
|
324
|
+
while (++index < requests.length) {
|
|
325
|
+
currentOperationType = requests[index].operationType;
|
|
326
|
+
if (operationType == null) {
|
|
327
|
+
throw new Error('Could not identify operation type of document.');
|
|
328
|
+
}
|
|
329
|
+
if (operationType === currentOperationType) {
|
|
330
|
+
currentBatch.push(requests[index]);
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
currentBatch = [requests[index]];
|
|
334
|
+
execBatches.push(currentBatch);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return [4 /*yield*/, Promise.all(execBatches.map(function (execBatch) { return __awaiter(_this, void 0, void 0, function () {
|
|
338
|
+
var mergedRequests, resultBatches;
|
|
339
|
+
return __generator(this, function (_a) {
|
|
340
|
+
switch (_a.label) {
|
|
341
|
+
case 0:
|
|
342
|
+
mergedRequests = mergeRequests(execBatch, extensionsReducer);
|
|
343
|
+
return [4 /*yield*/, executor(mergedRequests)];
|
|
344
|
+
case 1:
|
|
345
|
+
resultBatches = (_a.sent());
|
|
346
|
+
return [2 /*return*/, splitResult(resultBatches, execBatch.length)];
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
}); }))];
|
|
350
|
+
case 1:
|
|
351
|
+
results = _a.sent();
|
|
352
|
+
return [2 /*return*/, results.flat()];
|
|
321
353
|
}
|
|
322
|
-
}
|
|
323
|
-
executionResults = execBatches.map(function (execBatch) {
|
|
324
|
-
var mergedRequests = mergeRequests(execBatch, extensionsReducer);
|
|
325
|
-
return new ValueOrPromise(function () { return executor(mergedRequests); });
|
|
326
354
|
});
|
|
327
|
-
return [2 /*return*/, ValueOrPromise.all(executionResults)
|
|
328
|
-
.then(function (resultBatches) {
|
|
329
|
-
return resultBatches.reduce(function (results, resultBatch, index) { return results.concat(splitResult(resultBatch, execBatches[index].length)); }, new Array());
|
|
330
|
-
})
|
|
331
|
-
.resolve()];
|
|
332
355
|
});
|
|
333
|
-
}
|
|
356
|
+
};
|
|
334
357
|
}
|
|
335
358
|
function defaultExtensionsReducer(mergedExtensions, request) {
|
|
336
359
|
var newExtensions = request.extensions;
|
package/es5/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/batch-execute/es5",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.2",
|
|
4
4
|
"description": "A set of utils for faster development of GraphQL tools",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"graphql": "^14.0.0 || ^15.0.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@graphql-tools/utils": "8.0.
|
|
10
|
+
"@graphql-tools/utils": "8.0.2",
|
|
11
11
|
"dataloader": "2.0.0",
|
|
12
12
|
"tslib": "~2.3.0",
|
|
13
13
|
"value-or-promise": "1.0.10"
|
package/index.js
CHANGED
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
6
|
|
|
7
7
|
const DataLoader = _interopDefault(require('dataloader'));
|
|
8
|
-
const valueOrPromise = require('value-or-promise');
|
|
9
8
|
const graphql = require('graphql');
|
|
10
9
|
const utils = require('@graphql-tools/utils');
|
|
11
10
|
|
|
@@ -102,23 +101,25 @@ function mergeRequests(requests, extensionsReducer) {
|
|
|
102
101
|
}
|
|
103
102
|
function prefixRequest(prefix, request) {
|
|
104
103
|
var _a;
|
|
105
|
-
let document = aliasTopLevelFields(prefix, request.document);
|
|
106
104
|
const executionVariables = (_a = request.variables) !== null && _a !== void 0 ? _a : {};
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
105
|
+
function prefixNode(node) {
|
|
106
|
+
return prefixNodeName(node, prefix);
|
|
107
|
+
}
|
|
108
|
+
let prefixedDocument = aliasTopLevelFields(prefix, request.document);
|
|
109
|
+
const executionVariableNames = Object.keys(executionVariables);
|
|
110
|
+
if (executionVariableNames.length > 0) {
|
|
111
|
+
prefixedDocument = graphql.visit(prefixedDocument, {
|
|
112
|
+
[graphql.Kind.VARIABLE]: prefixNode,
|
|
113
|
+
[graphql.Kind.FRAGMENT_DEFINITION]: prefixNode,
|
|
114
|
+
[graphql.Kind.FRAGMENT_SPREAD]: prefixNode,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
const prefixedVariables = {};
|
|
118
|
+
for (const variableName of executionVariableNames) {
|
|
119
|
+
prefixedVariables[prefix + variableName] = executionVariables[variableName];
|
|
110
120
|
}
|
|
111
|
-
document = graphql.visit(document, {
|
|
112
|
-
[graphql.Kind.VARIABLE]: (node) => prefixNodeName(node, prefix),
|
|
113
|
-
[graphql.Kind.FRAGMENT_DEFINITION]: (node) => prefixNodeName(node, prefix),
|
|
114
|
-
[graphql.Kind.FRAGMENT_SPREAD]: (node) => prefixNodeName(node, prefix),
|
|
115
|
-
});
|
|
116
|
-
const prefixedVariables = variableNames.reduce((acc, name) => {
|
|
117
|
-
acc[prefix + name] = executionVariables[name];
|
|
118
|
-
return acc;
|
|
119
|
-
}, Object.create(null));
|
|
120
121
|
return {
|
|
121
|
-
document,
|
|
122
|
+
document: prefixedDocument,
|
|
122
123
|
variables: prefixedVariables,
|
|
123
124
|
operationType: request.operationType,
|
|
124
125
|
};
|
|
@@ -300,7 +301,7 @@ function createBatchingExecutor(executor, dataLoaderOptions, extensionsReducer =
|
|
|
300
301
|
};
|
|
301
302
|
}
|
|
302
303
|
function createLoadFn(executor, extensionsReducer) {
|
|
303
|
-
return async (requests)
|
|
304
|
+
return async function batchExecuteLoadFn(requests) {
|
|
304
305
|
const execBatches = [];
|
|
305
306
|
let index = 0;
|
|
306
307
|
const request = requests[index];
|
|
@@ -320,13 +321,12 @@ function createLoadFn(executor, extensionsReducer) {
|
|
|
320
321
|
execBatches.push(currentBatch);
|
|
321
322
|
}
|
|
322
323
|
}
|
|
323
|
-
const
|
|
324
|
+
const results = await Promise.all(execBatches.map(async (execBatch) => {
|
|
324
325
|
const mergedRequests = mergeRequests(execBatch, extensionsReducer);
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
.resolve();
|
|
326
|
+
const resultBatches = (await executor(mergedRequests));
|
|
327
|
+
return splitResult(resultBatches, execBatch.length);
|
|
328
|
+
}));
|
|
329
|
+
return results.flat();
|
|
330
330
|
};
|
|
331
331
|
}
|
|
332
332
|
function defaultExtensionsReducer(mergedExtensions, request) {
|
package/index.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import DataLoader from 'dataloader';
|
|
2
|
-
import { ValueOrPromise } from 'value-or-promise';
|
|
3
2
|
import { Kind, visit } from 'graphql';
|
|
4
3
|
import { relocatedError } from '@graphql-tools/utils';
|
|
5
4
|
|
|
@@ -96,23 +95,25 @@ function mergeRequests(requests, extensionsReducer) {
|
|
|
96
95
|
}
|
|
97
96
|
function prefixRequest(prefix, request) {
|
|
98
97
|
var _a;
|
|
99
|
-
let document = aliasTopLevelFields(prefix, request.document);
|
|
100
98
|
const executionVariables = (_a = request.variables) !== null && _a !== void 0 ? _a : {};
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
function prefixNode(node) {
|
|
100
|
+
return prefixNodeName(node, prefix);
|
|
101
|
+
}
|
|
102
|
+
let prefixedDocument = aliasTopLevelFields(prefix, request.document);
|
|
103
|
+
const executionVariableNames = Object.keys(executionVariables);
|
|
104
|
+
if (executionVariableNames.length > 0) {
|
|
105
|
+
prefixedDocument = visit(prefixedDocument, {
|
|
106
|
+
[Kind.VARIABLE]: prefixNode,
|
|
107
|
+
[Kind.FRAGMENT_DEFINITION]: prefixNode,
|
|
108
|
+
[Kind.FRAGMENT_SPREAD]: prefixNode,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
const prefixedVariables = {};
|
|
112
|
+
for (const variableName of executionVariableNames) {
|
|
113
|
+
prefixedVariables[prefix + variableName] = executionVariables[variableName];
|
|
104
114
|
}
|
|
105
|
-
document = visit(document, {
|
|
106
|
-
[Kind.VARIABLE]: (node) => prefixNodeName(node, prefix),
|
|
107
|
-
[Kind.FRAGMENT_DEFINITION]: (node) => prefixNodeName(node, prefix),
|
|
108
|
-
[Kind.FRAGMENT_SPREAD]: (node) => prefixNodeName(node, prefix),
|
|
109
|
-
});
|
|
110
|
-
const prefixedVariables = variableNames.reduce((acc, name) => {
|
|
111
|
-
acc[prefix + name] = executionVariables[name];
|
|
112
|
-
return acc;
|
|
113
|
-
}, Object.create(null));
|
|
114
115
|
return {
|
|
115
|
-
document,
|
|
116
|
+
document: prefixedDocument,
|
|
116
117
|
variables: prefixedVariables,
|
|
117
118
|
operationType: request.operationType,
|
|
118
119
|
};
|
|
@@ -294,7 +295,7 @@ function createBatchingExecutor(executor, dataLoaderOptions, extensionsReducer =
|
|
|
294
295
|
};
|
|
295
296
|
}
|
|
296
297
|
function createLoadFn(executor, extensionsReducer) {
|
|
297
|
-
return async (requests)
|
|
298
|
+
return async function batchExecuteLoadFn(requests) {
|
|
298
299
|
const execBatches = [];
|
|
299
300
|
let index = 0;
|
|
300
301
|
const request = requests[index];
|
|
@@ -314,13 +315,12 @@ function createLoadFn(executor, extensionsReducer) {
|
|
|
314
315
|
execBatches.push(currentBatch);
|
|
315
316
|
}
|
|
316
317
|
}
|
|
317
|
-
const
|
|
318
|
+
const results = await Promise.all(execBatches.map(async (execBatch) => {
|
|
318
319
|
const mergedRequests = mergeRequests(execBatch, extensionsReducer);
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
.resolve();
|
|
320
|
+
const resultBatches = (await executor(mergedRequests));
|
|
321
|
+
return splitResult(resultBatches, execBatch.length);
|
|
322
|
+
}));
|
|
323
|
+
return results.flat();
|
|
324
324
|
};
|
|
325
325
|
}
|
|
326
326
|
function defaultExtensionsReducer(mergedExtensions, request) {
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/batch-execute",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.2",
|
|
4
4
|
"description": "A set of utils for faster development of GraphQL tools",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"graphql": "^14.0.0 || ^15.0.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@graphql-tools/utils": "8.0.
|
|
10
|
+
"@graphql-tools/utils": "8.0.2",
|
|
11
11
|
"dataloader": "2.0.0",
|
|
12
12
|
"tslib": "~2.3.0",
|
|
13
13
|
"value-or-promise": "1.0.10"
|