@graphql-tools/delegate 7.1.3-alpha-1a132cb3.0 → 7.1.3
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/es5/index.cjs.js +35 -15
- package/es5/index.cjs.js.map +1 -1
- package/es5/index.esm.js +36 -16
- package/es5/index.esm.js.map +1 -1
- package/es5/package.json +5 -5
- package/index.cjs.js +29 -9
- package/index.cjs.js.map +1 -1
- package/index.esm.js +30 -10
- package/index.esm.js.map +1 -1
- package/package.json +5 -5
package/es5/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/delegate/es5",
|
|
3
|
-
"version": "7.1.3
|
|
3
|
+
"version": "7.1.3",
|
|
4
4
|
"description": "A set of utils for faster development of GraphQL tools",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@ardatan/aggregate-error": "0.0.6",
|
|
11
|
-
"@graphql-tools/batch-execute": "7.1.
|
|
12
|
-
"@graphql-tools/schema": "7.
|
|
11
|
+
"@graphql-tools/batch-execute": "^7.1.0",
|
|
12
|
+
"@graphql-tools/schema": "^7.0.0",
|
|
13
13
|
"@graphql-tools/utils": "^7.7.1",
|
|
14
14
|
"dataloader": "2.0.0",
|
|
15
|
-
"
|
|
16
|
-
"
|
|
15
|
+
"is-promise": "4.0.0",
|
|
16
|
+
"tslib": "~2.2.0"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
package/index.cjs.js
CHANGED
|
@@ -7,7 +7,7 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
|
|
|
7
7
|
const utils = require('@graphql-tools/utils');
|
|
8
8
|
const graphql = require('graphql');
|
|
9
9
|
const AggregateError = _interopDefault(require('@ardatan/aggregate-error'));
|
|
10
|
-
const
|
|
10
|
+
const isPromise = _interopDefault(require('is-promise'));
|
|
11
11
|
const batchExecute = require('@graphql-tools/batch-execute');
|
|
12
12
|
|
|
13
13
|
function applySchemaTransforms(originalWrappingSchema, subschemaConfig, transformedSchema) {
|
|
@@ -183,7 +183,7 @@ function mergeExternalObjects(schema, path, typeName, target, sources, selection
|
|
|
183
183
|
const results = [];
|
|
184
184
|
let errors = [];
|
|
185
185
|
sources.forEach((source, index) => {
|
|
186
|
-
if (source instanceof
|
|
186
|
+
if (source instanceof Error || source === null) {
|
|
187
187
|
const selectionSet = selectionSets[index];
|
|
188
188
|
const fieldNodes = utils.collectFields({
|
|
189
189
|
schema,
|
|
@@ -192,8 +192,15 @@ function mergeExternalObjects(schema, path, typeName, target, sources, selection
|
|
|
192
192
|
}, schema.getType(typeName), selectionSet, Object.create(null), Object.create(null));
|
|
193
193
|
const nullResult = {};
|
|
194
194
|
Object.keys(fieldNodes).forEach(responseKey => {
|
|
195
|
-
|
|
196
|
-
|
|
195
|
+
if (source instanceof graphql.GraphQLError) {
|
|
196
|
+
nullResult[responseKey] = utils.relocatedError(source, path.concat([responseKey]));
|
|
197
|
+
}
|
|
198
|
+
else if (source instanceof Error) {
|
|
199
|
+
nullResult[responseKey] = graphql.locatedError(source, fieldNodes[responseKey], path.concat([responseKey]));
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
nullResult[responseKey] = null;
|
|
203
|
+
}
|
|
197
204
|
});
|
|
198
205
|
results.push(nullResult);
|
|
199
206
|
}
|
|
@@ -559,13 +566,20 @@ function mergeFields(mergedTypeInfo, typeName, object, fieldNodes, sourceSubsche
|
|
|
559
566
|
if (!delegationMap.size) {
|
|
560
567
|
return object;
|
|
561
568
|
}
|
|
569
|
+
let containsPromises = false;
|
|
562
570
|
const resultMap = new Map();
|
|
563
571
|
delegationMap.forEach((selectionSet, s) => {
|
|
564
572
|
const resolver = mergedTypeInfo.resolvers.get(s);
|
|
565
|
-
|
|
566
|
-
|
|
573
|
+
let maybePromise = resolver(object, context, info, s, selectionSet);
|
|
574
|
+
if (isPromise(maybePromise)) {
|
|
575
|
+
containsPromises = true;
|
|
576
|
+
maybePromise = maybePromise.then(undefined, error => error);
|
|
577
|
+
}
|
|
578
|
+
resultMap.set(maybePromise, selectionSet);
|
|
567
579
|
});
|
|
568
|
-
return
|
|
580
|
+
return containsPromises
|
|
581
|
+
? Promise.all(resultMap.keys()).then(results => mergeFields(mergedTypeInfo, typeName, mergeExternalObjects(info.schema, graphql.responsePathAsArray(info.path), object.__typename, object, results, Array.from(resultMap.values())), unproxiableFieldNodes, combineSubschemas(sourceSubschemaOrSourceSubschemas, proxiableSubschemas), nonProxiableSubschemas, context, info))
|
|
582
|
+
: mergeFields(mergedTypeInfo, typeName, mergeExternalObjects(info.schema, graphql.responsePathAsArray(info.path), object.__typename, object, Array.from(resultMap.keys()), Array.from(resultMap.values())), unproxiableFieldNodes, combineSubschemas(sourceSubschemaOrSourceSubschemas, proxiableSubschemas), nonProxiableSubschemas, context, info);
|
|
569
583
|
}
|
|
570
584
|
const subschemaTypesContainSelectionSet = memoize3(function (mergedTypeInfo, sourceSubschemaOrSourceSubschemas, selectionSet) {
|
|
571
585
|
if (Array.isArray(sourceSubschemaOrSourceSubschemas)) {
|
|
@@ -1643,11 +1657,17 @@ function delegateRequest({ request, schema: subschemaOrSubschemaConfig, rootValu
|
|
|
1643
1657
|
const batchingOptions = subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.batchingOptions;
|
|
1644
1658
|
executor = batchExecute.getBatchingExecutor(context, executor, batchingOptions === null || batchingOptions === void 0 ? void 0 : batchingOptions.dataLoaderOptions, batchingOptions === null || batchingOptions === void 0 ? void 0 : batchingOptions.extensionsReducer);
|
|
1645
1659
|
}
|
|
1646
|
-
|
|
1660
|
+
const executionResult = executor({
|
|
1647
1661
|
...processedRequest,
|
|
1648
1662
|
context,
|
|
1649
1663
|
info,
|
|
1650
|
-
})
|
|
1664
|
+
});
|
|
1665
|
+
if (isPromise(executionResult)) {
|
|
1666
|
+
return executionResult.then(originalResult => {
|
|
1667
|
+
return transformer.transformResult(originalResult);
|
|
1668
|
+
});
|
|
1669
|
+
}
|
|
1670
|
+
return transformer.transformResult(executionResult);
|
|
1651
1671
|
}
|
|
1652
1672
|
const subscriber = (subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.subscriber) || createDefaultSubscriber(targetSchema, (subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.rootValue) || targetRootValue);
|
|
1653
1673
|
return subscriber({
|