Skip to content

Commit 702bc07

Browse files
IvanGoncharovyaacovCR
authored andcommitted
review change
1 parent 4d153df commit 702bc07

File tree

1 file changed

+33
-60
lines changed

1 file changed

+33
-60
lines changed

src/execution/execute.ts

+33-60
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ function completeValue(
672672
return completeAbstractValue(
673673
exeContext,
674674
returnType,
675+
returnType,
675676
fieldNodes,
676677
info,
677678
path,
@@ -796,93 +797,58 @@ function completeLeafValue(
796797
function completeAbstractValue(
797798
exeContext: ExecutionContext,
798799
returnType: GraphQLAbstractType,
800+
abstractType: GraphQLAbstractType,
799801
fieldNodes: ReadonlyArray<FieldNode>,
800802
info: GraphQLResolveInfo,
801803
path: Path,
802804
result: unknown,
803805
): PromiseOrValue<ObjMap<unknown>> {
804-
const runtimeType = resolveType(
805-
exeContext,
806-
returnType,
807-
returnType,
808-
fieldNodes,
809-
info,
806+
const resolveTypeFn = abstractType.resolveType ?? exeContext.typeResolver;
807+
const contextValue = exeContext.contextValue;
808+
const runtimeTypeName = resolveTypeFn(
810809
result,
810+
contextValue,
811+
info,
812+
abstractType,
811813
);
812814

813-
if (isPromise(runtimeType)) {
814-
return runtimeType.then((resolvedRuntimeType) =>
815-
completeObjectValue(
816-
exeContext,
817-
resolvedRuntimeType,
818-
fieldNodes,
819-
info,
820-
path,
821-
result,
822-
),
823-
);
824-
}
825-
826-
return completeObjectValue(
815+
return resolveRuntimeTypeName(
827816
exeContext,
828-
runtimeType,
817+
returnType,
818+
abstractType,
819+
runtimeTypeName,
829820
fieldNodes,
830821
info,
831822
path,
832823
result,
833824
);
834825
}
835826

836-
function resolveType(
827+
function resolveRuntimeTypeName(
837828
exeContext: ExecutionContext,
838829
returnType: GraphQLAbstractType,
839-
abstractType: GraphQLAbstractType,
830+
currentAbstractType: GraphQLAbstractType,
831+
runtimeTypeName: PromiseOrValue<string | undefined>,
840832
fieldNodes: ReadonlyArray<FieldNode>,
841833
info: GraphQLResolveInfo,
834+
path: Path,
842835
result: unknown,
843-
): GraphQLObjectType | Promise<GraphQLObjectType> {
844-
const resolveTypeFn = abstractType.resolveType ?? exeContext.typeResolver;
845-
const contextValue = exeContext.contextValue;
846-
const possibleRuntimeTypeName = resolveTypeFn(
847-
result,
848-
contextValue,
849-
info,
850-
abstractType,
851-
);
852-
853-
if (isPromise(possibleRuntimeTypeName)) {
854-
return possibleRuntimeTypeName.then((resolvedPossibleRuntimeTypeName) =>
855-
deriveRuntimeType(
856-
resolvedPossibleRuntimeTypeName,
836+
): PromiseOrValue<ObjMap<unknown>> {
837+
if (isPromise(runtimeTypeName)) {
838+
return runtimeTypeName.then((resolved) =>
839+
resolveRuntimeTypeName(
857840
exeContext,
858841
returnType,
859-
abstractType,
842+
currentAbstractType,
843+
resolved,
860844
fieldNodes,
861845
info,
846+
path,
862847
result,
863848
),
864849
);
865850
}
866-
return deriveRuntimeType(
867-
possibleRuntimeTypeName,
868-
exeContext,
869-
returnType,
870-
abstractType,
871-
fieldNodes,
872-
info,
873-
result,
874-
);
875-
}
876851

877-
function deriveRuntimeType(
878-
runtimeTypeName: unknown,
879-
exeContext: ExecutionContext,
880-
returnType: GraphQLAbstractType,
881-
currentAbstractType: GraphQLAbstractType,
882-
fieldNodes: ReadonlyArray<FieldNode>,
883-
info: GraphQLResolveInfo,
884-
result: unknown,
885-
): GraphQLObjectType | Promise<GraphQLObjectType> {
886852
if (runtimeTypeName == null) {
887853
throw new GraphQLError(
888854
`Abstract type resolution for "${returnType.name}" for field "${info.parentType.name}.${info.fieldName}" failed. ` +
@@ -926,13 +892,13 @@ function deriveRuntimeType(
926892
{ nodes: fieldNodes },
927893
);
928894
}
929-
930-
return resolveType(
895+
return completeAbstractValue(
931896
exeContext,
932897
returnType,
933898
runtimeType,
934899
fieldNodes,
935900
info,
901+
path,
936902
result,
937903
);
938904
}
@@ -953,7 +919,14 @@ function deriveRuntimeType(
953919
);
954920
}
955921

956-
return runtimeType;
922+
return completeObjectValue(
923+
exeContext,
924+
runtimeType,
925+
fieldNodes,
926+
info,
927+
path,
928+
result,
929+
);
957930
}
958931

959932
/**

0 commit comments

Comments
 (0)