@@ -661,12 +661,11 @@ export class GraphQLObjectType {
661
661
this . isTypeOf = config . isTypeOf ;
662
662
this . _typeConfig = config ;
663
663
invariant ( typeof config . name === 'string' , 'Must provide name.' ) ;
664
- if ( config . isTypeOf ) {
665
- invariant (
666
- typeof config . isTypeOf === 'function' ,
667
- `${ this . name } must provide "isTypeOf" as a function.` ,
668
- ) ;
669
- }
664
+ invariant (
665
+ isMaybeFunction ( config . isTypeOf ) ,
666
+ `${ this . name } must provide "isTypeOf" as a function, ` +
667
+ `but got: ${ inspect ( config . isTypeOf ) } .` ,
668
+ ) ;
670
669
}
671
670
672
671
getFields ( ) : GraphQLFieldMap < * , * > {
@@ -734,7 +733,7 @@ function defineFieldMap<TSource, TContext>(
734
733
name : fieldName ,
735
734
} ;
736
735
invariant (
737
- isValidResolver ( field . resolve ) ,
736
+ isMaybeFunction ( field . resolve ) ,
738
737
`${ type . name } .${ fieldName } field resolver must be a function if ` +
739
738
`provided, but got: ${ inspect ( field . resolve ) } .` ,
740
739
) ;
@@ -767,8 +766,8 @@ function isPlainObj(obj) {
767
766
return obj && typeof obj === 'object ' && ! Array . isArray ( obj ) ;
768
767
}
769
768
770
- // If a resolver is defined, it must be a function.
771
- function isValidResolver ( resolver : mixed ) : boolean {
769
+ // If a value is defined, it must be a function.
770
+ function isMaybeFunction ( resolver : mixed ) : boolean {
772
771
return resolver == null || typeof resolver === 'function ';
773
772
}
774
773
@@ -914,12 +913,11 @@ export class GraphQLInterfaceType {
914
913
this . resolveType = config . resolveType ;
915
914
this . _typeConfig = config ;
916
915
invariant ( typeof config . name === 'string' , 'Must provide name.' ) ;
917
- if ( config . resolveType ) {
918
- invariant (
919
- typeof config . resolveType === 'function' ,
920
- `${ this . name } must provide "resolveType" as a function.` ,
921
- ) ;
922
- }
916
+ invariant (
917
+ isMaybeFunction ( config . resolveType ) ,
918
+ `${ this . name } must provide "resolveType" as a function, ` +
919
+ `but got: ${ inspect ( config . resolveType ) } .` ,
920
+ ) ;
923
921
}
924
922
925
923
getFields ( ) : GraphQLFieldMap < * , * > {
@@ -993,12 +991,11 @@ export class GraphQLUnionType {
993
991
this . resolveType = config . resolveType ;
994
992
this . _typeConfig = config ;
995
993
invariant ( typeof config . name === 'string' , 'Must provide name.' ) ;
996
- if ( config . resolveType ) {
997
- invariant (
998
- typeof config . resolveType === 'function' ,
999
- `${ this . name } must provide "resolveType" as a function.` ,
1000
- ) ;
1001
- }
994
+ invariant (
995
+ isMaybeFunction ( config . resolveType ) ,
996
+ `${ this . name } must provide "resolveType" as a function, ` +
997
+ `but got: ${ inspect ( config . resolveType ) } .` ,
998
+ ) ;
1002
999
}
1003
1000
1004
1001
getTypes ( ) : Array < GraphQLObjectType > {
0 commit comments