i am using nestjs/graphql
, and i made a dto for a graphql mutation where i used class-validator options like @IsString()
and @IsBoolean()
. for this i installed class-validator
and class-transformer
. But when i do the mutation, it gives me an unheard error. i googled it, but nothing comes out.
the error is like this:
[Nest] 5872 - 2021. 11. 21. 오후 7:56:09 ERROR [ExceptionsHandler] classTransformer.plainToClass is not a function
TypeError: classTransformer.plainToClass is not a function
at ValidationPipe.transform (/home/inust33/ubereats-backend/node_modules/@nestjs/common/pipes/validation.pipe.js:51:39)
at /home/inust33/ubereats-backend/node_modules/@nestjs/core/pipes/pipes-consumer.js:16:33
at processTicksAndRejections (internal/process/task_queues.js:95:5)
in playground, it shows me like this: graphql playground error
my dto looks like this:
@ArgsType()
export class createRestaurantDto {
@Field((type) => String)
@IsString()
@Length(5, 10)
name: string;
@Field((type) => Boolean)
@IsBoolean()
isVegan: boolean;
@Field((type) => String)
@IsString()
address: string;
@Field((type) => String)
@IsString()
ownersName: string;
@Field(() => String)
@IsString()
categoryName: string;
}
the mutation i used this dto is this:
@Mutation(() => Boolean)
async createRestaurant(
@Args() createRestaurantDto: createRestaurantDto,
): Promise<boolean> {
try {
await this.restaurantService.createRestaurant(createRestaurantDto);
return true;
} catch (e) {
console.log(e);
return false;
}
}
i did the validation pipe setting in main.ts like this:
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useGlobalPipes(new ValidationPipe());
await app.listen(3000);
}
All I can get is without setting the useGlobalPipes
option which is not what i want to do here, the mutation works out well.
could you please help me with this?
problem solved. due to recent update, [email protected] makes an error when used in validationPipe of nestJS.
you should downgrade to [email protected]
https://github.com/nestjs/nest/issues/8637
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With