@@ -260,6 +260,7 @@ export type GraphQLScalarTypeConfig/* <T> */ = {
260
260
export class GraphQLObjectType {
261
261
name : string ;
262
262
description: ?string ;
263
+ isTypeOf: ?( value : any , info ? : GraphQLResolveInfo ) => boolean ;
263
264
264
265
_typeConfig: GraphQLObjectTypeConfig ;
265
266
_fields: GraphQLFieldDefinitionMap ;
@@ -269,6 +270,7 @@ export class GraphQLObjectType {
269
270
invariant ( config . name , 'Type must be named.' ) ;
270
271
this . name = config . name ;
271
272
this . description = config . description ;
273
+ this . isTypeOf = config . isTypeOf ;
272
274
this . _typeConfig = config ;
273
275
addImplementationToInterfaces ( this ) ;
274
276
}
@@ -283,13 +285,6 @@ export class GraphQLObjectType {
283
285
( this . _interfaces = defineInterfaces ( this . _typeConfig . interfaces || [ ] ) ) ;
284
286
}
285
287
286
- isTypeOf ( value : any ) : ?boolean {
287
- var predicate = this . _typeConfig . isTypeOf ;
288
- if ( predicate ) {
289
- return predicate ( value ) ;
290
- }
291
- }
292
-
293
288
toString ( ) : string {
294
289
return this . name ;
295
290
}
@@ -347,7 +342,7 @@ export type GraphQLObjectTypeConfig = {
347
342
name : string ;
348
343
interfaces ?: GraphQLInterfacesThunk | Array < GraphQLInterfaceType > ;
349
344
fields : GraphQLFieldConfigMapThunk | GraphQLFieldConfigMap ;
350
- isTypeOf ?: ( value : any ) => boolean ;
345
+ isTypeOf ?: ( value : any , info ?: GraphQLResolveInfo ) => boolean ;
351
346
description ?: ?string
352
347
}
353
348
@@ -474,7 +469,7 @@ export class GraphQLInterfaceType {
474
469
475
470
resolveType ( value : any , info : GraphQLResolveInfo ) : ?GraphQLObjectType {
476
471
var resolver = this . _typeConfig . resolveType ;
477
- return resolver ? resolver ( value , info ) : getTypeOf ( value , this ) ;
472
+ return resolver ? resolver ( value , info ) : getTypeOf ( value , info , this ) ;
478
473
}
479
474
480
475
toString ( ) : string {
@@ -484,13 +479,13 @@ export class GraphQLInterfaceType {
484
479
485
480
function getTypeOf (
486
481
value : any ,
482
+ info : GraphQLResolveInfo ,
487
483
abstractType : GraphQLAbstractType
488
484
) : ?GraphQLObjectType {
489
485
var possibleTypes = abstractType . getPossibleTypes ( ) ;
490
486
for ( var i = 0 ; i < possibleTypes . length ; i ++ ) {
491
487
var type = possibleTypes [ i ] ;
492
- var isTypeOf = type . isTypeOf ( value ) ;
493
- if ( isTypeOf === undefined ) {
488
+ if ( typeof type . isTypeOf !== 'function' ) {
494
489
// TODO: move this to a JS impl specific type system validation step
495
490
// so the error can be found before execution.
496
491
throw new Error (
@@ -499,7 +494,7 @@ function getTypeOf(
499
494
'isTypeOf. There is no way to determine if a value is of this type.'
500
495
) ;
501
496
}
502
- if ( isTypeOf ) {
497
+ if ( type . isTypeOf ( value , info ) ) {
503
498
return type ;
504
499
}
505
500
}
@@ -589,7 +584,7 @@ export class GraphQLUnionType {
589
584
590
585
resolveType ( value : any , info : GraphQLResolveInfo ) : ?GraphQLObjectType {
591
586
var resolver = this . _typeConfig . resolveType ;
592
- return resolver ? resolver ( value , info ) : getTypeOf ( value , this ) ;
587
+ return resolver ? resolver ( value , info ) : getTypeOf ( value , info , this ) ;
593
588
}
594
589
595
590
toString ( ) : string {
0 commit comments