@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.esm.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { cloneSchema, serializeInputValue, updateArgument, collectFields, relocatedError, mergeDeep, getResponseKeyFromInfo, implementsAbstractType, mapAsyncIterator } from '@graphql-tools/utils/es5';
|
|
2
2
|
import { __assign, __spreadArray, __read, __values } from 'tslib';
|
|
3
|
-
import { Kind, typeFromAST, GraphQLError, responsePathAsArray, getNamedType, getNullableType, isLeafType, isCompositeType, isListType, isAbstractType,
|
|
3
|
+
import { Kind, typeFromAST, GraphQLError, locatedError, responsePathAsArray, getNamedType, getNullableType, isLeafType, isCompositeType, isListType, isAbstractType, defaultFieldResolver, TypeInfo, visit, visitWithTypeInfo, print, isInterfaceType, isObjectType, TypeNameMetaFieldDef, getOperationAST, subscribe, validate, execute } from 'graphql';
|
|
4
4
|
import AggregateError from '@ardatan/aggregate-error';
|
|
5
|
-
import
|
|
5
|
+
import isPromise from 'is-promise';
|
|
6
6
|
import { getBatchingExecutor } from '@graphql-tools/batch-execute/es5';
|
|
7
7
|
|
|
8
8
|
function applySchemaTransforms(originalWrappingSchema, subschemaConfig, transformedSchema) {
|
|
@@ -184,17 +184,24 @@ function mergeExternalObjects(schema, path, typeName, target, sources, selection
|
|
|
184
184
|
var results = [];
|
|
185
185
|
var errors = [];
|
|
186
186
|
sources.forEach(function (source, index) {
|
|
187
|
-
if (source instanceof
|
|
187
|
+
if (source instanceof Error || source === null) {
|
|
188
188
|
var selectionSet = selectionSets[index];
|
|
189
|
-
var
|
|
189
|
+
var fieldNodes_1 = collectFields({
|
|
190
190
|
schema: schema,
|
|
191
191
|
variableValues: {},
|
|
192
192
|
fragments: {},
|
|
193
193
|
}, schema.getType(typeName), selectionSet, Object.create(null), Object.create(null));
|
|
194
194
|
var nullResult_1 = {};
|
|
195
|
-
Object.keys(
|
|
196
|
-
|
|
197
|
-
|
|
195
|
+
Object.keys(fieldNodes_1).forEach(function (responseKey) {
|
|
196
|
+
if (source instanceof GraphQLError) {
|
|
197
|
+
nullResult_1[responseKey] = relocatedError(source, path.concat([responseKey]));
|
|
198
|
+
}
|
|
199
|
+
else if (source instanceof Error) {
|
|
200
|
+
nullResult_1[responseKey] = locatedError(source, fieldNodes_1[responseKey], path.concat([responseKey]));
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
nullResult_1[responseKey] = null;
|
|
204
|
+
}
|
|
198
205
|
});
|
|
199
206
|
results.push(nullResult_1);
|
|
200
207
|
}
|
|
@@ -557,15 +564,22 @@ function mergeFields(mergedTypeInfo, typeName, object, fieldNodes, sourceSubsche
|
|
|
557
564
|
if (!delegationMap.size) {
|
|
558
565
|
return object;
|
|
559
566
|
}
|
|
567
|
+
var containsPromises = false;
|
|
560
568
|
var resultMap = new Map();
|
|
561
569
|
delegationMap.forEach(function (selectionSet, s) {
|
|
562
570
|
var resolver = mergedTypeInfo.resolvers.get(s);
|
|
563
|
-
var
|
|
564
|
-
|
|
571
|
+
var maybePromise = resolver(object, context, info, s, selectionSet);
|
|
572
|
+
if (isPromise(maybePromise)) {
|
|
573
|
+
containsPromises = true;
|
|
574
|
+
maybePromise = maybePromise.then(undefined, function (error) { return error; });
|
|
575
|
+
}
|
|
576
|
+
resultMap.set(maybePromise, selectionSet);
|
|
565
577
|
});
|
|
566
|
-
return
|
|
567
|
-
|
|
568
|
-
|
|
578
|
+
return containsPromises
|
|
579
|
+
? Promise.all(resultMap.keys()).then(function (results) {
|
|
580
|
+
return mergeFields(mergedTypeInfo, typeName, mergeExternalObjects(info.schema, responsePathAsArray(info.path), object.__typename, object, results, Array.from(resultMap.values())), unproxiableFieldNodes, combineSubschemas(sourceSubschemaOrSourceSubschemas, proxiableSubschemas), nonProxiableSubschemas, context, info);
|
|
581
|
+
})
|
|
582
|
+
: mergeFields(mergedTypeInfo, typeName, mergeExternalObjects(info.schema, 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
|
var subschemaTypesContainSelectionSet = memoize3(function (mergedTypeInfo, sourceSubschemaOrSourceSubschemas, selectionSet) {
|
|
571
585
|
if (Array.isArray(sourceSubschemaOrSourceSubschemas)) {
|
|
@@ -1650,13 +1664,19 @@ function delegateRequest(_a) {
|
|
|
1650
1664
|
validateRequest(targetSchema, processedRequest.document);
|
|
1651
1665
|
}
|
|
1652
1666
|
if (targetOperation === 'query' || targetOperation === 'mutation') {
|
|
1653
|
-
var
|
|
1667
|
+
var executor = (subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.executor) || createDefaultExecutor(targetSchema, (subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.rootValue) || targetRootValue);
|
|
1654
1668
|
if (subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.batch) {
|
|
1655
1669
|
var batchingOptions = subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.batchingOptions;
|
|
1656
|
-
|
|
1670
|
+
executor = getBatchingExecutor(context, executor, batchingOptions === null || batchingOptions === void 0 ? void 0 : batchingOptions.dataLoaderOptions, batchingOptions === null || batchingOptions === void 0 ? void 0 : batchingOptions.extensionsReducer);
|
|
1671
|
+
}
|
|
1672
|
+
var executionResult = executor(__assign(__assign({}, processedRequest), { context: context,
|
|
1673
|
+
info: info }));
|
|
1674
|
+
if (isPromise(executionResult)) {
|
|
1675
|
+
return executionResult.then(function (originalResult) {
|
|
1676
|
+
return transformer.transformResult(originalResult);
|
|
1677
|
+
});
|
|
1657
1678
|
}
|
|
1658
|
-
return
|
|
1659
|
-
info: info })); }).then(function (originalResult) { return transformer.transformResult(originalResult); }).resolve();
|
|
1679
|
+
return transformer.transformResult(executionResult);
|
|
1660
1680
|
}
|
|
1661
1681
|
var subscriber = (subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.subscriber) || createDefaultSubscriber(targetSchema, (subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.rootValue) || targetRootValue);
|
|
1662
1682
|
return subscriber(__assign(__assign({}, processedRequest), { context: context,
|