Skip to content

Can i create or use (from external crate validator) custom validation for fields in input objects #1296

Closed Answered by tyranron
WrldEngine asked this question in Q&A
Discussion options

You must be logged in to vote

@WrldEngine well, you may use the validator crate to do exactly what you've described, and then, whenever you receive such an input object in your GraphQL resolvers, just call the .validate() and return the errors, if any.

However, the idiomatic way to deal with this kind of stuff is to "parse, don't validate". For that, we have scalars in GraphQL. Instead of just using String for your email, username and password, it's better to introduce newtypes Email, Username and Password, implementing GraphQLScalar and, of course, containing already valid values only after parsing from an input.

For password particularly, you especially need a custom GraphQLScalar which internally utilizes the secrecy

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@WrldEngine
Comment options

Answer selected by tyranron
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
support k::api Related to API (application interface)
2 participants