async-graphql/src/scalars/bool.rs

25 lines
622 B
Rust
Raw Normal View History

use crate::{InputValueError, InputValueResult, Result, ScalarType, Value};
use async_graphql_derive::Scalar;
2020-03-01 10:54:34 +00:00
#[Scalar(internal)]
impl ScalarType for bool {
2020-03-01 10:54:34 +00:00
fn type_name() -> &'static str {
2020-03-03 11:15:18 +00:00
"Boolean"
2020-03-01 10:54:34 +00:00
}
2020-03-03 11:15:18 +00:00
fn description() -> Option<&'static str> {
Some("The `Boolean` scalar type represents `true` or `false`.")
}
fn parse(value: &Value) -> InputValueResult<Self> {
2020-03-01 10:54:34 +00:00
match value {
Value::Boolean(n) => Ok(*n),
_ => Err(InputValueError::ExpectedType),
2020-03-01 10:54:34 +00:00
}
}
2020-03-25 03:39:28 +00:00
fn to_json(&self) -> Result<serde_json::Value> {
Ok((*self).into())
2020-03-01 10:54:34 +00:00
}
}