Search code examples
graphqlnestjsclass-transformer

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 ?


Solution

  • 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