Circular Dependency
원인
- NestJS Module이 서로 import 하면 순환 의존성 문제 발생
@Module({
imports: [PostModule)],
providers: [
CommentResolver,
CommentSubResolver,
CommentService,
CommonCommentService,
],
exports: [CommentService],
})
export class CommentModule {}
@Module({
imports: [CommentModule)],
providers: [
PostResolver,
PostSubResolver,
PostService,
CommonPostService,
],
exports: [PostService],
})
export class PostModule {}
해결 방법
@Module({
imports: [forwardRef(() => PostModule)],
providers: [
CommentResolver,
CommentSubResolver,
CommentService,
CommonCommentService,
],
exports: [CommentService],
})
export class CommentModule {}
@Module({
imports: [forwardRef(() => CommentModule)],
providers: [
PostResolver,
PostSubResolver,
PostService,
CommonPostService,
],
exports: [PostService],
})
export class PostModule {}