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

Optional fields are not optional in the generated TS class #225

Open
kasir-barati opened this issue Dec 3, 2024 · 1 comment
Open

Optional fields are not optional in the generated TS class #225

kasir-barati opened this issue Dec 3, 2024 · 1 comment

Comments

@kasir-barati
Copy link

Hey guys,

I have seen issue #41 but I have a different case, I have an optional field defined in my model:

model AlertType {
  id                  String    @id @default(uuid())
  name           String    @unique @db.VarChar(200)
  description String?   @db.VarChar(500)
  // ...
}

And it is generating the following model for it:

// ...
@ObjectType()
export class Alert {
    @Field(() => ID, {nullable:false})
    id!: string;

    @Field(() => String, {nullable:false})
    title!: string;

    @Field(() => String, {nullable:true})
    description!: string | null;

    // ...
}

I am running into the same issue in my code. Do you think I am missing something? Here is my repo: https://github.com/kasir-barati/graphql/tree/main/apps/botprobe-nest

To reproduce:

  1. pnpm i.
  2. nx prisma-generate botprobe-nest.
  3. Then open apps/botprobe-nest/src/@generated/alert/alert.model.

Anything I can do to make it optional like what happens to the relation fields?

@kasir-barati
Copy link
Author

BTW This did not cause me any trouble in runtime but still it is kinda annoying. Although I am not sure if this is such a bad thing.

@kasir-barati kasir-barati changed the title Optional fields are marked as not nullable in TS Optional fields are not optional in the generated TS class Dec 3, 2024
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

1 participant