@@ -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
+ config . isTypeOf == null || typeof config . isTypeOf === 'function' ,
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
+ field . resolve == null || typeof field . resolve === ' function ' ,
728
727
`${config . name } . ${fieldName } field resolver must be a function if ` +
729
728
`provided , but got : ${inspect ( field . resolve ) } . `,
730
729
);
@@ -757,11 +756,6 @@ 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 {
762
- return resolver == null || typeof resolver === 'function' ;
763
- }
764
-
765
759
export type GraphQLObjectTypeConfig<TSource, TContext> = {|
766
760
name: string,
767
761
interfaces?: Thunk<?Array<GraphQLInterfaceType>>,
@@ -903,12 +897,11 @@ export class GraphQLInterfaceType {
903
897
this.resolveType = config.resolveType;
904
898
this._fields = defineFieldMap.bind(undefined, config);
905
899
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
- }
900
+ invariant(
901
+ config.resolveType == null || typeof config.resolveType === 'function',
902
+ ` $ { this . name } must provide "resolveType " as a function , ` +
903
+ ` but got : ${inspect ( config . resolveType ) } . `,
904
+ );
912
905
}
913
906
914
907
getFields(): GraphQLFieldMap<*, *> {
@@ -981,12 +974,11 @@ export class GraphQLUnionType {
981
974
this.resolveType = config.resolveType;
982
975
this._types = defineTypes.bind(undefined, config);
983
976
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
- }
977
+ invariant(
978
+ config.resolveType == null || typeof config.resolveType === 'function',
979
+ ` $ { this . name } must provide "resolveType " as a function , ` +
980
+ ` but got : ${inspect ( config . resolveType ) } . `,
981
+ );
990
982
}
991
983
992
984
getTypes(): Array<GraphQLObjectType> {
0 commit comments