You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi.
I am actively using zod schemas in my project to practically validate everything.
Some of the schemas have rules that mutate fields similar to z.string().toLowercase()
I created a middleware that would run zod.parse on args passed into the resolver in order to validate input.
However upon testing I realized that even though the validation happens the mutation does no as i am not(cannot) actually passing the result of zod.parse into the next() function.
I have also tried to do something with createParameterDecorator to maybe somehow create a custom @ValidatedArgs decorator to be used instead of the @Args decorator.
The idea is to use @ValidatedArgs(schema) to pass the schema on which the args would be processed.
I just couldn't figure out how to make it not mess with the metadata and just behave as normal @Args and thats why im asking for help.
If this is not possible is there really no better solution than to copy/paste args = schema.parse(args) into the beginning of every resolver?
Thank you)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi.
I am actively using zod schemas in my project to practically validate everything.
Some of the schemas have rules that mutate fields similar to z.string().toLowercase()
I created a middleware that would run zod.parse on args passed into the resolver in order to validate input.
However upon testing I realized that even though the validation happens the mutation does no as i am not(cannot) actually passing the result of zod.parse into the next() function.
Middleware
I have also tried to do something with createParameterDecorator to maybe somehow create a custom @ValidatedArgs decorator to be used instead of the @Args decorator.
The idea is to use @ValidatedArgs(schema) to pass the schema on which the args would be processed.
I just couldn't figure out how to make it not mess with the metadata and just behave as normal @Args and thats why im asking for help.
If this is not possible is there really no better solution than to copy/paste
args = schema.parse(args)
into the beginning of every resolver?Thank you)
Beta Was this translation helpful? Give feedback.
All reactions