[−][src]Trait async_graphql::validators::InputValueValidator
Input value validator
You can create your own input value validator by implementing this trait.
use async_graphql::*; use async_graphql::validators::{Email, MAC, IntRange}; struct QueryRoot; #[Object] impl QueryRoot { // Input is email address #[field] async fn value1(&self, #[arg(validator(Email))] email: String) -> i32 { unimplemented!() } // Input is email or MAC address #[field] async fn value2(&self, #[arg(validator(or(Email, MAC(colon = false))))] email_or_mac: String) -> i32 { unimplemented!() } // Input is integer between 100 and 200 #[field] async fn value3(&self, #[arg(validator(IntRange(min = 100, max = 200)))] value: i32) -> i32 { unimplemented!() } }
Required methods
fn is_valid(&self, value: &Value) -> Option<String>
Check value is valid, returns the reason for the error if it fails, otherwise None.
If the input type is different from the required type, return None directly, and other validators will find this error.