不能在左轮手枪中依赖注入服务
Can't dependency inject service in revolver
我无法在同一个模块中使用带有解析器的服务。我已经看了这个至少一个小时了,但不知道出了什么问题。
auth 服务在 auth 模块的 providers 数组中,所以 auth 解析器应该可以使用它吧?
Error: Nest can't resolve dependencies of the AuthResolver (?). Please make sure that the argument AuthService at index [0] is available in the AuthResolver context.
Potential solutions:
- If AuthService is a provider, is it part of the current AuthResolver?
- If AuthService is exported from a separate @Module, is that module imported within AuthResolver?
@Module({
imports: [ /* the Module containing AuthService */ ]
})
app.module.ts
@Module({
imports: [
MercuriusModule.forRoot({ autoSchemaFile: true, graphiql: 'playground' }),
AppResolver,
AuthModule,
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
auth.module.ts
@Module({
imports: [AuthResolver],
providers: [AuthService],
})
export class AuthModule {}
auth.service.ts
@Injectable()
export class AuthService {}
auth.resolver.ts
@Resolver()
export class AuthResolver {
constructor(private readonly authService: AuthService) {}
@Mutation(() => Boolean)
sendMagicLink(): boolean {
return true;
}
@Mutation(() => Boolean)
signIn(): boolean {
return true;
}
@Mutation(() => Boolean)
signOut(): boolean {
return true;
}
@Mutation(() => Boolean)
revokeRefreshToken(): boolean {
return true;
}
}
问题是解析器必须像这样位于提供程序数组中。
@Module({
providers: [AuthService, AuthResolver],
})
export class AuthModule {}
我无法在同一个模块中使用带有解析器的服务。我已经看了这个至少一个小时了,但不知道出了什么问题。
auth 服务在 auth 模块的 providers 数组中,所以 auth 解析器应该可以使用它吧?
Error: Nest can't resolve dependencies of the AuthResolver (?). Please make sure that the argument AuthService at index [0] is available in the AuthResolver context.
Potential solutions:
- If AuthService is a provider, is it part of the current AuthResolver?
- If AuthService is exported from a separate @Module, is that module imported within AuthResolver?
@Module({
imports: [ /* the Module containing AuthService */ ]
})
app.module.ts
@Module({
imports: [
MercuriusModule.forRoot({ autoSchemaFile: true, graphiql: 'playground' }),
AppResolver,
AuthModule,
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
auth.module.ts
@Module({
imports: [AuthResolver],
providers: [AuthService],
})
export class AuthModule {}
auth.service.ts
@Injectable()
export class AuthService {}
auth.resolver.ts
@Resolver()
export class AuthResolver {
constructor(private readonly authService: AuthService) {}
@Mutation(() => Boolean)
sendMagicLink(): boolean {
return true;
}
@Mutation(() => Boolean)
signIn(): boolean {
return true;
}
@Mutation(() => Boolean)
signOut(): boolean {
return true;
}
@Mutation(() => Boolean)
revokeRefreshToken(): boolean {
return true;
}
}
问题是解析器必须像这样位于提供程序数组中。
@Module({
providers: [AuthService, AuthResolver],
})
export class AuthModule {}