@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/index.cjs.js
CHANGED
|
@@ -8,7 +8,7 @@ const utils = require('@graphql-tools/utils/es5');
|
|
|
8
8
|
const tslib = require('tslib');
|
|
9
9
|
const graphql = require('graphql');
|
|
10
10
|
const AggregateError = _interopDefault(require('@ardatan/aggregate-error'));
|
|
11
|
-
const
|
|
11
|
+
const isPromise = _interopDefault(require('is-promise'));
|
|
12
12
|
const batchExecute = require('@graphql-tools/batch-execute/es5');
|
|
13
13
|
|
|
14
14
|
function applySchemaTransforms(originalWrappingSchema, subschemaConfig, transformedSchema) {
|
|
@@ -190,17 +190,24 @@ function mergeExternalObjects(schema, path, typeName, target, sources, selection
|
|
|
190
190
|
var results = [];
|
|
191
191
|
var errors = [];
|
|
192
192
|
sources.forEach(function (source, index) {
|
|
193
|
-
if (source instanceof
|
|
193
|
+
if (source instanceof Error || source === null) {
|
|
194
194
|
var selectionSet = selectionSets[index];
|
|
195
|
-
var
|
|
195
|
+
var fieldNodes_1 = utils.collectFields({
|
|
196
196
|
schema: schema,
|
|
197
197
|
variableValues: {},
|
|
198
198
|
fragments: {},
|
|
199
199
|
}, schema.getType(typeName), selectionSet, Object.create(null), Object.create(null));
|
|
200
200
|
var nullResult_1 = {};
|
|
201
|
-
Object.keys(
|
|
202
|
-
|
|
203
|
-
|
|
201
|
+
Object.keys(fieldNodes_1).forEach(function (responseKey) {
|
|
202
|
+
if (source instanceof graphql.GraphQLError) {
|
|
203
|
+
nullResult_1[responseKey] = utils.relocatedError(source, path.concat([responseKey]));
|
|
204
|
+
}
|
|
205
|
+
else if (source instanceof Error) {
|
|
206
|
+
nullResult_1[responseKey] = graphql.locatedError(source, fieldNodes_1[responseKey], path.concat([responseKey]));
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
nullResult_1[responseKey] = null;
|
|
210
|
+
}
|
|
204
211
|
});
|
|
205
212
|
results.push(nullResult_1);
|
|
206
213
|
}
|
|
@@ -563,15 +570,22 @@ function mergeFields(mergedTypeInfo, typeName, object, fieldNodes, sourceSubsche
|
|
|
563
570
|
if (!delegationMap.size) {
|
|
564
571
|
return object;
|
|
565
572
|
}
|
|
573
|
+
var containsPromises = false;
|
|
566
574
|
var resultMap = new Map();
|
|
567
575
|
delegationMap.forEach(function (selectionSet, s) {
|
|
568
576
|
var resolver = mergedTypeInfo.resolvers.get(s);
|
|
569
|
-
var
|
|
570
|
-
|
|
577
|
+
var maybePromise = resolver(object, context, info, s, selectionSet);
|
|
578
|
+
if (isPromise(maybePromise)) {
|
|
579
|
+
containsPromises = true;
|
|
580
|
+
maybePromise = maybePromise.then(undefined, function (error) { return error; });
|
|
581
|
+
}
|
|
582
|
+
resultMap.set(maybePromise, selectionSet);
|
|
571
583
|
});
|
|
572
|
-
return
|
|
573
|
-
|
|
574
|
-
|
|
584
|
+
return containsPromises
|
|
585
|
+
? Promise.all(resultMap.keys()).then(function (results) {
|
|
586
|
+
return 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);
|
|
587
|
+
})
|
|
588
|
+
: 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);
|
|
575
589
|
}
|
|
576
590
|
var subschemaTypesContainSelectionSet = memoize3(function (mergedTypeInfo, sourceSubschemaOrSourceSubschemas, selectionSet) {
|
|
577
591
|
if (Array.isArray(sourceSubschemaOrSourceSubschemas)) {
|
|
@@ -1656,13 +1670,19 @@ function delegateRequest(_a) {
|
|
|
1656
1670
|
validateRequest(targetSchema, processedRequest.document);
|
|
1657
1671
|
}
|
|
1658
1672
|
if (targetOperation === 'query' || targetOperation === 'mutation') {
|
|
1659
|
-
var
|
|
1673
|
+
var executor = (subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.executor) || createDefaultExecutor(targetSchema, (subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.rootValue) || targetRootValue);
|
|
1660
1674
|
if (subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.batch) {
|
|
1661
1675
|
var batchingOptions = subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.batchingOptions;
|
|
1662
|
-
|
|
1676
|
+
executor = batchExecute.getBatchingExecutor(context, executor, batchingOptions === null || batchingOptions === void 0 ? void 0 : batchingOptions.dataLoaderOptions, batchingOptions === null || batchingOptions === void 0 ? void 0 : batchingOptions.extensionsReducer);
|
|
1677
|
+
}
|
|
1678
|
+
var executionResult = executor(tslib.__assign(tslib.__assign({}, processedRequest), { context: context,
|
|
1679
|
+
info: info }));
|
|
1680
|
+
if (isPromise(executionResult)) {
|
|
1681
|
+
return executionResult.then(function (originalResult) {
|
|
1682
|
+
return transformer.transformResult(originalResult);
|
|
1683
|
+
});
|
|
1663
1684
|
}
|
|
1664
|
-
return
|
|
1665
|
-
info: info })); }).then(function (originalResult) { return transformer.transformResult(originalResult); }).resolve();
|
|
1685
|
+
return transformer.transformResult(executionResult);
|
|
1666
1686
|
}
|
|
1667
1687
|
var subscriber = (subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.subscriber) || createDefaultSubscriber(targetSchema, (subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.rootValue) || targetRootValue);
|
|
1668
1688
|
return subscriber(tslib.__assign(tslib.__assign({}, processedRequest), { context: context,
|