Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to control {nullable: true} of generated fields. #201

Open
Trottero opened this issue Dec 10, 2023 · 3 comments
Open

Unable to control {nullable: true} of generated fields. #201

Trottero opened this issue Dec 10, 2023 · 3 comments

Comments

@Trottero
Copy link

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?

@vladyslav-n
Copy link

Yeah, totally agree that current behaviour of lists being optional is incorrect, default list field type mapping should definitely be like [Type!]!.

@Trottero
Copy link
Author

Trottero commented Feb 1, 2024

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.

@SOG-web
Copy link

SOG-web commented Aug 29, 2024

please any solution to this yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants