import { ArtifactOptions , BaseArtifactBooter , BootBindings , booter , } from '@loopback/boot' ; import { Application , config , Constructor , CoreBindings , inject , } from '@loopback/core' ; import debugFactory from 'debug' ; import { ResolverClassMetadata } from 'type-graphql/dist/metadata/definitions' ; import { getMetadataStorage } from 'type-graphql/dist/metadata/getMetadataStorage' ; import { registerResolver } from '../graphql.server' ; const debug = debugFactory ( 'loopback:graphql:resolver-booter' ) ; type GraphQLResolverClass = Constructor < object > ; param app param projectRoot param bootConfig @ booter ( 'graphqlResolvers' ) export class GraphQLResolverBooter extends BaseArtifactBooter { resolvers : GraphQLResolverClass [ ] ; constructor ( @ inject ( CoreBindings . APPLICATION_INSTANCE ) public app , @ inject ( BootBindings . PROJECT_ROOT ) projectRoot , @ config ( ) public interceptorConfig = { } ) { super ( projectRoot , Object . assign ( { } , GraphQLResolverDefaults , interceptorConfig ) ) ; } /**
     * Uses super method to get a list of Artifact classes. Boot each file by
     * creating a DataSourceConstructor and binding it to the application class.
     */ async load ( ) { await super . load ( ) ; const resolverClasses = ( getMetadataStorage ( ) as any ) . resolverClasses ; this . resolvers = this . classes . filter ( cls => { return resolverClasses . some ( r => ! r . isAbstract && r . target === cls ) ; } ) ; for ( const resolver of this . resolvers ) { debug ( 'Bind interceptor: %s' , resolver . name ) ; const binding = registerResolver ( this . app , resolver ) ; debug ( 'Binding created for interceptor: %j' , binding ) ; } } } /**
 * Default ArtifactOptions for GraphQLResolverBooter.
 */ export const GraphQLResolverDefaults = { dirs : [ 'graphql-resolvers' ] , extensions : [ '.js' ] , nested : true , } ;