async-graphql/src/types/external/uuid.rs

17 lines
454 B
Rust
Raw Normal View History

use crate::{GQLScalar, InputValueError, InputValueResult, ScalarType, Value};
2020-03-01 10:54:34 +00:00
use uuid::Uuid;
#[GQLScalar(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
}
}