[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Having two TypeOrm entities, that has fields that references each other, however without circular dependency, as reference is a string in TypeOrm @OneToMany / @ManyToOne decorator.
user.entity.ts
import { Field, HideField, ObjectType } from '@nestjs/graphql';
import { Entity, OneToMany } from 'typeorm';
import { Profile } from '../profile/profile.entity';
@ObjectType()
@Entity()
export class User {
@Field(() => [Profile])
@OneToMany('Profile', 'user', { eager: true })
profiles: Profile[];
@HideField()
activeProfile: Profile;
// ... other fields ...
}
profile.entity.ts
import { Field, ObjectType } from '@nestjs/graphql';
import { Entity, ManyToOne } from 'typeorm';
import { User } from '../user/user.entity';
@ObjectType()
@Entity()
export class Profile {
@Field(() => User)
@ManyToOne('User', 'profiles', { eager: false, nullable: false, onDelete: 'RESTRICT' })
user: User;
// ... other fields ...
}
Entity classes becomes properly decorated to be used with Gql resolvers and mutations
@nestjs/graphql/plugin (I didn't tested this case without plugin)WARNING in Circular dependency detected:
src/profile/profile.entity.ts -> src/user/user.entity.ts -> src/profile/profile.entity.ts
WARNING in Circular dependency detected:
src/user/user.entity.ts -> src/profile/profile.entity.ts -> src/user/user.entity.ts
However, if you will comment / remove Gql decorators the warning disappears.
This issue happens even if you will put ONLY one @HideField on any field shown in example above.
Nest version: 7.0.5
@nestjs/graphql: 7.0.14
@nrwl/*: 9.1.2
For Tooling issues:
- Node version: v12.14.1
- Platform: Linux
Others:
This is completely fine. Webpack automatically warns about the circular dependencies, but it won't cause any issues.
@kamilmysliwiec I realize this would not cause any issue and works fine but can't we have have any solution for it like typeorm for which we can provide string as type? So that it won't keep displaying circular dependency warning?
Most helpful comment
@kamilmysliwiec I realize this would not cause any issue and works fine but can't we have have any solution for it like typeorm for which we can provide string as type? So that it won't keep displaying circular dependency warning?