Replies: 1 comment 1 reply
-
One way to do it would be to transform it to typescript and then use a different tool to transform typescript to zod. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We're working on a new project and decided to go with the graphql-code-generator and we're getting to the point in development we needed to solve validation and decided to go with the Zod library. It was pleasantly surprising to see that the code generator we chose already supported Zod generation!
We've got it to a point that the graphql-code-generator is producing both a GraphQL schema/types file and, based off that file, a Zod validation types file successfuly. All the basic type validation is working, but the next question was how to assigned validation rules to specific properties. For example, we would like to set the MaxLength of a string property and the Maximum value of a numeric property. We were hoping to be able to define these rules somehow on the backend via GraphQL (we're using Hot Chocolate) so that the code generator picks it up and passes it to the schema and then to Zod.
This seems to be possible according to https://the-guild.dev/graphql/codegen/plugins/typescript/typescript-validation-schema#directives
However, probably due to my own lack of GraphQL expertise, I cannot figure out how to achieve this. Is this truly possible? If so, how would one properly define a directive (or something else) on the server side GraphQL API in Hot Chocolate so that a validation rule would propagate down via the generator?
Beta Was this translation helpful? Give feedback.
All reactions