-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Feature: Add (Nested) Validation to Create / Update / Delete Args #23
Closed
johannesschobel
wants to merge
6
commits into
doug-martin:master
from
johannesschobel:feat/validation
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9d3a793
chore: add deps
johannesschobel 82832b4
fix: make validation pipe more restrictive
johannesschobel ea04760
feat: add a custom argstype with nested validation
johannesschobel d8b6e68
fix: BREAKING change input to id for DELETE ONE
johannesschobel edc9d2d
refactor: fix typo
johannesschobel 9620cf1
feat: add validators
johannesschobel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
examples/nest-graphql-typeorm/src/todo-item/args/custom-args.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { CreateOneArgsType } from '@nestjs-query/query-graphql'; | ||
import { Type } from 'class-transformer'; | ||
import { ValidateNested } from 'class-validator'; | ||
import { ArgsType, Field } from 'type-graphql'; | ||
import { TodoItemInputDTO } from '../dto/todo-item-input.dto'; | ||
|
||
@ArgsType() | ||
export class CreateOneTodoItemArgs extends CreateOneArgsType(TodoItemInputDTO) { | ||
@Type(() => TodoItemInputDTO) | ||
@ValidateNested() | ||
@Field({ | ||
description: 'The ToDo Item to be created', | ||
}) | ||
input!: TodoItemInputDTO; | ||
} |
4 changes: 4 additions & 0 deletions
4
examples/nest-graphql-typeorm/src/todo-item/dto/todo-item-input.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
import { IsString, MaxLength, IsBoolean } from 'class-validator'; | ||
import { Field, InputType } from 'type-graphql'; | ||
|
||
@InputType('TodoItemInput') | ||
export class TodoItemInputDTO { | ||
@IsString() | ||
@MaxLength(20) | ||
@Field() | ||
title!: string; | ||
|
||
@IsBoolean() | ||
@Field() | ||
completed!: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { Class } from '@nestjs-query/core'; | ||
import { Field, ID, ArgsType } from 'type-graphql'; | ||
import { IsNotEmpty } from 'class-validator'; | ||
|
||
export interface DeleteOneArgsType { | ||
input: string | number; | ||
id: string | number; | ||
} | ||
|
||
/** @internal */ | ||
|
@@ -13,8 +14,9 @@ export function DeleteOneArgsType(): Class<DeleteOneArgsType> { | |
} | ||
@ArgsType() | ||
class DeleteOneArgs implements DeleteOneArgsType { | ||
@IsNotEmpty() | ||
@Field(() => ID, { description: 'The id of the record to delete.' }) | ||
input!: string | number; | ||
id!: string | number; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should update the docs to reflect this change. |
||
} | ||
deleteOneArgsType = DeleteOneArgs; | ||
return deleteOneArgsType; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this required for the example?