2020-03-09 10:05:52 +00:00
|
|
|
use crate::{impl_scalar_internal, GQLScalar, Result, Value};
|
2020-03-01 10:54:34 +00:00
|
|
|
use uuid::Uuid;
|
|
|
|
|
2020-03-05 06:23:55 +00:00
|
|
|
impl GQLScalar for Uuid {
|
2020-03-01 10:54:34 +00:00
|
|
|
fn type_name() -> &'static str {
|
|
|
|
"UUID"
|
|
|
|
}
|
|
|
|
|
2020-03-04 02:38:07 +00:00
|
|
|
fn parse(value: &Value) -> Option<Self> {
|
2020-03-01 10:54:34 +00:00
|
|
|
match value {
|
2020-03-03 11:15:18 +00:00
|
|
|
Value::String(s) => Some(Uuid::parse_str(&s).ok()?),
|
|
|
|
_ => None,
|
2020-03-01 10:54:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-02 00:24:49 +00:00
|
|
|
fn to_json(&self) -> Result<serde_json::Value> {
|
2020-03-01 10:54:34 +00:00
|
|
|
Ok(self.to_string().into())
|
|
|
|
}
|
|
|
|
}
|
2020-03-06 15:58:43 +00:00
|
|
|
|
2020-03-09 10:05:52 +00:00
|
|
|
impl_scalar_internal!(Uuid);
|