0
I have a problem with a circular dependency in a GraphQL model.
I’m using Nestjs Graphql MongoDb Mongoose ad I have 3 entities.
@ObjectType()
@Schema({ timestamps: true })
export class User {
@Field(() => ID)
_id: string;
@Field({ nullable: true })
@Prop({ nullable: true, unique: true })
pseudoDiscord?: string;
}
@ObjectType()
@Schema({ timestamps: true })
export class UserGame {
@Field(() => ID)
_id: string;
@Field(() => User)
@Prop({ type: mongoose.Schema.Types.ObjectId, ref: 'User' })
userId: User;
}
@ObjectType()
@Schema({ timestamps: true })
export class UserGameRole {
@Field(() => ID)
_id: string;
@Field(() => UserGame)
@Prop({ type: mongoose.Schema.Types.ObjectId, ref: 'UserGame' })
userGameId: UserGame;
otherField...
}
I’d like to create a field named userGame in the user entity so that I can extract information from this entity.
How do I do this? I need to import the UserGame module into User to access the UserGameService and make requests, but the UserGameModule already imports the UserModule to resolve **userId **fields.
When I start from the UserGameRole and go back up to the UserGame and then to the User with a GraphQL query, the information received is null.
1
Circular dependencies between types are quite common and even expected in GraphQL. Could you post the actual gql query you are attempting to run?
10 mins ago