@graphql-tools/delegate 7.0.0-alpha-624d205a.0 → 7.0.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/index.esm.js CHANGED
@@ -1,5 +1,5 @@
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, execute, subscribe, validate } from 'graphql';
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';
3
3
  import isPromise from 'is-promise';
4
4
  import AggregateError$1 from '@ardatan/aggregate-error';
5
5
  import { getBatchingExecutor } from '@graphql-tools/batch-execute';
@@ -26,7 +26,6 @@ class Subschema {
26
26
  this.subscriber = config.subscriber;
27
27
  this.batch = config.batch;
28
28
  this.batchingOptions = config.batchingOptions;
29
- this.endpoint = config.endpoint;
30
29
  this.createProxyingResolver = config.createProxyingResolver;
31
30
  this.transforms = (_a = config.transforms) !== null && _a !== void 0 ? _a : [];
32
31
  this.transformedSchema = applySchemaTransforms(this.schema, config);
@@ -1577,7 +1576,7 @@ function getDelegationReturnType(targetSchema, operation, fieldName) {
1577
1576
  return rootType.getFields()[fieldName].type;
1578
1577
  }
1579
1578
  function delegateRequest({ request, schema: subschemaOrSubschemaConfig, rootValue, info, operation, fieldName, args, returnType, context, transforms = [], transformedSchema, skipValidation, skipTypeMerging, binding, }) {
1580
- var _a, _b, _c, _d, _e;
1579
+ var _a, _b, _c;
1581
1580
  let operationDefinition;
1582
1581
  let targetOperation;
1583
1582
  let targetFieldName;
@@ -1595,7 +1594,7 @@ function delegateRequest({ request, schema: subschemaOrSubschemaConfig, rootValu
1595
1594
  else {
1596
1595
  targetFieldName = fieldName;
1597
1596
  }
1598
- const { targetSchema, targetRootValue, subschemaConfig, endpoint, allTransforms } = collectTargetParameters(subschemaOrSubschemaConfig, rootValue, info, transforms);
1597
+ const { targetSchema, targetRootValue, subschemaConfig, allTransforms } = collectTargetParameters(subschemaOrSubschemaConfig, rootValue, info, transforms);
1599
1598
  const delegationContext = {
1600
1599
  subschema: subschemaOrSubschemaConfig,
1601
1600
  targetSchema,
@@ -1615,9 +1614,10 @@ function delegateRequest({ request, schema: subschemaOrSubschemaConfig, rootValu
1615
1614
  validateRequest(targetSchema, processedRequest.document);
1616
1615
  }
1617
1616
  if (targetOperation === 'query' || targetOperation === 'mutation') {
1618
- let executor = (endpoint === null || endpoint === void 0 ? void 0 : endpoint.executor) || createDefaultExecutor(targetSchema, (subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.rootValue) || targetRootValue);
1619
- if (endpoint === null || endpoint === void 0 ? void 0 : endpoint.batch) {
1620
- executor = getBatchingExecutor(context, executor, (_d = endpoint === null || endpoint === void 0 ? void 0 : endpoint.batchingOptions) === null || _d === void 0 ? void 0 : _d.dataLoaderOptions, (_e = endpoint === null || endpoint === void 0 ? void 0 : endpoint.batchingOptions) === null || _e === void 0 ? void 0 : _e.extensionsReducer);
1617
+ let executor = (subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.executor) || createDefaultExecutor(targetSchema, (subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.rootValue) || targetRootValue);
1618
+ if (subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.batch) {
1619
+ const batchingOptions = subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.batchingOptions;
1620
+ executor = getBatchingExecutor(context, executor, batchingOptions === null || batchingOptions === void 0 ? void 0 : batchingOptions.dataLoaderOptions, batchingOptions === null || batchingOptions === void 0 ? void 0 : batchingOptions.extensionsReducer);
1621
1621
  }
1622
1622
  const executionResult = executor({
1623
1623
  ...processedRequest,
@@ -1631,7 +1631,7 @@ function delegateRequest({ request, schema: subschemaOrSubschemaConfig, rootValu
1631
1631
  }
1632
1632
  return transformer.transformResult(executionResult);
1633
1633
  }
1634
- const subscriber = (endpoint === null || endpoint === void 0 ? void 0 : endpoint.subscriber) || createDefaultSubscriber(targetSchema, (subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.rootValue) || targetRootValue);
1634
+ const subscriber = (subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.subscriber) || createDefaultSubscriber(targetSchema, (subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.rootValue) || targetRootValue);
1635
1635
  return subscriber({
1636
1636
  ...processedRequest,
1637
1637
  context,
@@ -1646,16 +1646,16 @@ function delegateRequest({ request, schema: subschemaOrSubschemaConfig, rootValu
1646
1646
  return transformer.transformResult(subscriptionResult);
1647
1647
  });
1648
1648
  }
1649
+ const emptyObject = {};
1649
1650
  function collectTargetParameters(subschema, rootValue, info, transforms = []) {
1650
- var _a, _b, _c, _d;
1651
+ var _a, _b, _c, _d, _e;
1651
1652
  const stitchingInfo = (_a = info === null || info === void 0 ? void 0 : info.schema.extensions) === null || _a === void 0 ? void 0 : _a.stitchingInfo;
1652
1653
  const subschemaOrSubschemaConfig = (_b = stitchingInfo === null || stitchingInfo === void 0 ? void 0 : stitchingInfo.subschemaMap.get(subschema)) !== null && _b !== void 0 ? _b : subschema;
1653
1654
  if (isSubschemaConfig(subschemaOrSubschemaConfig)) {
1654
1655
  return {
1655
1656
  targetSchema: subschemaOrSubschemaConfig.schema,
1656
- targetRootValue: (_c = rootValue !== null && rootValue !== void 0 ? rootValue : subschemaOrSubschemaConfig === null || subschemaOrSubschemaConfig === void 0 ? void 0 : subschemaOrSubschemaConfig.rootValue) !== null && _c !== void 0 ? _c : info === null || info === void 0 ? void 0 : info.rootValue,
1657
+ targetRootValue: (_d = (_c = rootValue !== null && rootValue !== void 0 ? rootValue : subschemaOrSubschemaConfig === null || subschemaOrSubschemaConfig === void 0 ? void 0 : subschemaOrSubschemaConfig.rootValue) !== null && _c !== void 0 ? _c : info === null || info === void 0 ? void 0 : info.rootValue) !== null && _d !== void 0 ? _d : emptyObject,
1657
1658
  subschemaConfig: subschemaOrSubschemaConfig,
1658
- endpoint: (_d = subschemaOrSubschemaConfig.endpoint) !== null && _d !== void 0 ? _d : subschemaOrSubschemaConfig,
1659
1659
  allTransforms: subschemaOrSubschemaConfig.transforms != null
1660
1660
  ? subschemaOrSubschemaConfig.transforms.concat(transforms)
1661
1661
  : transforms,
@@ -1663,7 +1663,7 @@ function collectTargetParameters(subschema, rootValue, info, transforms = []) {
1663
1663
  }
1664
1664
  return {
1665
1665
  targetSchema: subschemaOrSubschemaConfig,
1666
- targetRootValue: rootValue !== null && rootValue !== void 0 ? rootValue : info === null || info === void 0 ? void 0 : info.rootValue,
1666
+ targetRootValue: (_e = rootValue !== null && rootValue !== void 0 ? rootValue : info === null || info === void 0 ? void 0 : info.rootValue) !== null && _e !== void 0 ? _e : emptyObject,
1667
1667
  allTransforms: transforms,
1668
1668
  };
1669
1669
  }
@@ -1678,7 +1678,7 @@ function validateRequest(targetSchema, document) {
1678
1678
  throw error.originalError || error;
1679
1679
  }
1680
1680
  }
1681
- function createDefaultExecutor(schema, rootValue) {
1681
+ const createDefaultExecutor = memoize2(function (schema, rootValue) {
1682
1682
  return (({ document, context, variables, info }) => execute({
1683
1683
  schema,
1684
1684
  document,
@@ -1686,7 +1686,7 @@ function createDefaultExecutor(schema, rootValue) {
1686
1686
  variableValues: variables,
1687
1687
  rootValue: rootValue !== null && rootValue !== void 0 ? rootValue : info === null || info === void 0 ? void 0 : info.rootValue,
1688
1688
  }));
1689
- }
1689
+ });
1690
1690
  function createDefaultSubscriber(schema, rootValue) {
1691
1691
  return ({ document, context, variables, info }) => subscribe({
1692
1692
  schema,