@graphql-tools/delegate 8.5.0 → 8.5.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.js +7 -16
- package/index.mjs +7 -16
- package/mergeFields.d.ts +1 -1
- package/package.json +4 -4
- package/types.d.ts +2 -2
package/index.js
CHANGED
|
@@ -708,20 +708,21 @@ async function executeDelegationStage(mergedTypeInfo, delegationMap, object, con
|
|
|
708
708
|
const combinedErrors = object[UNPATHED_ERRORS_SYMBOL];
|
|
709
709
|
const path = graphql.responsePathAsArray(info.path);
|
|
710
710
|
const combinedFieldSubschemaMap = object[FIELD_SUBSCHEMA_MAP_SYMBOL];
|
|
711
|
-
|
|
712
|
-
await Promise.all([...delegationMap.entries()].map(async ([s, selectionSet]) => {
|
|
711
|
+
await Promise.all([...delegationMap.entries()].map(async ([subschema, selectionSet]) => {
|
|
713
712
|
var _a;
|
|
714
|
-
const
|
|
713
|
+
const schema = subschema.transformedSchema || info.schema;
|
|
714
|
+
const type = schema.getType(object.__typename);
|
|
715
|
+
const resolver = mergedTypeInfo.resolvers.get(subschema);
|
|
715
716
|
if (resolver) {
|
|
716
717
|
let source;
|
|
717
718
|
try {
|
|
718
|
-
source = await resolver(object, context, info,
|
|
719
|
+
source = await resolver(object, context, info, subschema, selectionSet, undefined, type);
|
|
719
720
|
}
|
|
720
721
|
catch (error) {
|
|
721
722
|
source = error;
|
|
722
723
|
}
|
|
723
724
|
if (source instanceof Error || source == null) {
|
|
724
|
-
const fieldNodeResponseKeyMap = utils.collectFields(
|
|
725
|
+
const fieldNodeResponseKeyMap = utils.collectFields(schema, EMPTY_OBJECT, EMPTY_OBJECT, type, selectionSet, new Map(), new Set());
|
|
725
726
|
const nullResult = {};
|
|
726
727
|
for (const [responseKey, fieldNodes] of fieldNodeResponseKeyMap) {
|
|
727
728
|
const combinedPath = [...path, responseKey];
|
|
@@ -784,17 +785,7 @@ function resolveExternalObject(type, object, unpathedErrors, subschema, context,
|
|
|
784
785
|
if (stitchingInfo == null) {
|
|
785
786
|
return object;
|
|
786
787
|
}
|
|
787
|
-
|
|
788
|
-
if (graphql.isAbstractType(type)) {
|
|
789
|
-
const resolvedType = info.schema.getType(object.__typename);
|
|
790
|
-
if (resolvedType == null) {
|
|
791
|
-
throw new Error(`Unable to resolve type '${object.__typename}'. Did you forget to include a transform that renames types? Did you delegate to the original subschema rather that the subschema config object containing the transform?`);
|
|
792
|
-
}
|
|
793
|
-
typeName = resolvedType.name;
|
|
794
|
-
}
|
|
795
|
-
else {
|
|
796
|
-
typeName = type.name;
|
|
797
|
-
}
|
|
788
|
+
const typeName = graphql.isAbstractType(type) ? object.__typename : type.name;
|
|
798
789
|
const mergedTypeInfo = stitchingInfo.mergedTypes[typeName];
|
|
799
790
|
let targetSubschemas;
|
|
800
791
|
// Within the stitching context, delegation to a stitched GraphQLSchema or SubschemaConfig
|
package/index.mjs
CHANGED
|
@@ -704,20 +704,21 @@ async function executeDelegationStage(mergedTypeInfo, delegationMap, object, con
|
|
|
704
704
|
const combinedErrors = object[UNPATHED_ERRORS_SYMBOL];
|
|
705
705
|
const path = responsePathAsArray(info.path);
|
|
706
706
|
const combinedFieldSubschemaMap = object[FIELD_SUBSCHEMA_MAP_SYMBOL];
|
|
707
|
-
|
|
708
|
-
await Promise.all([...delegationMap.entries()].map(async ([s, selectionSet]) => {
|
|
707
|
+
await Promise.all([...delegationMap.entries()].map(async ([subschema, selectionSet]) => {
|
|
709
708
|
var _a;
|
|
710
|
-
const
|
|
709
|
+
const schema = subschema.transformedSchema || info.schema;
|
|
710
|
+
const type = schema.getType(object.__typename);
|
|
711
|
+
const resolver = mergedTypeInfo.resolvers.get(subschema);
|
|
711
712
|
if (resolver) {
|
|
712
713
|
let source;
|
|
713
714
|
try {
|
|
714
|
-
source = await resolver(object, context, info,
|
|
715
|
+
source = await resolver(object, context, info, subschema, selectionSet, undefined, type);
|
|
715
716
|
}
|
|
716
717
|
catch (error) {
|
|
717
718
|
source = error;
|
|
718
719
|
}
|
|
719
720
|
if (source instanceof Error || source == null) {
|
|
720
|
-
const fieldNodeResponseKeyMap = collectFields(
|
|
721
|
+
const fieldNodeResponseKeyMap = collectFields(schema, EMPTY_OBJECT, EMPTY_OBJECT, type, selectionSet, new Map(), new Set());
|
|
721
722
|
const nullResult = {};
|
|
722
723
|
for (const [responseKey, fieldNodes] of fieldNodeResponseKeyMap) {
|
|
723
724
|
const combinedPath = [...path, responseKey];
|
|
@@ -780,17 +781,7 @@ function resolveExternalObject(type, object, unpathedErrors, subschema, context,
|
|
|
780
781
|
if (stitchingInfo == null) {
|
|
781
782
|
return object;
|
|
782
783
|
}
|
|
783
|
-
|
|
784
|
-
if (isAbstractType(type)) {
|
|
785
|
-
const resolvedType = info.schema.getType(object.__typename);
|
|
786
|
-
if (resolvedType == null) {
|
|
787
|
-
throw new Error(`Unable to resolve type '${object.__typename}'. Did you forget to include a transform that renames types? Did you delegate to the original subschema rather that the subschema config object containing the transform?`);
|
|
788
|
-
}
|
|
789
|
-
typeName = resolvedType.name;
|
|
790
|
-
}
|
|
791
|
-
else {
|
|
792
|
-
typeName = type.name;
|
|
793
|
-
}
|
|
784
|
+
const typeName = isAbstractType(type) ? object.__typename : type.name;
|
|
794
785
|
const mergedTypeInfo = stitchingInfo.mergedTypes[typeName];
|
|
795
786
|
let targetSubschemas;
|
|
796
787
|
// Within the stitching context, delegation to a stitched GraphQLSchema or SubschemaConfig
|
package/mergeFields.d.ts
CHANGED
|
@@ -5,4 +5,4 @@ export declare function isExternalObject(data: any): data is ExternalObject;
|
|
|
5
5
|
export declare function annotateExternalObject<TContext>(object: any, errors: Array<GraphQLError>, subschema: GraphQLSchema | SubschemaConfig<any, any, any, TContext> | undefined, subschemaMap: Record<string, GraphQLSchema | SubschemaConfig<any, any, any, Record<string, any>>>): ExternalObject;
|
|
6
6
|
export declare function getSubschema(object: ExternalObject, responseKey: string): GraphQLSchema | SubschemaConfig;
|
|
7
7
|
export declare function getUnpathedErrors(object: ExternalObject): Array<GraphQLError>;
|
|
8
|
-
export declare function mergeFields(mergedTypeInfo: MergedTypeInfo, object: any, sourceSubschema: Subschema<any, any, any,
|
|
8
|
+
export declare function mergeFields<TContext>(mergedTypeInfo: MergedTypeInfo, object: any, sourceSubschema: Subschema<any, any, any, TContext>, context: any, info: GraphQLResolveInfo): Promise<any>;
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/delegate",
|
|
3
|
-
"version": "8.5.
|
|
3
|
+
"version": "8.5.3",
|
|
4
4
|
"description": "A set of utils for faster development of GraphQL tools",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@graphql-tools/batch-execute": "^8.3.
|
|
11
|
-
"@graphql-tools/schema": "^8.3.
|
|
12
|
-
"@graphql-tools/utils": "^8.
|
|
10
|
+
"@graphql-tools/batch-execute": "^8.3.2",
|
|
11
|
+
"@graphql-tools/schema": "^8.3.2",
|
|
12
|
+
"@graphql-tools/utils": "^8.6.2",
|
|
13
13
|
"dataloader": "2.0.0",
|
|
14
14
|
"graphql-executor": "0.0.18",
|
|
15
15
|
"tslib": "~2.3.0",
|
package/types.d.ts
CHANGED
|
@@ -118,7 +118,7 @@ export interface MergedTypeConfig<K = any, V = any, TContext = Record<string, an
|
|
|
118
118
|
}
|
|
119
119
|
export interface MergedTypeEntryPoint<K = any, V = any, TContext = Record<string, any>> extends MergedTypeResolverOptions<K, V> {
|
|
120
120
|
selectionSet?: string;
|
|
121
|
-
key?: (originalResult: any) => K
|
|
121
|
+
key?: (originalResult: any) => K | PromiseLike<K>;
|
|
122
122
|
resolve?: MergedTypeResolver<TContext>;
|
|
123
123
|
}
|
|
124
124
|
export interface MergedTypeResolverOptions<K = any, V = any> {
|
|
@@ -132,7 +132,7 @@ export interface MergedFieldConfig {
|
|
|
132
132
|
computed?: boolean;
|
|
133
133
|
canonical?: boolean;
|
|
134
134
|
}
|
|
135
|
-
export declare type MergedTypeResolver<TContext = Record<string, any>> = (originalResult: any, context: TContext, info: GraphQLResolveInfo, subschema:
|
|
135
|
+
export declare type MergedTypeResolver<TContext = Record<string, any>> = (originalResult: any, context: TContext, info: GraphQLResolveInfo, subschema: Subschema<any, any, any, TContext>, selectionSet: SelectionSetNode, key: any | undefined, type: GraphQLOutputType) => any;
|
|
136
136
|
export interface StitchingInfo<TContext = Record<string, any>> {
|
|
137
137
|
subschemaMap: Map<GraphQLSchema | SubschemaConfig<any, any, any, TContext>, Subschema<any, any, any, TContext>>;
|
|
138
138
|
fieldNodesByType: Record<string, Array<FieldNode>>;
|