JejeDev
JejeDev

Reputation: 528

How can I sanitize / serialize input data with @nestjs/graphql

I'm working on a NestJs app with graphql, and I'm trying to sanitize my resolvers inputs with class-transformer like this :

@InputType()
export class CreateUserInput {
  @Field(() => String)
  @Transform(({ value }) => value.trim())
  email!: string;
}

But the Transform content is never executed.

How can I sanitize properly with decorator in an InputType ?

Upvotes: 1

Views: 1589

Answers (1)

Jay McDoniel
Jay McDoniel

Reputation: 70171

To use the @Transform() decorator, you need to have the ValidationPipe bound to the route, resolver, or server, and you need to set the transform option to true

Upvotes: 6

Related Questions