2

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.

Rahul Agrawal
  • 303
  • 3
  • 12
  • Honestly, that should be all that's necessary. And specifying the type in the route handler, just as you do with REST. Can you provide a minimum reproduction? Or access to your code? Show what isn't working. – Jay McDoniel Jan 08 '21 at 16:51
  • Did you resolve this? – Ajvo May 20 '21 at 09:47

2 Answers2

0

Try with transform:

app.useGlobalPipes(new ValidationPipe({ transform: true }));
Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
Jeremy Meek
  • 140
  • 2
  • 6
0

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 {}
Oro
  • 2,250
  • 1
  • 6
  • 22