import { ResolverBuilder , TargetTypesMap } from './common' ; import { GraphQLTypeInformer } from './graphql-type-informer' ; import { GraphQLFieldConfigMap , GraphQLObjectType , GraphQLNonNull } from 'graphql' ; export class GraphQLMutationGenerator { public constructor ( private readonly targetTypes , private readonly typeInformer , private readonly mutationResolver ) { } public generate ( ) { const mutations = this . generateMutations ( ) ; if ( Object . keys ( mutations ) . length === 0 ) { return undefined ; } return new GraphQLObjectType ( { name : 'Mutation' , fields : mutations , } ) ; } private generateMutations ( ) { const mutations = { } ; for ( const name in this . targetTypes ) { const type = this . targetTypes [ name ] ; mutations [ name ] = { type : this . typeInformer . getGraphQLTypeFor ( type . returnClass ?? Boolean ) , args : { input : { type : new GraphQLNonNull ( this . typeInformer . getGraphQLInputTypeFor ( type . class ) ) , } , } , resolve : this . mutationResolver ( type . class ) , } ; } return mutations ; } }