0

I'm trying to setup a graphql nestjs clean architecture, I have my resolver call the service, service calls repository and repository calls orm methods. Am I missing a step?

But I get this error:

[Nest] 59764 - 03/10/2022, 16:36:13 ERROR [ExceptionHandler] Nest can't resolve dependencies of the AthleteRepository (?). Please make sure that the argument AthleteEntityRepository at index [0] is available in the GraphQLModule context. Potential solutions: - If AthleteEntityRepository is a provider, is it part of the current GraphQLModule? - If AthleteEntityRepository is exported from a separate @Module, is that module imported within GraphQLModule? @Module({ imports: [ /* the Module containing AthleteEntityRepository */ ] }) Error: Nest can't resolve dependencies of the AthleteRepository (?). Please make sure that the argument AthleteEntityRepository at index [0] is available in the GraphQLModule context. 

This is my module:

@Module({ imports: [ InfraestructureModule, NestGraphqlModule.forRoot<MercuriusDriverConfig>({ driver: MercuriusDriver, graphiql: true, autoSchemaFile: join( process.cwd(), 'src/infraestructure/graphql/schema.gql', ), sortSchema: true, }), ], controllers: [AuthResolver, UserResolver], providers: [ FirebaseService, AthleteEntity, AthleteRepository, AthleteService, ], }) export class GraphQLModule {} 

Adding repository by comment request, it's mostly just wrappers around the typerom Repository.

import { Controller } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import { AthleteEntity } from '../entity/athlete.entity'; @Controller('') export class AthleteRepository { constructor( @InjectRepository(AthleteEntity) private athleteRepository: Repository<AthleteEntity>, ) {} async getAthleteByUserId(id: string): Promise<AthleteEntity> { return this.athleteRepository.findOne({ where: { id } }); } async getAthletes(): Promise<AthleteEntity[]> { return this.athleteRepository.find(); } } 
2
  • show us that AthleteRepository class Commented Oct 3, 2022 at 23:49
  • AthleteRepository added. Commented Oct 4, 2022 at 0:08

2 Answers 2

1

As you use @InjectRepository(AtheleteEntity) you need to have TypeOrmModule.forFeature([AtheleteEntity]) used in the imports of the GraphQlModule.

Side note: Is that supposed to be @Controller() or @Injectable()? It doesn't look like a standard HTTP or RPC controller to me

Sign up to request clarification or add additional context in comments.

1 Comment

I guess an injectable, I'm trying to reacreate a clean architecture to expose both REST and Graphl, so this services, repositories, etc are what those endpoints call.
0

change AthleteRepository to an @Injectable instead of @Controller.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.