@@ -25,6 +25,7 @@ import {
25
25
} from '../type/definition' ;
26
26
import type {
27
27
GraphQLType ,
28
+ GraphQLLeafType ,
28
29
GraphQLAbstractType ,
29
30
GraphQLFieldDefinition ,
30
31
GraphQLResolveInfo ,
@@ -701,9 +702,7 @@ function completeValue(
701
702
// null if serialization is not possible.
702
703
if (returnType instanceof GraphQLScalarType ||
703
704
returnType instanceof GraphQLEnumType) {
704
- invariant ( returnType . serialize , 'Missing serialize method on type' ) ;
705
- const serializedResult = returnType . serialize ( result ) ;
706
- return isNullish ( serializedResult ) ? null : serializedResult ;
705
+ return completeLeafValue ( exeContext , returnType , fieldASTs , info , result ) ;
707
706
}
708
707
709
708
// Field type must be Object, Interface or Union and expect sub-selections.
@@ -789,6 +788,22 @@ function completeListValue(
789
788
return containsPromise ? Promise . all ( completedResults ) : completedResults ;
790
789
}
791
790
791
+ /**
792
+ * Complete a Scalar or Enum by serializing to a valid value, returning
793
+ * null if serialization is not possible.
794
+ */
795
+ function completeLeafValue(
796
+ exeContext: ExecutionContext,
797
+ returnType: GraphQLLeafType,
798
+ fieldASTs: Array< Field > ,
799
+ info: GraphQLResolveInfo,
800
+ result: mixed
801
+ ): mixed {
802
+ invariant ( returnType . serialize , 'Missing serialize method on type' ) ;
803
+ const serializedResult = returnType . serialize ( result ) ;
804
+ return isNullish ( serializedResult ) ? null : serializedResult ;
805
+ }
806
+
792
807
/**
793
808
* If a resolve function is not given, then a default resolve behavior is used
794
809
* which takes the property of the source object of the same name as the field
0 commit comments