async-graphql/src/scalars/uuid.rs

18 lines
474 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
use uuid::Uuid;
#[Scalar(internal, name = "UUID")]
impl ScalarType for Uuid {
fn parse(value: Value) -> InputValueResult<Self> {
2020-03-01 10:54:34 +00:00
match value {
Value::String(s) => Ok(Uuid::parse_str(&s)?),
_ => Err(InputValueError::ExpectedType(value)),
2020-03-01 10:54:34 +00:00
}
}
fn to_value(&self) -> Value {
Value::String(self.to_string())
2020-03-01 10:54:34 +00:00
}
}