@@ -798,7 +798,13 @@ function completeAbstractValue(
798798 info: GraphQLResolveInfo,
799799 result: mixed
800800): mixed {
801- const runtimeType = returnType . getObjectType ( result , info ) ;
801+ let runtimeType : ?GraphQLObjectType ;
802+ if ( returnType . resolveType ) {
803+ runtimeType = returnType . resolveType ( result , info ) ;
804+ } else {
805+ runtimeType = defaultResolveTypeFn ( result , info , returnType ) ;
806+ }
807+
802808 if ( runtimeType && ! returnType . isPossibleType ( runtimeType ) ) {
803809 throw new GraphQLError (
804810 `Runtime Object type "${ runtimeType } " is not a possible type ` +
@@ -859,6 +865,25 @@ function completeObjectValue(
859865 return executeFields ( exeContext , returnType , result , subFieldASTs ) ;
860866}
861867
868+ /**
869+ * If a resolveType function is not given, then a default resolve behavior is
870+ * used which tests each possible type for the abstract type by calling
871+ * isTypeOf for the object being coerced, returning the first type that matches.
872+ */
873+ function defaultResolveTypeFn (
874+ value : mixed ,
875+ info : GraphQLResolveInfo ,
876+ abstractType : GraphQLAbstractType
877+ ) : ?GraphQLObjectType {
878+ const possibleTypes = abstractType . getPossibleTypes ( ) ;
879+ for ( let i = 0 ; i < possibleTypes . length ; i ++ ) {
880+ const type = possibleTypes [ i ] ;
881+ if ( typeof type . isTypeOf === 'function' && type . isTypeOf ( value , info ) ) {
882+ return type ;
883+ }
884+ }
885+ }
886+
862887/**
863888 * If a resolve function is not given, then a default resolve behavior is used
864889 * which takes the property of the source object of the same name as the field
0 commit comments