-
Notifications
You must be signed in to change notification settings - Fork 275
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
Using NexusTypes with ZOD validation tool (Or yup, joy ...) #1133
Comments
Hello @Capsicum42 Also, I think that using a validation library (e.g. zod, yup,...) with graphql is not a very good idea because the main objective of these libraries is to check that types are correct. graphql does this for us already. Please, read through motivation section to further know what I mean. |
As pointed out by ahmedosama, the basic typings are validated automatically by GraphQL. For typing beyond this, I do create a specific "business logic" schema such as If you are needing auto-generated schema to compliment your nexus types, you may want to consider a tool such as ts-to-zod, which can take your generated types in |
Hello @jakobo You can also build your own custom resuable validators (which can return promises that we internally resolve without sacrificing the performance of synchronous validators). Moreover, we provide typesafe transformation for arguemnts before validating them. e.g. trimming strings, converting to lowercase/uppercase, clamping a numeric argument or any kind of transformation you want. |
I try to create a validation of my input args of Nexus e.g.
const MembersFilter = inputObjectType({ name: 'MembersFilter', definition(t) { t.list.string('memberIds', { nullable: true }) }, })
with the ZOD https://github.com/colinhacks/zod#basic-usage validation libray.
e.g. min characters 3, max 10 of memberId
Currently I define the type twice and keep them in sync.
Has anybody an Idea how to define it once (in typescript) and then use it in both tools ?
Regards
Holger
The text was updated successfully, but these errors were encountered: