async-graphql/src/scalars/bool.rs

25 lines
636 B
Rust
Raw Normal View History

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