@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/index.esm.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { cloneSchema, serializeInputValue, updateArgument, collectFields, relocatedError, mergeDeep, getResponseKeyFromInfo, implementsAbstractType, mapAsyncIterator } from '@graphql-tools/utils';
2
- import { Kind, typeFromAST, GraphQLError, responsePathAsArray, getNamedType, getNullableType, isLeafType, isCompositeType, isListType, isAbstractType, locatedError, defaultFieldResolver, TypeInfo, visit, visitWithTypeInfo, print, isInterfaceType, isObjectType, TypeNameMetaFieldDef, getOperationAST, subscribe, validate, execute } from 'graphql';
2
+ 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';
3
3
  import AggregateError from '@ardatan/aggregate-error';
4
- import { ValueOrPromise } from 'value-or-promise';
4
+ import isPromise from 'is-promise';
5
5
  import { getBatchingExecutor } from '@graphql-tools/batch-execute';
6
6
 
7
7
  function applySchemaTransforms(originalWrappingSchema, subschemaConfig, transformedSchema) {
@@ -177,7 +177,7 @@ function mergeExternalObjects(schema, path, typeName, target, sources, selection
177
177
  const results = [];
178
178
  let errors = [];
179
179
  sources.forEach((source, index) => {
180
- if (source instanceof GraphQLError || source === null) {
180
+ if (source instanceof Error || source === null) {
181
181
  const selectionSet = selectionSets[index];
182
182
  const fieldNodes = collectFields({
183
183
  schema,
@@ -186,8 +186,15 @@ function mergeExternalObjects(schema, path, typeName, target, sources, selection
186
186
  }, schema.getType(typeName), selectionSet, Object.create(null), Object.create(null));
187
187
  const nullResult = {};
188
188
  Object.keys(fieldNodes).forEach(responseKey => {
189
- nullResult[responseKey] =
190
- source instanceof GraphQLError ? relocatedError(source, path.concat([responseKey])) : null;
189
+ if (source instanceof GraphQLError) {
190
+ nullResult[responseKey] = relocatedError(source, path.concat([responseKey]));
191
+ }
192
+ else if (source instanceof Error) {
193
+ nullResult[responseKey] = locatedError(source, fieldNodes[responseKey], path.concat([responseKey]));
194
+ }
195
+ else {
196
+ nullResult[responseKey] = null;
197
+ }
191
198
  });
192
199
  results.push(nullResult);
193
200
  }
@@ -553,13 +560,20 @@ function mergeFields(mergedTypeInfo, typeName, object, fieldNodes, sourceSubsche
553
560
  if (!delegationMap.size) {
554
561
  return object;
555
562
  }
563
+ let containsPromises = false;
556
564
  const resultMap = new Map();
557
565
  delegationMap.forEach((selectionSet, s) => {
558
566
  const resolver = mergedTypeInfo.resolvers.get(s);
559
- const valueOrPromise = new ValueOrPromise(() => resolver(object, context, info, s, selectionSet)).catch(error => error);
560
- resultMap.set(valueOrPromise, selectionSet);
567
+ let maybePromise = resolver(object, context, info, s, selectionSet);
568
+ if (isPromise(maybePromise)) {
569
+ containsPromises = true;
570
+ maybePromise = maybePromise.then(undefined, error => error);
571
+ }
572
+ resultMap.set(maybePromise, selectionSet);
561
573
  });
562
- return ValueOrPromise.all(Array.from(resultMap.keys())).then(results => mergeFields(mergedTypeInfo, typeName, mergeExternalObjects(info.schema, responsePathAsArray(info.path), object.__typename, object, results, Array.from(resultMap.values())), unproxiableFieldNodes, combineSubschemas(sourceSubschemaOrSourceSubschemas, proxiableSubschemas), nonProxiableSubschemas, context, info)).resolve();
574
+ return containsPromises
575
+ ? Promise.all(resultMap.keys()).then(results => mergeFields(mergedTypeInfo, typeName, mergeExternalObjects(info.schema, responsePathAsArray(info.path), object.__typename, object, results, Array.from(resultMap.values())), unproxiableFieldNodes, combineSubschemas(sourceSubschemaOrSourceSubschemas, proxiableSubschemas), nonProxiableSubschemas, context, info))
576
+ : 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);
563
577
  }
564
578
  const subschemaTypesContainSelectionSet = memoize3(function (mergedTypeInfo, sourceSubschemaOrSourceSubschemas, selectionSet) {
565
579
  if (Array.isArray(sourceSubschemaOrSourceSubschemas)) {
@@ -1637,11 +1651,17 @@ function delegateRequest({ request, schema: subschemaOrSubschemaConfig, rootValu
1637
1651
  const batchingOptions = subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.batchingOptions;
1638
1652
  executor = getBatchingExecutor(context, executor, batchingOptions === null || batchingOptions === void 0 ? void 0 : batchingOptions.dataLoaderOptions, batchingOptions === null || batchingOptions === void 0 ? void 0 : batchingOptions.extensionsReducer);
1639
1653
  }
1640
- return new ValueOrPromise(() => executor({
1654
+ const executionResult = executor({
1641
1655
  ...processedRequest,
1642
1656
  context,
1643
1657
  info,
1644
- })).then(originalResult => transformer.transformResult(originalResult)).resolve();
1658
+ });
1659
+ if (isPromise(executionResult)) {
1660
+ return executionResult.then(originalResult => {
1661
+ return transformer.transformResult(originalResult);
1662
+ });
1663
+ }
1664
+ return transformer.transformResult(executionResult);
1645
1665
  }
1646
1666
  const subscriber = (subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.subscriber) || createDefaultSubscriber(targetSchema, (subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.rootValue) || targetRootValue);
1647
1667
  return subscriber({