@graphql-tools/delegate 7.0.3 → 7.0.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/delegate/es5",
3
- "version": "7.0.3",
3
+ "version": "7.0.5",
4
4
  "description": "A set of utils for faster development of GraphQL tools",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
package/es5/types.d.ts CHANGED
@@ -77,6 +77,7 @@ export interface MergedTypeInfo {
77
77
  typeMaps: Map<GraphQLSchema | SubschemaConfig, TypeMap>;
78
78
  selectionSets: Map<Subschema, SelectionSetNode>;
79
79
  fieldSelectionSets: Map<Subschema, Record<string, SelectionSetNode>>;
80
+ resolvers: Map<Subschema, MergedTypeResolver>;
80
81
  }
81
82
  export interface ExecutionParams<TArgs = Record<string, any>, TContext = any> {
82
83
  document: DocumentNode;
@@ -111,7 +112,7 @@ export interface SubschemaConfig<K = any, V = any, C = K> {
111
112
  batch?: boolean;
112
113
  batchingOptions?: BatchingOptions<K, V, C>;
113
114
  }
114
- export interface MergedTypeConfig<K = any, V = any> {
115
+ export interface MergedTypeConfig<K = any, V = any> extends MergedTypeResolverOptions<K, V> {
115
116
  selectionSet?: string;
116
117
  fields?: Record<string, {
117
118
  selectionSet?: string;
@@ -119,17 +120,19 @@ export interface MergedTypeConfig<K = any, V = any> {
119
120
  computedFields?: Record<string, {
120
121
  selectionSet?: string;
121
122
  }>;
123
+ key?: (originalResult: any) => K;
122
124
  resolve?: MergedTypeResolver;
125
+ }
126
+ export interface MergedTypeResolverOptions<K = any, V = any> {
123
127
  fieldName?: string;
124
128
  args?: (originalResult: any) => Record<string, any>;
125
- key?: (originalResult: any) => K;
126
129
  argsFromKeys?: (keys: ReadonlyArray<K>) => Record<string, any>;
127
130
  valuesFromResults?: (results: any, keys: ReadonlyArray<K>) => Array<V>;
128
131
  }
129
132
  export interface MergedFieldConfig {
130
133
  selectionSet?: string;
131
134
  }
132
- export declare type MergedTypeResolver = (originalResult: any, context: Record<string, any>, info: GraphQLResolveInfo, subschema: GraphQLSchema | SubschemaConfig, selectionSet: SelectionSetNode) => any;
135
+ export declare type MergedTypeResolver = (originalResult: any, context: Record<string, any>, info: GraphQLResolveInfo, subschema: GraphQLSchema | SubschemaConfig, selectionSet: SelectionSetNode, key?: any) => any;
133
136
  export interface StitchingInfo {
134
137
  subschemaMap: Map<GraphQLSchema | SubschemaConfig, Subschema>;
135
138
  selectionSetsByField: Record<string, Record<string, SelectionSetNode>>;
package/index.cjs.js CHANGED
@@ -6,8 +6,8 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
6
6
 
7
7
  const utils = require('@graphql-tools/utils');
8
8
  const graphql = require('graphql');
9
+ const AggregateError = _interopDefault(require('@ardatan/aggregate-error'));
9
10
  const isPromise = _interopDefault(require('is-promise'));
10
- const AggregateError$1 = _interopDefault(require('@ardatan/aggregate-error'));
11
11
  const batchExecute = require('@graphql-tools/batch-execute');
12
12
 
13
13
  function applySchemaTransforms(originalWrappingSchema, subschemaConfig, transformedSchema) {
@@ -566,7 +566,8 @@ function mergeFields(mergedTypeInfo, typeName, object, fieldNodes, sourceSubsche
566
566
  let containsPromises = false;
567
567
  const resultMap = new Map();
568
568
  delegationMap.forEach((selectionSet, s) => {
569
- const maybePromise = s.merge[typeName].resolve(object, context, info, s, selectionSet);
569
+ const resolver = mergedTypeInfo.resolvers.get(s);
570
+ const maybePromise = resolver(object, context, info, s, selectionSet);
570
571
  resultMap.set(maybePromise, selectionSet);
571
572
  if (isPromise(maybePromise)) {
572
573
  containsPromises = true;
@@ -1396,7 +1397,7 @@ function mergeDataAndErrors(data, errors, path, index = 1) {
1396
1397
  const newPath = path === undefined ? error.path : error.path === undefined ? path : path.concat(error.path.slice(1));
1397
1398
  return { data: utils.relocatedError(errors[0], newPath), unpathedErrors: [] };
1398
1399
  }
1399
- return { data: graphql.locatedError(new AggregateError$1(errors), undefined, path), unpathedErrors: [] };
1400
+ return { data: graphql.locatedError(new AggregateError(errors), undefined, path), unpathedErrors: [] };
1400
1401
  }
1401
1402
  if (!errors.length) {
1402
1403
  return { data, unpathedErrors: [] };
@@ -1697,7 +1698,7 @@ function validateRequest(targetSchema, document) {
1697
1698
  const errors = graphql.validate(targetSchema, document);
1698
1699
  if (errors.length > 0) {
1699
1700
  if (errors.length > 1) {
1700
- const combinedError = new AggregateError$1(errors);
1701
+ const combinedError = new AggregateError(errors);
1701
1702
  throw combinedError;
1702
1703
  }
1703
1704
  const error = errors[0];