2020-05-10 10:27:46 +00:00
|
|
|
use crate::{InputValueError, InputValueResult, Result, ScalarType, Value};
|
2020-04-27 09:58:10 +00:00
|
|
|
use async_graphql_derive::Scalar;
|
2020-03-01 10:54:34 +00:00
|
|
|
use uuid::Uuid;
|
|
|
|
|
2020-04-27 09:58:10 +00:00
|
|
|
#[Scalar(internal)]
|
|
|
|
impl ScalarType for Uuid {
|
2020-03-01 10:54:34 +00:00
|
|
|
fn type_name() -> &'static str {
|
|
|
|
"UUID"
|
|
|
|
}
|
|
|
|
|
2020-05-10 10:27:46 +00:00
|
|
|
fn parse(value: &Value) -> InputValueResult<Self> {
|
2020-03-01 10:54:34 +00:00
|
|
|
match value {
|
2020-05-10 10:27:46 +00:00
|
|
|
Value::String(s) => Ok(Uuid::parse_str(&s)?),
|
|
|
|
_ => 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.to_string().into())
|
2020-03-01 10:54:34 +00:00
|
|
|
}
|
|
|
|
}
|