@@ -259,22 +259,14 @@ export class ASTDefinitionBuilder {
259
259
field : FieldDefinitionNode ,
260
260
typeName ?: string ,
261
261
) : GraphQLFieldConfig < mixed , mixed > {
262
- const resolve =
263
- ( typeName &&
264
- this . _options &&
265
- this . _options . resolvers &&
266
- this . _options . resolvers [ typeName ] &&
267
- this . _options . resolvers [ typeName ] [ field . name . value ] ) ||
268
- undefined ;
269
-
270
262
return {
271
263
// Note: While this could make assertions to get the correctly typed
272
264
// value, that would throw immediately while type system validation
273
265
// with validateSchema() will produce more actionable results.
274
266
type : ( this . getWrappedType ( field . type ) : any ) ,
275
267
description : getDescription ( field , this . _options ) ,
276
268
args : keyByNameNode ( field . arguments || [ ] , arg => this . buildArg ( arg ) ) ,
277
- resolve,
269
+ resolve : this . _lookupResolver ( typeName , field . name . value ) ,
278
270
deprecationReason : getDeprecationReason ( field ) ,
279
271
astNode : field ,
280
272
} ;
@@ -306,8 +298,12 @@ export class ASTDefinitionBuilder {
306
298
} ;
307
299
}
308
300
309
- buildEnumValue ( value : EnumValueDefinitionNode ) : GraphQLEnumValueConfig {
301
+ buildEnumValue (
302
+ value : EnumValueDefinitionNode ,
303
+ typeName ?: string ,
304
+ ) : GraphQLEnumValueConfig {
310
305
return {
306
+ value : this . _lookupResolver ( typeName , value . name . value ) ,
311
307
description : getDescription ( value , this . _options ) ,
312
308
deprecationReason : getDeprecationReason ( value ) ,
313
309
astNode : value ,
@@ -389,11 +385,14 @@ export class ASTDefinitionBuilder {
389
385
390
386
_makeEnumDef ( astNode : EnumTypeDefinitionNode ) {
391
387
const valueNodes = astNode . values || [ ] ;
388
+ const name = astNode . name . value ;
392
389
393
390
return new GraphQLEnumType ( {
394
- name : astNode . name . value ,
391
+ name,
395
392
description : getDescription ( astNode , this . _options ) ,
396
- values : keyByNameNode ( valueNodes , value => this . buildEnumValue ( value ) ) ,
393
+ values : keyByNameNode ( valueNodes , value =>
394
+ this . buildEnumValue ( value , name ) ,
395
+ ) ,
397
396
astNode,
398
397
} ) ;
399
398
}
@@ -437,6 +436,17 @@ export class ASTDefinitionBuilder {
437
436
astNode : def ,
438
437
} ) ;
439
438
}
439
+
440
+ _lookupResolver ( typeName : ?string , key : string ) {
441
+ return (
442
+ ( typeName &&
443
+ this . _options &&
444
+ this . _options . resolvers &&
445
+ this . _options . resolvers [ typeName ] &&
446
+ this . _options . resolvers [ typeName ] [ key ] ) ||
447
+ undefined
448
+ ) ;
449
+ }
440
450
}
441
451
442
452
function keyByNameNode < T : { + name : NameNode , ... } , V > (
0 commit comments