question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ValidateNested() on nested objects

See original GitHub issue

Hi, For instance, I have my inputType class:

@InputType()
export class ReadingCreateInput {
  @Field(() => Int, { nullable: false })
  @IsNegative()
  reading!: number;

  @Field(() => Int, { nullable: false })
  previousReading!: number;

  @HideField()
  excessAmount!: number;

  @HideField()
  basicAmount!: number;

  @HideField()
  createdAt?: Date | string;
}

I want to validate the field reading, to do that I need that the args class associated has the decorator @ValidateNested() Something like this:

@ArgsType()
export class CreateOneReadingArgs {
  @Field(() => ReadingCreateInput, { nullable: false })
  @ValidateNested()
  data!: ReadingCreateInput;
}

Is there a way to set the decorator @ValidateNested() to the @Args() and to any generated nested object, setting a property to the nestgraphql generator?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
unlightcommented, Sep 11, 2021

@grodasgomez Try version from @next channel.

Config should look like:

decorate_1_type = "CreateOneUserArgs"
decorate_1_field = data
decorate_1_name = ValidateNested
decorate_1_from = "class-validator"
decorate_1_arguments = "[]"
decorate_2_type = "CreateOneUserArgs"
decorate_2_field = data
decorate_2_from = "class-transformer"
decorate_2_arguments = "['() => {propertyType.0}']"
decorate_2_name = Type
0reactions
unlightcommented, Sep 23, 2021

🎉 This issue has been resolved in version 14.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

Validating nested objects with class-validator in NestJS
Today I have for you a quick and short article. Maybe it will help someone. I'm using class-validator for request validation in NestJS ......
Read more >
validate nested objects using class-validator in nest.js controller
Try specifying the nested type with @Type : import { Type } from 'class-transformer'; export class CurrencyDTO { @ValidateNested({ each: ...
Read more >
ValidateNested does not work · Issue #443 · nestjs/nest - GitHub
When using ValidateNested from class-validator to validate a nested object on a dto, the validation passes successfully with invalid nested ...
Read more >
Validate a nested array of objects GET query parameter using ...
Then set @ValidateNested({ each: true }) , and @Type(() => YourClass in my validation schema, like this. import { DictionnaryOfValues } from './ ......
Read more >
Nested Objects and Arrays - VeeValidate
Nested Objects. You can specify a field to be nested in an object using dot paths, like what you would normally do in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found