@@ -47,6 +47,7 @@ import {
47
47
type GraphQLEnumValueConfig ,
48
48
type GraphQLInputFieldConfig ,
49
49
type GraphQLFieldResolver ,
50
+ type GraphQLScalarTypeConverters ,
50
51
GraphQLScalarType ,
51
52
GraphQLObjectType ,
52
53
GraphQLInterfaceType ,
@@ -73,10 +74,15 @@ import {
73
74
GraphQLSchema ,
74
75
} from '../type/schema' ;
75
76
76
- export type TypeFieldResolverMap = ObjMap <
77
- | ObjMap < GraphQLFieldResolver < mixed , mixed , mixed >> /* type and interface */
78
- | ObjMap < any > /* enum */ ,
79
- > ;
77
+ export type TypeFieldResolver =
78
+ /* scalars */
79
+ | GraphQLScalarTypeConverters < any , any >
80
+ /* type and interface */
81
+ | ObjMap < GraphQLFieldResolver < mixed , mixed , mixed >>
82
+ /* enum */
83
+ | ObjMap < any > ;
84
+
85
+ export type TypeFieldResolverMap = ObjMap < TypeFieldResolver > ;
80
86
81
87
export type BuildSchemaOptions = {
82
88
...GraphQLSchemaValidationOptions ,
@@ -127,6 +133,7 @@ export type BuildSchemaOptions = {
127
133
* - resolvers — map of named types
128
134
* - Object, Interface — field resolvers
129
135
* - Enum — External string → any internal value
136
+ * - Scalars — serialize, parseValue, parseLiteral
130
137
*
131
138
*/
132
139
export function buildASTSchema (
@@ -272,7 +279,7 @@ export class ASTDefinitionBuilder {
272
279
type : ( this . getWrappedType ( field . type ) : any ) ,
273
280
description : getDescription ( field , this . _options ) ,
274
281
args : keyByNameNode ( field . arguments || [ ] , arg => this . buildArg ( arg ) ) ,
275
- resolve : this . _lookupResolver ( typeName , field . name . value ) ,
282
+ resolve : this . _lookupResolverField ( typeName , field . name . value ) ,
276
283
deprecationReason : getDeprecationReason ( field ) ,
277
284
astNode : field ,
278
285
} ;
@@ -309,7 +316,7 @@ export class ASTDefinitionBuilder {
309
316
typeName ?: string ,
310
317
) : GraphQLEnumValueConfig {
311
318
return {
312
- value : this . _lookupResolver ( typeName , value . name . value ) ,
319
+ value : this . _lookupResolverField ( typeName , value . name . value ) ,
313
320
description : getDescription ( value , this . _options ) ,
314
321
deprecationReason : getDeprecationReason ( value ) ,
315
322
astNode : value ,
@@ -423,9 +430,17 @@ export class ASTDefinitionBuilder {
423
430
}
424
431
425
432
_makeScalarDef ( astNode : ScalarTypeDefinitionNode ) {
433
+ const name = astNode . name . value ;
434
+ const resolver = ( ( this . _lookupResolver (
435
+ name ,
436
+ ) : any ) : GraphQLScalarTypeConverters < any , any > ) ;
437
+
426
438
return new GraphQLScalarType ( {
427
- name : astNode . name . value ,
439
+ name,
428
440
description : getDescription ( astNode , this . _options ) ,
441
+ serialize : ( resolver && resolver . serialize ) || undefined ,
442
+ parseValue : ( resolver && resolver . parseValue ) || undefined ,
443
+ parseLiteral : ( resolver && resolver . parseLiteral ) || undefined ,
429
444
astNode,
430
445
} ) ;
431
446
}
@@ -443,16 +458,18 @@ export class ASTDefinitionBuilder {
443
458
} ) ;
444
459
}
445
460
446
- _lookupResolver ( typeName : ?string , key : string ) {
461
+ _lookupResolver ( typeName : ?string ) {
462
+ const opts = this . _options ;
447
463
return (
448
- ( typeName &&
449
- this . _options &&
450
- this . _options . resolvers &&
451
- this . _options . resolvers [ typeName ] &&
452
- this . _options . resolvers [ typeName ] [ key ] ) ||
464
+ ( typeName && opts && opts . resolvers && opts . resolvers [ typeName ] ) ||
453
465
undefined
454
466
) ;
455
467
}
468
+
469
+ _lookupResolverField ( typeName : ?string , key : string ) {
470
+ const resolver = this . _lookupResolver ( typeName ) ;
471
+ return ( resolver && resolver [ key ] ) || undefined ;
472
+ }
456
473
}
457
474
458
475
function keyByNameNode < T : { + name : NameNode , ... } , V > (
0 commit comments