Graphql: Decorating fields with @Field or @HideField causes "WARNING in Circular dependency detected"

Created on 23 Mar 2020  路  2Comments  路  Source: nestjs/graphql

I'm submitting a...


[ ] 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.

Current behavior

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 ...
}

Expected behavior

Entity classes becomes properly decorated to be used with Gql resolvers and mutations

Minimal reproduction of the problem with instructions

  • create mentioned entities without Gql decorators
  • run app and ensure there are no warnings in console output related to circular dependency issues
  • enable @nestjs/graphql/plugin (I didn't tested this case without plugin)
  • decorate fields as it shown above
  • check console output for warnings like
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.

Environment


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:

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?

All 2 comments

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?

Was this page helpful?
0 / 5 - 0 ratings