[][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(validators(Email))] email: String) -> i32 {
        unimplemented!()
    }

    // Input is email or MAC address
    #[field]
    async fn value2(&self, #[arg(validators(or(Email, MAC(colon: false))))] email_or_mac: String) -> i32 {
        unimplemented!()
    }

    // Input is integer between 100 and 200
    #[field]
    async fn value3(&self, #[arg(validators(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.

Loading content...

Implementors

impl InputValueValidator for Email[src]

impl InputValueValidator for IntGreaterThan[src]

impl InputValueValidator for IntLessThan[src]

impl InputValueValidator for IntRange[src]

impl InputValueValidator for MAC[src]

Loading content...