async-graphql/src/types/external/bool.rs
2020-10-14 11:11:52 +08:00

21 lines
559 B
Rust

use crate::{InputValueError, InputValueResult, Scalar, ScalarType, Value};
/// The `Boolean` scalar type represents `true` or `false`.
#[Scalar(internal, name = "Boolean")]
impl ScalarType for bool {
fn parse(value: Value) -> InputValueResult<Self> {
match value {
Value::Boolean(n) => Ok(n),
_ => Err(InputValueError::expected_type(value)),
}
}
fn is_valid(value: &Value) -> bool {
matches!(value, Value::Boolean(_))
}
fn to_value(&self) -> Value {
Value::Boolean(*self)
}
}