prisma-nestjs-graphql
prisma-nestjs-graphql copied to clipboard
Unable to control `{nullable: true}` of generated fields.
Hi! thanks for building the generator, it has saved me so much time already!
I am however running into an issue where I can't seem to configure one-to-many relations correctly, specifically, I can't seem to control the nullability of the array type.
For example;
model User {
id String @id
posts BlogPost[]
}
model BlogPost {
id String @id
userId String
user User @relation(fields: [userId], references: [id])
}
Generates (just included the user class)
@ObjectType()
export class User {
@Field(() => ID, {nullable:false})
id!: string;
@Field(() => [BlogPost], {nullable:true}) <-- it's not nullable, its always an array
posts?: Array<BlogPost>
}
This makes it so the gql server thinks posts is nullable, when in reality it always returns an array, with it being empty if there are no posts.
How do I control this behaviour?
Yeah, totally agree that current behaviour of lists being optional is incorrect, default list field type mapping should definitely be like [Type!]!.
Yeah, totally agree that current behaviour of lists being optional is incorrect, default list field type mapping should definitely be like
[Type!]!.
I dont't mind the default being nullable though, I'd rather focus on being able to configure it as other setups might return null anyway.
please any solution to this yet