@@ -46,6 +46,7 @@ import {
4646 type GraphQLArgumentConfig ,
4747 type GraphQLEnumValueConfig ,
4848 type GraphQLInputFieldConfig ,
49+ type GraphQLFieldResolver ,
4950 GraphQLScalarType ,
5051 GraphQLObjectType ,
5152 GraphQLInterfaceType ,
@@ -72,6 +73,10 @@ import {
7273 GraphQLSchema ,
7374} from '../type/schema' ;
7475
76+ export type TypeFieldResolverMap = ObjMap <
77+ ObjMap < GraphQLFieldResolver < mixed , mixed , mixed >> ,
78+ > ;
79+
7580export type BuildSchemaOptions = {
7681 ...GraphQLSchemaValidationOptions ,
7782
@@ -92,6 +97,13 @@ export type BuildSchemaOptions = {
9297 */
9398 assumeValidSDL ?: boolean ,
9499
100+ /**
101+ * Object map of object maps to resolver funtions.
102+ *
103+ * Default: undefined
104+ */
105+ resolvers ?: TypeFieldResolverMap ,
106+
95107 ...
96108} ;
97109
@@ -243,14 +255,26 @@ export class ASTDefinitionBuilder {
243255 } ) ;
244256 }
245257
246- buildField ( field : FieldDefinitionNode ) : GraphQLFieldConfig < mixed , mixed > {
258+ buildField (
259+ field : FieldDefinitionNode ,
260+ typeName ?: string ,
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+
247270 return {
248271 // Note: While this could make assertions to get the correctly typed
249272 // value, that would throw immediately while type system validation
250273 // with validateSchema() will produce more actionable results.
251274 type : ( this . getWrappedType ( field . type ) : any ) ,
252275 description : getDescription ( field , this . _options ) ,
253276 args : keyByNameNode ( field . arguments || [ ] , arg => this . buildArg ( arg ) ) ,
277+ resolve,
254278 deprecationReason : getDeprecationReason ( field ) ,
255279 astNode : field ,
256280 } ;
@@ -330,13 +354,15 @@ export class ASTDefinitionBuilder {
330354 ? ( ) => interfaceNodes . map ( ref => ( this . getNamedType ( ref ) : any ) )
331355 : [ ] ;
332356
357+ const name = astNode . name . value ;
358+
333359 const fields =
334360 fieldNodes && fieldNodes . length > 0
335- ? ( ) => keyByNameNode ( fieldNodes , field => this . buildField ( field ) )
361+ ? ( ) => keyByNameNode ( fieldNodes , field => this . buildField ( field , name ) )
336362 : Object . create ( null ) ;
337363
338364 return new GraphQLObjectType ( {
339- name : astNode . name . value ,
365+ name,
340366 description : getDescription ( astNode , this . _options ) ,
341367 interfaces,
342368 fields,
@@ -346,14 +372,15 @@ export class ASTDefinitionBuilder {
346372
347373 _makeInterfaceDef ( astNode : InterfaceTypeDefinitionNode ) {
348374 const fieldNodes = astNode . fields ;
375+ const name = astNode . name . value ;
349376
350377 const fields =
351378 fieldNodes && fieldNodes . length > 0
352- ? ( ) => keyByNameNode ( fieldNodes , field => this . buildField ( field ) )
379+ ? ( ) => keyByNameNode ( fieldNodes , field => this . buildField ( field , name ) )
353380 : Object . create ( null ) ;
354381
355382 return new GraphQLInterfaceType ( {
356- name : astNode . name . value ,
383+ name,
357384 description : getDescription ( astNode , this . _options ) ,
358385 fields,
359386 astNode,
0 commit comments