@@ -651,12 +651,11 @@ export class GraphQLObjectType {
651
651
this . _fields = defineFieldMap . bind ( undefined , config ) ;
652
652
this . _interfaces = defineInterfaces . bind ( undefined , config ) ;
653
653
invariant ( typeof config . name === 'string' , 'Must provide name.' ) ;
654
- if ( config . isTypeOf ) {
655
- invariant (
656
- typeof config . isTypeOf === 'function' ,
657
- `${ this . name } must provide "isTypeOf" as a function.` ,
658
- ) ;
659
- }
654
+ invariant (
655
+ isMaybeFunction ( config . isTypeOf ) ,
656
+ `${ this . name } must provide "isTypeOf" as a function, ` +
657
+ `but got: ${ inspect ( config . isTypeOf ) } .` ,
658
+ ) ;
660
659
}
661
660
662
661
getFields ( ) : GraphQLFieldMap < * , * > {
@@ -724,7 +723,7 @@ function defineFieldMap<TSource, TContext>(
724
723
name : fieldName ,
725
724
} ;
726
725
invariant (
727
- isValidResolver ( field . resolve ) ,
726
+ isMaybeFunction ( field . resolve ) ,
728
727
`${config . name } . $ { fieldName } field resolver must be a function if ` +
729
728
`provided, but got: ${ inspect ( field . resolve ) } .` ,
730
729
) ;
@@ -757,8 +756,8 @@ function isPlainObj(obj) {
757
756
return obj && typeof obj === 'object' && ! Array . isArray ( obj ) ;
758
757
}
759
758
760
- // If a resolver is defined, it must be a function.
761
- function isValidResolver ( resolver : mixed ) : boolean {
759
+ // If a value is defined, it must be a function.
760
+ function isMaybeFunction ( resolver : mixed ) : boolean {
762
761
return resolver == null || typeof resolver === 'function' ;
763
762
}
764
763
@@ -903,12 +902,11 @@ export class GraphQLInterfaceType {
903
902
this . resolveType = config . resolveType ;
904
903
this . _fields = defineFieldMap . bind ( undefined , config ) ;
905
904
invariant ( typeof config . name === 'string' , 'Must provide name.' ) ;
906
- if ( config . resolveType ) {
907
- invariant (
908
- typeof config . resolveType === 'function' ,
909
- `${ this . name } must provide "resolveType" as a function.` ,
910
- ) ;
911
- }
905
+ invariant (
906
+ isMaybeFunction ( config . resolveType ) ,
907
+ `${ this . name } must provide "resolveType" as a function, ` +
908
+ `but got: ${ inspect ( config . resolveType ) } .` ,
909
+ ) ;
912
910
}
913
911
914
912
getFields ( ) : GraphQLFieldMap < * , * > {
@@ -981,12 +979,11 @@ export class GraphQLUnionType {
981
979
this . resolveType = config . resolveType ;
982
980
this . _types = defineTypes . bind ( undefined , config ) ;
983
981
invariant ( typeof config . name === 'string' , 'Must provide name.' ) ;
984
- if ( config . resolveType ) {
985
- invariant (
986
- typeof config . resolveType === 'function' ,
987
- `${ this . name } must provide "resolveType" as a function.` ,
988
- ) ;
989
- }
982
+ invariant (
983
+ isMaybeFunction ( config . resolveType ) ,
984
+ `${ this . name } must provide "resolveType" as a function, ` +
985
+ `but got: ${ inspect ( config . resolveType ) } .` ,
986
+ ) ;
990
987
}
991
988
992
989
getTypes ( ) : Array < GraphQLObjectType > {
0 commit comments