Projections/Schema/Field
@validate
Use the @validate
directive to validate the content of a field.
You can use all "baked-in validations" specified in this library.
Scope of Validation Statements
The only restriction for this directive is that you cannot perform validations based on other fields.
Example
We want to check if the email is a valid email address and if it is lowercase. This is the first option to achieve this:
type User @upsertOn(...) {
email: String! @validate(tags: ["email"]) @validate(tags: ["lowercase"])
}
As you can see, the @validate
directive can be used multiple times to specify multiple validations.
Another option is to use the tags
parameter to specify multiple validations:
type User @upsertOn(...) {
email: String! @validate(tags: ["email", "lowercase"])
}
Both examples will validate the email field with the email
and lowercase
tags.