@@ -668,6 +668,7 @@ function completeValue(
668
668
return completeAbstractValue (
669
669
exeContext ,
670
670
returnType ,
671
+ returnType ,
671
672
fieldNodes ,
672
673
info ,
673
674
path ,
@@ -792,93 +793,58 @@ function completeLeafValue(
792
793
function completeAbstractValue (
793
794
exeContext : ExecutionContext ,
794
795
returnType : GraphQLAbstractType ,
796
+ abstractType : GraphQLAbstractType ,
795
797
fieldNodes : ReadonlyArray < FieldNode > ,
796
798
info : GraphQLResolveInfo ,
797
799
path : Path ,
798
800
result : unknown ,
799
801
) : 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 (
806
805
result ,
806
+ contextValue ,
807
+ info ,
808
+ abstractType ,
807
809
) ;
808
810
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 (
823
812
exeContext ,
824
- runtimeType ,
813
+ returnType ,
814
+ abstractType ,
815
+ runtimeTypeName ,
825
816
fieldNodes ,
826
817
info ,
827
818
path ,
828
819
result ,
829
820
) ;
830
821
}
831
822
832
- function resolveType (
823
+ function resolveRuntimeTypeName (
833
824
exeContext : ExecutionContext ,
834
825
returnType : GraphQLAbstractType ,
835
- abstractType : GraphQLAbstractType ,
826
+ currentAbstractType : GraphQLAbstractType ,
827
+ runtimeTypeName : PromiseOrValue < string | undefined > ,
836
828
fieldNodes : ReadonlyArray < FieldNode > ,
837
829
info : GraphQLResolveInfo ,
830
+ path : Path ,
838
831
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 (
853
836
exeContext ,
854
837
returnType ,
855
- abstractType ,
838
+ currentAbstractType ,
839
+ resolved ,
856
840
fieldNodes ,
857
841
info ,
842
+ path ,
858
843
result ,
859
844
) ,
860
845
) ;
861
846
}
862
- return deriveRuntimeType (
863
- possibleRuntimeTypeName ,
864
- exeContext ,
865
- returnType ,
866
- abstractType ,
867
- fieldNodes ,
868
- info ,
869
- result ,
870
- ) ;
871
- }
872
847
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 > {
882
848
if ( runtimeTypeName == null ) {
883
849
throw new GraphQLError (
884
850
`Abstract type resolution for "${ returnType . name } " for field "${ info . parentType . name } .${ info . fieldName } " failed. ` +
@@ -922,13 +888,13 @@ function deriveRuntimeType(
922
888
{ nodes : fieldNodes } ,
923
889
) ;
924
890
}
925
-
926
- return resolveType (
891
+ return completeAbstractValue (
927
892
exeContext ,
928
893
returnType ,
929
894
runtimeType ,
930
895
fieldNodes ,
931
896
info ,
897
+ path ,
932
898
result ,
933
899
) ;
934
900
}
@@ -949,7 +915,14 @@ function deriveRuntimeType(
949
915
) ;
950
916
}
951
917
952
- return runtimeType ;
918
+ return completeObjectValue (
919
+ exeContext ,
920
+ runtimeType ,
921
+ fieldNodes ,
922
+ info ,
923
+ path ,
924
+ result ,
925
+ ) ;
953
926
}
954
927
955
928
/**
0 commit comments