async_graphql/types/external/bool.rs
1use crate::{InputValueError, InputValueResult, Scalar, ScalarType, Value};
2
3/// The `Boolean` scalar type represents `true` or `false`.
4#[Scalar(internal, name = "Boolean")]
5impl ScalarType for bool {
6 fn parse(value: Value) -> InputValueResult<Self> {
7 match value {
8 Value::Boolean(n) => Ok(n),
9 _ => Err(InputValueError::expected_type(value)),
10 }
11 }
12
13 fn is_valid(value: &Value) -> bool {
14 matches!(value, Value::Boolean(_))
15 }
16
17 fn to_value(&self) -> Value {
18 Value::Boolean(*self)
19 }
20}