[][src]Trait async_graphql::validators::InputValueValidator

pub trait InputValueValidator where
    Self: Sync + Send
{ fn is_valid(&self, value: &Value) -> Option<String>; }

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.

Loading content...

Implementors

impl InputValueValidator for Email[src]

impl InputValueValidator for IntGreaterThan[src]

impl InputValueValidator for IntLessThan[src]

impl InputValueValidator for IntNonZero[src]

impl InputValueValidator for IntRange[src]

impl InputValueValidator for ListMaxLength[src]

impl InputValueValidator for ListMinLength[src]

impl InputValueValidator for MAC[src]

impl InputValueValidator for StringMaxLength[src]

impl InputValueValidator for StringMinLength[src]

Loading content...