@@ -252,6 +252,7 @@ export class GraphQLObjectType {
252
252
253
253
_typeConfig: GraphQLObjectTypeConfig ;
254
254
_fields: GraphQLFieldDefinitionMap ;
255
+ _interfaces: Array < GraphQLInterfaceType > ;
255
256
256
257
constructor ( config : GraphQLObjectTypeConfig ) {
257
258
invariant ( config . name , 'Type must be named.' ) ;
@@ -267,7 +268,8 @@ export class GraphQLObjectType {
267
268
}
268
269
269
270
getInterfaces ( ) : Array < GraphQLInterfaceType > {
270
- return this . _typeConfig . interfaces || [ ] ;
271
+ return this . _interfaces ||
272
+ ( this . _interfaces = defineInterfaces ( this . _typeConfig . interfaces || [ ] ) ) ;
271
273
}
272
274
273
275
isTypeOf ( value : any ) : ?boolean {
@@ -282,10 +284,18 @@ export class GraphQLObjectType {
282
284
}
283
285
}
284
286
287
+ function resolveMaybeThunk < T > (thingOrThunk: T | () => T) : T {
288
+ return typeof thingOrThunk === 'function' ? thingOrThunk ( ) : thingOrThunk ;
289
+ }
290
+
291
+ function defineInterfaces ( interfacesOrThunk ) : Array < GraphQLInterfaceType > {
292
+ return resolveMaybeThunk ( interfacesOrThunk ) ;
293
+ }
294
+
285
295
function defineFieldMap (
286
296
fields : GraphQLFieldConfigMap
287
297
) : GraphQLFieldDefinitionMap {
288
- var fieldMap : any = typeof fields === 'function' ? fields ( ) : fields ;
298
+ var fieldMap : any = resolveMaybeThunk ( fields ) ;
289
299
Object . keys ( fieldMap ) . forEach ( fieldName => {
290
300
var field = fieldMap [ fieldName ] ;
291
301
field . name = fieldName ;
0 commit comments