@@ -668,6 +668,7 @@ function completeValue(
668668 return completeAbstractValue (
669669 exeContext ,
670670 returnType ,
671+ returnType ,
671672 fieldNodes ,
672673 info ,
673674 path ,
@@ -792,93 +793,58 @@ function completeLeafValue(
792793function completeAbstractValue (
793794 exeContext : ExecutionContext ,
794795 returnType : GraphQLAbstractType ,
796+ abstractType : GraphQLAbstractType ,
795797 fieldNodes : ReadonlyArray < FieldNode > ,
796798 info : GraphQLResolveInfo ,
797799 path : Path ,
798800 result : unknown ,
799801) : PromiseOrValue < ObjMap < unknown > > {
800- const runtimeType = resolveType (
801- exeContext ,
802- returnType ,
803- returnType ,
804- fieldNodes ,
805- info ,
802+ const resolveTypeFn = abstractType . resolveType ?? exeContext . typeResolver ;
803+ const contextValue = exeContext . contextValue ;
804+ const runtimeTypeName = resolveTypeFn (
806805 result ,
806+ contextValue ,
807+ info ,
808+ abstractType ,
807809 ) ;
808810
809- if ( isPromise ( runtimeType ) ) {
810- return runtimeType . then ( ( resolvedRuntimeType ) =>
811- completeObjectValue (
812- exeContext ,
813- resolvedRuntimeType ,
814- fieldNodes ,
815- info ,
816- path ,
817- result ,
818- ) ,
819- ) ;
820- }
821-
822- return completeObjectValue (
811+ return resolveRuntimeTypeName (
823812 exeContext ,
824- runtimeType ,
813+ returnType ,
814+ abstractType ,
815+ runtimeTypeName ,
825816 fieldNodes ,
826817 info ,
827818 path ,
828819 result ,
829820 ) ;
830821}
831822
832- function resolveType (
823+ function resolveRuntimeTypeName (
833824 exeContext : ExecutionContext ,
834825 returnType : GraphQLAbstractType ,
835- abstractType : GraphQLAbstractType ,
826+ currentAbstractType : GraphQLAbstractType ,
827+ runtimeTypeName : PromiseOrValue < string | undefined > ,
836828 fieldNodes : ReadonlyArray < FieldNode > ,
837829 info : GraphQLResolveInfo ,
830+ path : Path ,
838831 result : unknown ,
839- ) : GraphQLObjectType | Promise < GraphQLObjectType > {
840- const resolveTypeFn = abstractType . resolveType ?? exeContext . typeResolver ;
841- const contextValue = exeContext . contextValue ;
842- const possibleRuntimeTypeName = resolveTypeFn (
843- result ,
844- contextValue ,
845- info ,
846- abstractType ,
847- ) ;
848-
849- if ( isPromise ( possibleRuntimeTypeName ) ) {
850- return possibleRuntimeTypeName . then ( ( resolvedPossibleRuntimeTypeName ) =>
851- deriveRuntimeType (
852- resolvedPossibleRuntimeTypeName ,
832+ ) : PromiseOrValue < ObjMap < unknown > > {
833+ if ( isPromise ( runtimeTypeName ) ) {
834+ return runtimeTypeName . then ( ( resolved ) =>
835+ resolveRuntimeTypeName (
853836 exeContext ,
854837 returnType ,
855- abstractType ,
838+ currentAbstractType ,
839+ resolved ,
856840 fieldNodes ,
857841 info ,
842+ path ,
858843 result ,
859844 ) ,
860845 ) ;
861846 }
862- return deriveRuntimeType (
863- possibleRuntimeTypeName ,
864- exeContext ,
865- returnType ,
866- abstractType ,
867- fieldNodes ,
868- info ,
869- result ,
870- ) ;
871- }
872847
873- function deriveRuntimeType (
874- runtimeTypeName : unknown ,
875- exeContext : ExecutionContext ,
876- returnType : GraphQLAbstractType ,
877- currentAbstractType : GraphQLAbstractType ,
878- fieldNodes : ReadonlyArray < FieldNode > ,
879- info : GraphQLResolveInfo ,
880- result : unknown ,
881- ) : GraphQLObjectType | Promise < GraphQLObjectType > {
882848 if ( runtimeTypeName == null ) {
883849 throw new GraphQLError (
884850 `Abstract type resolution for "${ returnType . name } " for field "${ info . parentType . name } .${ info . fieldName } " failed. ` +
@@ -922,13 +888,13 @@ function deriveRuntimeType(
922888 { nodes : fieldNodes } ,
923889 ) ;
924890 }
925-
926- return resolveType (
891+ return completeAbstractValue (
927892 exeContext ,
928893 returnType ,
929894 runtimeType ,
930895 fieldNodes ,
931896 info ,
897+ path ,
932898 result ,
933899 ) ;
934900 }
@@ -949,7 +915,14 @@ function deriveRuntimeType(
949915 ) ;
950916 }
951917
952- return runtimeType ;
918+ return completeObjectValue (
919+ exeContext ,
920+ runtimeType ,
921+ fieldNodes ,
922+ info ,
923+ path ,
924+ result ,
925+ ) ;
953926}
954927
955928/**
0 commit comments