async-graphql/src/types/external/bool.rs

24 lines
616 B
Rust
Raw Normal View History

use crate::{GQLScalar, InputValueError, InputValueResult, ScalarType, Value};
2020-03-01 10:54:34 +00:00
/// The `Boolean` scalar type represents `true` or `false`.
#[GQLScalar(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
}
}