Reputation: 319
I would like to make some data I send in graphql mutation optional but not nullable. I'm using the code-first approach.
For example:
@InputType()
export class CreateUserDto {
@Field()
firstName?: string;
}
I understand I can use the nullable
parameter or possibly defaultValue
but none of these options are really usable in my case.
Also, I know there is the Nest's PartialType
utility but that would mean creating another file with the class if I'm correct and that doesn't seem very efficient.
Upvotes: 5
Views: 5449
Reputation: 61
set nullable to true in @Field decorator like:
@Field({ nullable: true })
So your code should be:
@InputType()
export class CreateUserDto {
@Field({ nullable: true })
firstName?: string;
}
Upvotes: 6