Skip to content

Commit

Permalink
Added validation pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
TannerGabriel committed Jul 5, 2019
1 parent 3746c2d commit aa251e9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions nest-graph-ql/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions nest-graph-ql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@nestjs/mongoose": "^6.1.2",
"@nestjs/platform-express": "^6.0.0",
"apollo-server-express": "^2.7.0-alpha.3",
"class-transformer": "^0.2.3",
"graphql": "^14.4.1",
"graphql-tools": "^4.0.5",
"mongoose": "^5.6.2",
Expand Down
6 changes: 6 additions & 0 deletions nest-graph-ql/src/items/dto/create-item.dto.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { ObjectType, Field, Int, ID } from 'type-graphql';
import { IsString, IsNotEmpty, IsNumber } from 'class-validator';

@ObjectType()
export class ItemType {
@Field(() => ID)
@IsString()
readonly id: string;
@Field()
@IsString()
@IsNotEmpty()
readonly title: string;
@Field(() => Int)
@IsNumber()
readonly price: number;
@Field()
@IsString()
readonly description: string;
}
2 changes: 2 additions & 0 deletions nest-graph-ql/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { ValidationPipe } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useGlobalPipes(new ValidationPipe());
await app.listen(3000);
}
bootstrap();

0 comments on commit aa251e9

Please sign in to comment.