@depup/graphql-tools__batch-execute 10.0.8-depup.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/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # @depup/graphql-tools__batch-execute
2
+
3
+ > Dependency-bumped version of [@graphql-tools/batch-execute](https://www.npmjs.com/package/@graphql-tools/batch-execute)
4
+
5
+ Generated by [DepUp](https://github.com/depup/npm) -- all production
6
+ dependencies bumped to latest versions.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install @depup/graphql-tools__batch-execute
12
+ ```
13
+
14
+ | Field | Value |
15
+ |-------|-------|
16
+ | Original | [@graphql-tools/batch-execute](https://www.npmjs.com/package/@graphql-tools/batch-execute) @ 10.0.8 |
17
+ | Processed | 2026-04-03 |
18
+ | Smoke test | passed |
19
+ | Deps updated | 0 |
20
+
21
+ ---
22
+
23
+ Source: https://github.com/depup/npm | Original: https://www.npmjs.com/package/@graphql-tools/batch-execute
24
+
25
+ License inherited from the original package.
package/changes.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "bumped": {},
3
+ "timestamp": "2026-04-03T12:19:55.315Z",
4
+ "totalUpdated": 0
5
+ }
package/dist/index.cjs ADDED
@@ -0,0 +1,362 @@
1
+ 'use strict';
2
+
3
+ var utils = require('@graphql-tools/utils');
4
+ var promiseHelpers = require('@whatwg-node/promise-helpers');
5
+ var DataLoader = require('dataloader');
6
+ var graphql = require('graphql');
7
+
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
+
10
+ var DataLoader__default = /*#__PURE__*/_interopDefault(DataLoader);
11
+
12
+ function createPrefix(index) {
13
+ return `_v${index}_`;
14
+ }
15
+ function matchKey(prefixedKey) {
16
+ const match = /^_v(\d+)_(.*)$/.exec(prefixedKey);
17
+ if (match && match.length === 3 && !isNaN(Number(match[1])) && match[2]) {
18
+ return { index: Number(match[1]), originalKey: match[2] };
19
+ }
20
+ return null;
21
+ }
22
+ function parseKey(prefixedKey) {
23
+ const match = matchKey(prefixedKey);
24
+ if (!match) {
25
+ throw new Error(`Key ${prefixedKey} is not correctly prefixed`);
26
+ }
27
+ return match;
28
+ }
29
+ function parseKeyFromPath(path) {
30
+ let keyOffset = 0;
31
+ let match = null;
32
+ for (; !match && keyOffset < path.length; keyOffset++) {
33
+ const pathKey = path[keyOffset];
34
+ if (typeof pathKey === "string") {
35
+ match = matchKey(pathKey);
36
+ }
37
+ }
38
+ if (!match) {
39
+ throw new Error(
40
+ `Path ${path.join(".")} does not contain correctly prefixed key`
41
+ );
42
+ }
43
+ return {
44
+ ...match,
45
+ keyOffset
46
+ };
47
+ }
48
+
49
+ function mergeRequests(requests, extensionsReducer) {
50
+ const firstRequest = requests[0];
51
+ if (!firstRequest) {
52
+ throw new Error("At least one request is required");
53
+ }
54
+ const requestCount = requests.length;
55
+ if (requestCount === 1) {
56
+ return firstRequest;
57
+ }
58
+ const mergedVariables = /* @__PURE__ */ Object.create(null);
59
+ const mergedVariableDefinitions = [];
60
+ const mergedSelections = [];
61
+ const mergedFragmentDefinitions = [];
62
+ let mergedExtensions = /* @__PURE__ */ Object.create(null);
63
+ let subgraphName;
64
+ let operationName;
65
+ let operationType;
66
+ let context;
67
+ let info;
68
+ let rootValue;
69
+ for (let index = 0; index < requestCount; index++) {
70
+ const request = requests[index];
71
+ if (request) {
72
+ subgraphName ??= request.subgraphName;
73
+ operationName ??= request.operationName;
74
+ operationType ??= request.operationType;
75
+ context ??= request.context;
76
+ info ??= request.info;
77
+ rootValue ??= request.rootValue;
78
+ const prefixedRequests = prefixRequest(createPrefix(index), request);
79
+ for (const def of prefixedRequests.document.definitions) {
80
+ if (isOperationDefinition(def)) {
81
+ mergedSelections.push(...def.selectionSet.selections);
82
+ operationType ??= def.operation;
83
+ operationName ??= def.name?.value;
84
+ if (def.variableDefinitions) {
85
+ mergedVariableDefinitions.push(...def.variableDefinitions);
86
+ }
87
+ }
88
+ if (isFragmentDefinition(def)) {
89
+ mergedFragmentDefinitions.push(def);
90
+ }
91
+ }
92
+ Object.assign(mergedVariables, prefixedRequests.variables);
93
+ mergedExtensions = extensionsReducer(mergedExtensions, request);
94
+ }
95
+ }
96
+ if (operationName == null) {
97
+ operationName = info?.operation?.name?.value;
98
+ }
99
+ operationType ||= "query";
100
+ const mergedOperationDefinition = {
101
+ kind: graphql.Kind.OPERATION_DEFINITION,
102
+ operation: operationType,
103
+ variableDefinitions: mergedVariableDefinitions,
104
+ selectionSet: {
105
+ kind: graphql.Kind.SELECTION_SET,
106
+ selections: mergedSelections
107
+ },
108
+ name: operationName ? {
109
+ kind: graphql.Kind.NAME,
110
+ value: operationName
111
+ } : void 0
112
+ };
113
+ return {
114
+ subgraphName,
115
+ document: {
116
+ kind: graphql.Kind.DOCUMENT,
117
+ definitions: [mergedOperationDefinition, ...mergedFragmentDefinitions]
118
+ },
119
+ variables: mergedVariables,
120
+ extensions: mergedExtensions,
121
+ context,
122
+ info,
123
+ operationType,
124
+ rootValue,
125
+ operationName
126
+ };
127
+ }
128
+ function prefixRequest(prefix, request) {
129
+ function prefixNode(node) {
130
+ return prefixNodeName(node, prefix);
131
+ }
132
+ let prefixedDocument = aliasTopLevelFields(prefix, request.document);
133
+ let hasFragmentDefinitionsOrVariables = false;
134
+ for (const def of prefixedDocument.definitions) {
135
+ if (isFragmentDefinition(def) || isOperationDefinition(def) && !!def.variableDefinitions?.length) {
136
+ hasFragmentDefinitionsOrVariables = true;
137
+ break;
138
+ }
139
+ }
140
+ const fragmentSpreadImpl = {};
141
+ let hasFragments = false;
142
+ if (hasFragmentDefinitionsOrVariables) {
143
+ prefixedDocument = graphql.visit(prefixedDocument, {
144
+ [graphql.Kind.VARIABLE]: prefixNode,
145
+ [graphql.Kind.FRAGMENT_DEFINITION](node) {
146
+ hasFragments = true;
147
+ return prefixNode(node);
148
+ },
149
+ [graphql.Kind.FRAGMENT_SPREAD]: (node) => {
150
+ node = prefixNodeName(node, prefix);
151
+ fragmentSpreadImpl[node.name.value] = true;
152
+ return node;
153
+ }
154
+ });
155
+ }
156
+ let prefixedVariables;
157
+ const executionVariables = request.variables;
158
+ if (executionVariables) {
159
+ prefixedVariables = /* @__PURE__ */ Object.create(null);
160
+ for (const variableName in executionVariables) {
161
+ prefixedVariables[prefix + variableName] = executionVariables[variableName];
162
+ }
163
+ }
164
+ if (hasFragments) {
165
+ prefixedDocument = {
166
+ ...prefixedDocument,
167
+ definitions: prefixedDocument.definitions.filter(
168
+ (def) => !isFragmentDefinition(def) || fragmentSpreadImpl[def.name.value]
169
+ )
170
+ };
171
+ }
172
+ return {
173
+ document: prefixedDocument,
174
+ variables: prefixedVariables
175
+ };
176
+ }
177
+ function aliasTopLevelFields(prefix, document) {
178
+ const transformer = {
179
+ [graphql.Kind.OPERATION_DEFINITION]: (def) => {
180
+ const { selections } = def.selectionSet;
181
+ return {
182
+ ...def,
183
+ selectionSet: {
184
+ ...def.selectionSet,
185
+ selections: aliasFieldsInSelection(prefix, selections, document)
186
+ }
187
+ };
188
+ }
189
+ };
190
+ return graphql.visit(document, transformer, {
191
+ [graphql.Kind.DOCUMENT]: [`definitions`]
192
+ });
193
+ }
194
+ function aliasFieldsInSelection(prefix, selections, document) {
195
+ return selections.map((selection) => {
196
+ switch (selection.kind) {
197
+ case graphql.Kind.INLINE_FRAGMENT:
198
+ return aliasFieldsInInlineFragment(prefix, selection, document);
199
+ case graphql.Kind.FRAGMENT_SPREAD: {
200
+ const inlineFragment = inlineFragmentSpread(selection, document);
201
+ return aliasFieldsInInlineFragment(prefix, inlineFragment, document);
202
+ }
203
+ case graphql.Kind.FIELD:
204
+ default:
205
+ return aliasField(selection, prefix);
206
+ }
207
+ });
208
+ }
209
+ function aliasFieldsInInlineFragment(prefix, fragment, document) {
210
+ const { selections } = fragment.selectionSet;
211
+ return {
212
+ ...fragment,
213
+ selectionSet: {
214
+ ...fragment.selectionSet,
215
+ selections: aliasFieldsInSelection(prefix, selections, document)
216
+ }
217
+ };
218
+ }
219
+ function inlineFragmentSpread(spread, document) {
220
+ const fragment = document.definitions.find(
221
+ (def) => isFragmentDefinition(def) && def.name.value === spread.name.value
222
+ );
223
+ if (!fragment) {
224
+ throw new Error(`Fragment ${spread.name.value} does not exist`);
225
+ }
226
+ const { typeCondition, selectionSet } = fragment;
227
+ return {
228
+ kind: graphql.Kind.INLINE_FRAGMENT,
229
+ typeCondition,
230
+ selectionSet,
231
+ directives: spread.directives
232
+ };
233
+ }
234
+ function prefixNodeName(namedNode, prefix) {
235
+ return {
236
+ ...namedNode,
237
+ name: {
238
+ ...namedNode.name,
239
+ value: prefix + namedNode.name.value
240
+ }
241
+ };
242
+ }
243
+ function aliasField(field, aliasPrefix) {
244
+ const aliasNode = field.alias ? field.alias : field.name;
245
+ return {
246
+ ...field,
247
+ alias: {
248
+ ...aliasNode,
249
+ value: aliasPrefix + aliasNode.value
250
+ }
251
+ };
252
+ }
253
+ function isOperationDefinition(def) {
254
+ return def.kind === graphql.Kind.OPERATION_DEFINITION;
255
+ }
256
+ function isFragmentDefinition(def) {
257
+ return def.kind === graphql.Kind.FRAGMENT_DEFINITION;
258
+ }
259
+
260
+ function splitResult({ data, errors }, numResults) {
261
+ const splitResults = new Array(numResults);
262
+ if (data) {
263
+ for (const prefixedKey in data) {
264
+ if (prefixedKey === "__proto__" || prefixedKey === "constructor" || prefixedKey === "prototype") {
265
+ continue;
266
+ }
267
+ const { index, originalKey } = parseKey(prefixedKey);
268
+ const result = splitResults[index];
269
+ if (result == null) {
270
+ splitResults[index] = {
271
+ data: {
272
+ [originalKey]: data[prefixedKey]
273
+ }
274
+ };
275
+ } else if (result.data == null) {
276
+ result.data = { [originalKey]: data[prefixedKey] };
277
+ } else {
278
+ result.data[originalKey] = data[prefixedKey];
279
+ }
280
+ }
281
+ }
282
+ if (errors) {
283
+ for (const error of errors) {
284
+ if (error.path) {
285
+ const { index, originalKey, keyOffset } = parseKeyFromPath(error.path);
286
+ const newError = utils.relocatedError(error, [
287
+ originalKey,
288
+ ...error.path.slice(keyOffset)
289
+ ]);
290
+ const splittedResult = splitResults[index];
291
+ if (splittedResult == null) {
292
+ splitResults[index] = { errors: [newError] };
293
+ continue;
294
+ } else if (splittedResult.errors == null) {
295
+ splittedResult.errors = [newError];
296
+ continue;
297
+ } else {
298
+ splittedResult.errors.push(newError);
299
+ }
300
+ } else {
301
+ for (let i = 0; i < numResults; i++) {
302
+ const splittedResult = splitResults[i];
303
+ if (splittedResult == null) {
304
+ splitResults[i] = { errors: [error] };
305
+ continue;
306
+ } else if (splittedResult.errors == null) {
307
+ splittedResult.errors = [error];
308
+ continue;
309
+ } else {
310
+ splittedResult.errors.push(error);
311
+ }
312
+ }
313
+ }
314
+ }
315
+ }
316
+ return splitResults;
317
+ }
318
+
319
+ function createBatchingExecutor(executor, dataLoaderOptions, extensionsReducer = defaultExtensionsReducer) {
320
+ const loadFn = createLoadFn(executor, extensionsReducer);
321
+ const queryLoader = new DataLoader__default.default(loadFn, dataLoaderOptions);
322
+ const mutationLoader = new DataLoader__default.default(loadFn, dataLoaderOptions);
323
+ return function batchingExecutor(request) {
324
+ const operationType = request.operationType ?? utils.getOperationASTFromRequest(request)?.operation;
325
+ switch (operationType) {
326
+ case "query":
327
+ return queryLoader.load(request);
328
+ case "mutation":
329
+ return mutationLoader.load(request);
330
+ case "subscription":
331
+ return executor(request);
332
+ default:
333
+ throw new Error(`Invalid operation type "${operationType}"`);
334
+ }
335
+ };
336
+ }
337
+ function createLoadFn(executor, extensionsReducer) {
338
+ return function batchExecuteLoadFn(requests) {
339
+ if (requests.length === 1 && requests[0]) {
340
+ const request = requests[0];
341
+ return promiseHelpers.fakePromise().then(() => executor(request)).catch((err) => err).then((res) => [res]);
342
+ }
343
+ const mergedRequests = mergeRequests(requests, extensionsReducer);
344
+ return promiseHelpers.fakePromise().then(() => executor(mergedRequests)).then(
345
+ (resultBatches) => splitResult(resultBatches, requests.length)
346
+ ).catch((err) => requests.map(() => err));
347
+ };
348
+ }
349
+ function defaultExtensionsReducer(mergedExtensions, request) {
350
+ const newExtensions = request.extensions;
351
+ if (newExtensions != null) {
352
+ Object.assign(mergedExtensions, newExtensions);
353
+ }
354
+ return mergedExtensions;
355
+ }
356
+
357
+ const getBatchingExecutor = utils.memoize2of4(function getBatchingExecutor2(_context, executor, dataLoaderOptions, extensionsReducer) {
358
+ return createBatchingExecutor(executor, dataLoaderOptions, extensionsReducer);
359
+ });
360
+
361
+ exports.createBatchingExecutor = createBatchingExecutor;
362
+ exports.getBatchingExecutor = getBatchingExecutor;
@@ -0,0 +1,8 @@
1
+ import { Executor, ExecutionRequest, MaybeAsyncIterable } from '@graphql-tools/utils';
2
+ import DataLoader from 'dataloader';
3
+
4
+ declare function createBatchingExecutor(executor: Executor, dataLoaderOptions?: DataLoader.Options<ExecutionRequest, MaybeAsyncIterable<any>>, extensionsReducer?: (mergedExtensions: Record<string, any>, request: ExecutionRequest) => Record<string, any>): Executor;
5
+
6
+ declare const getBatchingExecutor: (_context: Record<string, any>, executor: Executor, dataLoaderOptions?: DataLoader.Options<any, any, any> | undefined, extensionsReducer?: undefined | ((mergedExtensions: Record<string, any>, request: ExecutionRequest) => Record<string, any>)) => Executor;
7
+
8
+ export { createBatchingExecutor, getBatchingExecutor };
@@ -0,0 +1,8 @@
1
+ import { Executor, ExecutionRequest, MaybeAsyncIterable } from '@graphql-tools/utils';
2
+ import DataLoader from 'dataloader';
3
+
4
+ declare function createBatchingExecutor(executor: Executor, dataLoaderOptions?: DataLoader.Options<ExecutionRequest, MaybeAsyncIterable<any>>, extensionsReducer?: (mergedExtensions: Record<string, any>, request: ExecutionRequest) => Record<string, any>): Executor;
5
+
6
+ declare const getBatchingExecutor: (_context: Record<string, any>, executor: Executor, dataLoaderOptions?: DataLoader.Options<any, any, any> | undefined, extensionsReducer?: undefined | ((mergedExtensions: Record<string, any>, request: ExecutionRequest) => Record<string, any>)) => Executor;
7
+
8
+ export { createBatchingExecutor, getBatchingExecutor };
package/dist/index.js ADDED
@@ -0,0 +1,355 @@
1
+ import { relocatedError, getOperationASTFromRequest, memoize2of4 } from '@graphql-tools/utils';
2
+ import { fakePromise } from '@whatwg-node/promise-helpers';
3
+ import DataLoader from 'dataloader';
4
+ import { Kind, visit } from 'graphql';
5
+
6
+ function createPrefix(index) {
7
+ return `_v${index}_`;
8
+ }
9
+ function matchKey(prefixedKey) {
10
+ const match = /^_v(\d+)_(.*)$/.exec(prefixedKey);
11
+ if (match && match.length === 3 && !isNaN(Number(match[1])) && match[2]) {
12
+ return { index: Number(match[1]), originalKey: match[2] };
13
+ }
14
+ return null;
15
+ }
16
+ function parseKey(prefixedKey) {
17
+ const match = matchKey(prefixedKey);
18
+ if (!match) {
19
+ throw new Error(`Key ${prefixedKey} is not correctly prefixed`);
20
+ }
21
+ return match;
22
+ }
23
+ function parseKeyFromPath(path) {
24
+ let keyOffset = 0;
25
+ let match = null;
26
+ for (; !match && keyOffset < path.length; keyOffset++) {
27
+ const pathKey = path[keyOffset];
28
+ if (typeof pathKey === "string") {
29
+ match = matchKey(pathKey);
30
+ }
31
+ }
32
+ if (!match) {
33
+ throw new Error(
34
+ `Path ${path.join(".")} does not contain correctly prefixed key`
35
+ );
36
+ }
37
+ return {
38
+ ...match,
39
+ keyOffset
40
+ };
41
+ }
42
+
43
+ function mergeRequests(requests, extensionsReducer) {
44
+ const firstRequest = requests[0];
45
+ if (!firstRequest) {
46
+ throw new Error("At least one request is required");
47
+ }
48
+ const requestCount = requests.length;
49
+ if (requestCount === 1) {
50
+ return firstRequest;
51
+ }
52
+ const mergedVariables = /* @__PURE__ */ Object.create(null);
53
+ const mergedVariableDefinitions = [];
54
+ const mergedSelections = [];
55
+ const mergedFragmentDefinitions = [];
56
+ let mergedExtensions = /* @__PURE__ */ Object.create(null);
57
+ let subgraphName;
58
+ let operationName;
59
+ let operationType;
60
+ let context;
61
+ let info;
62
+ let rootValue;
63
+ for (let index = 0; index < requestCount; index++) {
64
+ const request = requests[index];
65
+ if (request) {
66
+ subgraphName ??= request.subgraphName;
67
+ operationName ??= request.operationName;
68
+ operationType ??= request.operationType;
69
+ context ??= request.context;
70
+ info ??= request.info;
71
+ rootValue ??= request.rootValue;
72
+ const prefixedRequests = prefixRequest(createPrefix(index), request);
73
+ for (const def of prefixedRequests.document.definitions) {
74
+ if (isOperationDefinition(def)) {
75
+ mergedSelections.push(...def.selectionSet.selections);
76
+ operationType ??= def.operation;
77
+ operationName ??= def.name?.value;
78
+ if (def.variableDefinitions) {
79
+ mergedVariableDefinitions.push(...def.variableDefinitions);
80
+ }
81
+ }
82
+ if (isFragmentDefinition(def)) {
83
+ mergedFragmentDefinitions.push(def);
84
+ }
85
+ }
86
+ Object.assign(mergedVariables, prefixedRequests.variables);
87
+ mergedExtensions = extensionsReducer(mergedExtensions, request);
88
+ }
89
+ }
90
+ if (operationName == null) {
91
+ operationName = info?.operation?.name?.value;
92
+ }
93
+ operationType ||= "query";
94
+ const mergedOperationDefinition = {
95
+ kind: Kind.OPERATION_DEFINITION,
96
+ operation: operationType,
97
+ variableDefinitions: mergedVariableDefinitions,
98
+ selectionSet: {
99
+ kind: Kind.SELECTION_SET,
100
+ selections: mergedSelections
101
+ },
102
+ name: operationName ? {
103
+ kind: Kind.NAME,
104
+ value: operationName
105
+ } : void 0
106
+ };
107
+ return {
108
+ subgraphName,
109
+ document: {
110
+ kind: Kind.DOCUMENT,
111
+ definitions: [mergedOperationDefinition, ...mergedFragmentDefinitions]
112
+ },
113
+ variables: mergedVariables,
114
+ extensions: mergedExtensions,
115
+ context,
116
+ info,
117
+ operationType,
118
+ rootValue,
119
+ operationName
120
+ };
121
+ }
122
+ function prefixRequest(prefix, request) {
123
+ function prefixNode(node) {
124
+ return prefixNodeName(node, prefix);
125
+ }
126
+ let prefixedDocument = aliasTopLevelFields(prefix, request.document);
127
+ let hasFragmentDefinitionsOrVariables = false;
128
+ for (const def of prefixedDocument.definitions) {
129
+ if (isFragmentDefinition(def) || isOperationDefinition(def) && !!def.variableDefinitions?.length) {
130
+ hasFragmentDefinitionsOrVariables = true;
131
+ break;
132
+ }
133
+ }
134
+ const fragmentSpreadImpl = {};
135
+ let hasFragments = false;
136
+ if (hasFragmentDefinitionsOrVariables) {
137
+ prefixedDocument = visit(prefixedDocument, {
138
+ [Kind.VARIABLE]: prefixNode,
139
+ [Kind.FRAGMENT_DEFINITION](node) {
140
+ hasFragments = true;
141
+ return prefixNode(node);
142
+ },
143
+ [Kind.FRAGMENT_SPREAD]: (node) => {
144
+ node = prefixNodeName(node, prefix);
145
+ fragmentSpreadImpl[node.name.value] = true;
146
+ return node;
147
+ }
148
+ });
149
+ }
150
+ let prefixedVariables;
151
+ const executionVariables = request.variables;
152
+ if (executionVariables) {
153
+ prefixedVariables = /* @__PURE__ */ Object.create(null);
154
+ for (const variableName in executionVariables) {
155
+ prefixedVariables[prefix + variableName] = executionVariables[variableName];
156
+ }
157
+ }
158
+ if (hasFragments) {
159
+ prefixedDocument = {
160
+ ...prefixedDocument,
161
+ definitions: prefixedDocument.definitions.filter(
162
+ (def) => !isFragmentDefinition(def) || fragmentSpreadImpl[def.name.value]
163
+ )
164
+ };
165
+ }
166
+ return {
167
+ document: prefixedDocument,
168
+ variables: prefixedVariables
169
+ };
170
+ }
171
+ function aliasTopLevelFields(prefix, document) {
172
+ const transformer = {
173
+ [Kind.OPERATION_DEFINITION]: (def) => {
174
+ const { selections } = def.selectionSet;
175
+ return {
176
+ ...def,
177
+ selectionSet: {
178
+ ...def.selectionSet,
179
+ selections: aliasFieldsInSelection(prefix, selections, document)
180
+ }
181
+ };
182
+ }
183
+ };
184
+ return visit(document, transformer, {
185
+ [Kind.DOCUMENT]: [`definitions`]
186
+ });
187
+ }
188
+ function aliasFieldsInSelection(prefix, selections, document) {
189
+ return selections.map((selection) => {
190
+ switch (selection.kind) {
191
+ case Kind.INLINE_FRAGMENT:
192
+ return aliasFieldsInInlineFragment(prefix, selection, document);
193
+ case Kind.FRAGMENT_SPREAD: {
194
+ const inlineFragment = inlineFragmentSpread(selection, document);
195
+ return aliasFieldsInInlineFragment(prefix, inlineFragment, document);
196
+ }
197
+ case Kind.FIELD:
198
+ default:
199
+ return aliasField(selection, prefix);
200
+ }
201
+ });
202
+ }
203
+ function aliasFieldsInInlineFragment(prefix, fragment, document) {
204
+ const { selections } = fragment.selectionSet;
205
+ return {
206
+ ...fragment,
207
+ selectionSet: {
208
+ ...fragment.selectionSet,
209
+ selections: aliasFieldsInSelection(prefix, selections, document)
210
+ }
211
+ };
212
+ }
213
+ function inlineFragmentSpread(spread, document) {
214
+ const fragment = document.definitions.find(
215
+ (def) => isFragmentDefinition(def) && def.name.value === spread.name.value
216
+ );
217
+ if (!fragment) {
218
+ throw new Error(`Fragment ${spread.name.value} does not exist`);
219
+ }
220
+ const { typeCondition, selectionSet } = fragment;
221
+ return {
222
+ kind: Kind.INLINE_FRAGMENT,
223
+ typeCondition,
224
+ selectionSet,
225
+ directives: spread.directives
226
+ };
227
+ }
228
+ function prefixNodeName(namedNode, prefix) {
229
+ return {
230
+ ...namedNode,
231
+ name: {
232
+ ...namedNode.name,
233
+ value: prefix + namedNode.name.value
234
+ }
235
+ };
236
+ }
237
+ function aliasField(field, aliasPrefix) {
238
+ const aliasNode = field.alias ? field.alias : field.name;
239
+ return {
240
+ ...field,
241
+ alias: {
242
+ ...aliasNode,
243
+ value: aliasPrefix + aliasNode.value
244
+ }
245
+ };
246
+ }
247
+ function isOperationDefinition(def) {
248
+ return def.kind === Kind.OPERATION_DEFINITION;
249
+ }
250
+ function isFragmentDefinition(def) {
251
+ return def.kind === Kind.FRAGMENT_DEFINITION;
252
+ }
253
+
254
+ function splitResult({ data, errors }, numResults) {
255
+ const splitResults = new Array(numResults);
256
+ if (data) {
257
+ for (const prefixedKey in data) {
258
+ if (prefixedKey === "__proto__" || prefixedKey === "constructor" || prefixedKey === "prototype") {
259
+ continue;
260
+ }
261
+ const { index, originalKey } = parseKey(prefixedKey);
262
+ const result = splitResults[index];
263
+ if (result == null) {
264
+ splitResults[index] = {
265
+ data: {
266
+ [originalKey]: data[prefixedKey]
267
+ }
268
+ };
269
+ } else if (result.data == null) {
270
+ result.data = { [originalKey]: data[prefixedKey] };
271
+ } else {
272
+ result.data[originalKey] = data[prefixedKey];
273
+ }
274
+ }
275
+ }
276
+ if (errors) {
277
+ for (const error of errors) {
278
+ if (error.path) {
279
+ const { index, originalKey, keyOffset } = parseKeyFromPath(error.path);
280
+ const newError = relocatedError(error, [
281
+ originalKey,
282
+ ...error.path.slice(keyOffset)
283
+ ]);
284
+ const splittedResult = splitResults[index];
285
+ if (splittedResult == null) {
286
+ splitResults[index] = { errors: [newError] };
287
+ continue;
288
+ } else if (splittedResult.errors == null) {
289
+ splittedResult.errors = [newError];
290
+ continue;
291
+ } else {
292
+ splittedResult.errors.push(newError);
293
+ }
294
+ } else {
295
+ for (let i = 0; i < numResults; i++) {
296
+ const splittedResult = splitResults[i];
297
+ if (splittedResult == null) {
298
+ splitResults[i] = { errors: [error] };
299
+ continue;
300
+ } else if (splittedResult.errors == null) {
301
+ splittedResult.errors = [error];
302
+ continue;
303
+ } else {
304
+ splittedResult.errors.push(error);
305
+ }
306
+ }
307
+ }
308
+ }
309
+ }
310
+ return splitResults;
311
+ }
312
+
313
+ function createBatchingExecutor(executor, dataLoaderOptions, extensionsReducer = defaultExtensionsReducer) {
314
+ const loadFn = createLoadFn(executor, extensionsReducer);
315
+ const queryLoader = new DataLoader(loadFn, dataLoaderOptions);
316
+ const mutationLoader = new DataLoader(loadFn, dataLoaderOptions);
317
+ return function batchingExecutor(request) {
318
+ const operationType = request.operationType ?? getOperationASTFromRequest(request)?.operation;
319
+ switch (operationType) {
320
+ case "query":
321
+ return queryLoader.load(request);
322
+ case "mutation":
323
+ return mutationLoader.load(request);
324
+ case "subscription":
325
+ return executor(request);
326
+ default:
327
+ throw new Error(`Invalid operation type "${operationType}"`);
328
+ }
329
+ };
330
+ }
331
+ function createLoadFn(executor, extensionsReducer) {
332
+ return function batchExecuteLoadFn(requests) {
333
+ if (requests.length === 1 && requests[0]) {
334
+ const request = requests[0];
335
+ return fakePromise().then(() => executor(request)).catch((err) => err).then((res) => [res]);
336
+ }
337
+ const mergedRequests = mergeRequests(requests, extensionsReducer);
338
+ return fakePromise().then(() => executor(mergedRequests)).then(
339
+ (resultBatches) => splitResult(resultBatches, requests.length)
340
+ ).catch((err) => requests.map(() => err));
341
+ };
342
+ }
343
+ function defaultExtensionsReducer(mergedExtensions, request) {
344
+ const newExtensions = request.extensions;
345
+ if (newExtensions != null) {
346
+ Object.assign(mergedExtensions, newExtensions);
347
+ }
348
+ return mergedExtensions;
349
+ }
350
+
351
+ const getBatchingExecutor = memoize2of4(function getBatchingExecutor2(_context, executor, dataLoaderOptions, extensionsReducer) {
352
+ return createBatchingExecutor(executor, dataLoaderOptions, extensionsReducer);
353
+ });
354
+
355
+ export { createBatchingExecutor, getBatchingExecutor };
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@depup/graphql-tools__batch-execute",
3
+ "version": "10.0.8-depup.0",
4
+ "type": "module",
5
+ "description": "A set of utils for faster development of GraphQL tools (with updated dependencies)",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/graphql-hive/gateway.git",
9
+ "directory": "packages/batch-execute"
10
+ },
11
+ "license": "MIT",
12
+ "engines": {
13
+ "node": ">=20.0.0"
14
+ },
15
+ "main": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "require": {
20
+ "types": "./dist/index.d.cts",
21
+ "default": "./dist/index.cjs"
22
+ },
23
+ "import": {
24
+ "types": "./dist/index.d.ts",
25
+ "default": "./dist/index.js"
26
+ }
27
+ },
28
+ "./package.json": "./package.json"
29
+ },
30
+ "files": [
31
+ "dist",
32
+ "changes.json",
33
+ "README.md"
34
+ ],
35
+ "scripts": {
36
+ "build": "pkgroll --clean-dist"
37
+ },
38
+ "peerDependencies": {
39
+ "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
40
+ },
41
+ "dependencies": {
42
+ "@graphql-tools/utils": "^11.0.0",
43
+ "@whatwg-node/promise-helpers": "^1.3.2",
44
+ "dataloader": "^2.2.3",
45
+ "tslib": "^2.8.1"
46
+ },
47
+ "devDependencies": {
48
+ "graphql": "^16.12.0",
49
+ "pkgroll": "2.27.0"
50
+ },
51
+ "sideEffects": false,
52
+ "keywords": [
53
+ "@graphql-tools/batch-execute",
54
+ "depup",
55
+ "updated-dependencies",
56
+ "security",
57
+ "latest",
58
+ "patched"
59
+ ],
60
+ "depup": {
61
+ "changes": {},
62
+ "depsUpdated": 0,
63
+ "originalPackage": "@graphql-tools/batch-execute",
64
+ "originalVersion": "10.0.8",
65
+ "processedAt": "2026-04-03T12:19:59.027Z",
66
+ "smokeTest": "passed"
67
+ }
68
+ }