Nestjs validation pipe not working with Graphql

Viewed 621

I am new to nestJS and I have added a ValidationPipe() to main.ts

app.useGlobalPipes(new ValidationPipe())

Now I am using class-validator decorators inside my DTO's but nothing is working right now. I am using GraphQl but as I have already configured the pipe globally it must work.

Is there any more configuration that needs to be done and I am missing that? Please help.

2 Answers

Try with transform:

app.useGlobalPipes(new ValidationPipe({ transform: true }));

This is working for me:

import { Module } from '@nestjs/common';
import { APP_PIPE } from '@nestjs/core';

@Module({
  providers: [
    {
      provide: APP_PIPE,
      useClass: ValidationPipe,
    },
  ],
})
export class AppModule {}
Related