MichalLytek / MichalLytek/type-graphql
Validation using zod
- Dominant language
- TypeScript
- Stars
- 8.1k
- Forks
- 672
- PR merge metrics
- No merged PRs in 30d
Description
**Is your feature request related to a problem? Please describe.**
Since my project extensively uses [zod](https://github.com/colinhacks/zod) I want to be able validate `InputType`s and maybe `ObjectType`s too using zod.
**Describe the solution you'd like**
something like this?
```ts
@InputType()
class Bar {
@ZodValidate(z.string())
@Field()
field: string;
}
```
**Describe alternatives you've considered**
Using built in `class-validator` or `joiful` as described here => https://typegraphql.com/docs/validation.html#custom-validator
**Additional context**
`joiful` does not seem to be well maintained. `class-validator` seems not bad but `zod` is already quite popular library with friendly and understandable API having high flexibility and customization. So it might be worth to integrate zod with `type-graphql`.
I feel like it is already possible to do it with zod by using Extension decorator => https://typegraphql.com/docs/extensions.html and custom validation function => https://typegraphql.com/docs/validation.html#custom-validator but I did not find examples in docs how to do that.
Basically how to extract extensions data in custom validation function?
If it is possible, I can even maybe contribute to add examples with zod validation if needed and someone can give me direction of where to start and where to look for...
So what would be the best way to integrate zod with typegraphql?
Contributor guide
Research direction
Start with the validation and extensions documentation linked in the issue, then inspect how type-graphql exposes extension data to a custom validation function. Determine whether the existing extension and custom-validator mechanisms support a zod example or require a new integration design; done means a decided integration approach and corresponding documentation or implementation scope.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100