@@ -941,30 +941,24 @@ function completeAbstractValue(
941
941
result: mixed
942
942
): mixed {
943
943
const runtimeType = returnType . resolveType ?
944
- returnType . resolveType (
945
- result ,
946
- exeContext . contextValue ,
947
- info
948
- ) :
949
- defaultResolveTypeFn (
950
- result ,
951
- exeContext . contextValue ,
952
- info ,
953
- returnType
954
- ) ;
944
+ returnType . resolveType ( result , exeContext . contextValue , info ) :
945
+ defaultResolveTypeFn ( result , exeContext . contextValue , info , returnType ) ;
955
946
956
947
if ( isThenable ( runtimeType ) ) {
957
- return ( ( runtimeType : any ) : Promise < * > ) . then ( resolvedRuntimeType => (
948
+ // Cast to Promise
949
+ const runtimeTypePromise : Promise < GraphQLObjectType | string > =
950
+ ( runtimeType : any ) ;
951
+ return runtimeTypePromise . then ( resolvedRuntimeType =>
958
952
validateRuntimeTypeAndCompleteObjectValue (
959
953
exeContext ,
960
954
returnType ,
961
955
fieldNodes ,
962
956
info ,
963
957
path ,
964
- resolvedRuntimeType ,
958
+ ensureType ( exeContext . schema , resolvedRuntimeType ) ,
965
959
result
966
960
)
967
- ) ) ;
961
+ ) ;
968
962
}
969
963
970
964
return validateRuntimeTypeAndCompleteObjectValue (
@@ -973,27 +967,29 @@ function completeAbstractValue(
973
967
fieldNodes ,
974
968
info ,
975
969
path ,
976
- runtimeType,
970
+ ensureType ( exeContext . schema , runtimeType ) ,
977
971
result
978
972
) ;
979
973
}
980
974
975
+ function ensureType(
976
+ schema: GraphQLSchema,
977
+ typeOrName: string | GraphQLObjectType
978
+ ): GraphQLObjectType {
979
+ return typeof typeOrName === 'string' ?
980
+ schema . getType ( typeOrName ) :
981
+ typeOrName ;
982
+ }
983
+
981
984
function validateRuntimeTypeAndCompleteObjectValue(
982
985
exeContext: ExecutionContext,
983
986
returnType: GraphQLAbstractType,
984
987
fieldNodes: Array< FieldNode > ,
985
988
info: GraphQLResolveInfo,
986
989
path: ResponsePath,
987
- returnedRuntimeType: mixed ,
990
+ runtimeType: GraphQLObjectType ,
988
991
result: mixed
989
992
): mixed {
990
- let runtimeType = returnedRuntimeType ;
991
-
992
- // If resolveType returns a string, we assume it's a GraphQLObjectType name.
993
- if ( typeof runtimeType === 'string' ) {
994
- runtimeType = exeContext . schema . getType ( runtimeType ) ;
995
- }
996
-
997
993
if ( ! ( runtimeType instanceof GraphQLObjectType ) ) {
998
994
throw new GraphQLError (
999
995
`Abstract type ${ returnType . name } must resolve to an Object type at ` +
@@ -1087,16 +1083,14 @@ function validateResultTypeAndExecuteFields(
1087
1083
// rather than continuing execution.
1088
1084
if ( ! isTypeOfResult ) {
1089
1085
throw new GraphQLError (
1090
- `Expected value of type "${ returnType . name } " ` +
1091
- `but got: ${ String ( result ) } .` ,
1086
+ `Expected value of type "${ returnType . name } " but got: ${ String ( result ) } .` ,
1092
1087
fieldNodes
1093
1088
) ;
1094
1089
}
1095
1090
1096
1091
// Collect sub-fields to execute to complete this value.
1097
1092
let subFieldNodes = Object.create(null);
1098
1093
const visitedFragmentNames = Object.create(null);
1099
-
1100
1094
for (let i = 0; i < fieldNodes . length ; i ++ ) {
1101
1095
const selectionSet = fieldNodes [ i ] . selectionSet ;
1102
1096
if ( selectionSet ) {
@@ -1122,7 +1116,7 @@ function defaultResolveTypeFn(
1122
1116
value : mixed ,
1123
1117
context : mixed ,
1124
1118
info : GraphQLResolveInfo ,
1125
- abstractType : GraphQLAbstractType ,
1119
+ abstractType : GraphQLAbstractType
1126
1120
) : ?GraphQLObjectType | ?Promise < ?GraphQLObjectType > {
1127
1121
const possibleTypes = info . schema . getPossibleTypes ( abstractType ) ;
1128
1122
const promisedIsTypeOfResults = [ ] ;
0 commit comments