@@ -672,6 +672,7 @@ function completeValue(
672
672
return completeAbstractValue (
673
673
exeContext ,
674
674
returnType ,
675
+ returnType ,
675
676
fieldNodes ,
676
677
info ,
677
678
path ,
@@ -796,93 +797,58 @@ function completeLeafValue(
796
797
function completeAbstractValue (
797
798
exeContext : ExecutionContext ,
798
799
returnType : GraphQLAbstractType ,
800
+ abstractType : GraphQLAbstractType ,
799
801
fieldNodes : ReadonlyArray < FieldNode > ,
800
802
info : GraphQLResolveInfo ,
801
803
path : Path ,
802
804
result : unknown ,
803
805
) : 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 (
810
809
result ,
810
+ contextValue ,
811
+ info ,
812
+ abstractType ,
811
813
) ;
812
814
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 (
827
816
exeContext ,
828
- runtimeType ,
817
+ returnType ,
818
+ abstractType ,
819
+ runtimeTypeName ,
829
820
fieldNodes ,
830
821
info ,
831
822
path ,
832
823
result ,
833
824
) ;
834
825
}
835
826
836
- function resolveType (
827
+ function resolveRuntimeTypeName (
837
828
exeContext : ExecutionContext ,
838
829
returnType : GraphQLAbstractType ,
839
- abstractType : GraphQLAbstractType ,
830
+ currentAbstractType : GraphQLAbstractType ,
831
+ runtimeTypeName : PromiseOrValue < string | undefined > ,
840
832
fieldNodes : ReadonlyArray < FieldNode > ,
841
833
info : GraphQLResolveInfo ,
834
+ path : Path ,
842
835
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 (
857
840
exeContext ,
858
841
returnType ,
859
- abstractType ,
842
+ currentAbstractType ,
843
+ resolved ,
860
844
fieldNodes ,
861
845
info ,
846
+ path ,
862
847
result ,
863
848
) ,
864
849
) ;
865
850
}
866
- return deriveRuntimeType (
867
- possibleRuntimeTypeName ,
868
- exeContext ,
869
- returnType ,
870
- abstractType ,
871
- fieldNodes ,
872
- info ,
873
- result ,
874
- ) ;
875
- }
876
851
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 > {
886
852
if ( runtimeTypeName == null ) {
887
853
throw new GraphQLError (
888
854
`Abstract type resolution for "${ returnType . name } " for field "${ info . parentType . name } .${ info . fieldName } " failed. ` +
@@ -926,13 +892,13 @@ function deriveRuntimeType(
926
892
{ nodes : fieldNodes } ,
927
893
) ;
928
894
}
929
-
930
- return resolveType (
895
+ return completeAbstractValue (
931
896
exeContext ,
932
897
returnType ,
933
898
runtimeType ,
934
899
fieldNodes ,
935
900
info ,
901
+ path ,
936
902
result ,
937
903
) ;
938
904
}
@@ -953,7 +919,14 @@ function deriveRuntimeType(
953
919
) ;
954
920
}
955
921
956
- return runtimeType ;
922
+ return completeObjectValue (
923
+ exeContext ,
924
+ runtimeType ,
925
+ fieldNodes ,
926
+ info ,
927
+ path ,
928
+ result ,
929
+ ) ;
957
930
}
958
931
959
932
/**
0 commit comments