async-graphql/src/types/external/uuid08.rs
Sunli 7a365d5659 Release 4.0.0-alpha.1
async-graphql@4.0.0-alpha.1
async-graphql-actix-web@4.0.0-alpha.1
async-graphql-axum@4.0.0-alpha.1
async-graphql-derive@4.0.0-alpha.1
async-graphql-parser@4.0.0-alpha.1
async-graphql-poem@4.0.0-alpha.1
async-graphql-rocket@4.0.0-alpha.1
async-graphql-tide@4.0.0-alpha.1
async-graphql-value@4.0.0-alpha.1
async-graphql-warp@4.0.0-alpha.1

Generated by cargo-workspaces
2022-05-05 12:49:58 +08:00

30 lines
981 B
Rust

use uuid08::Uuid;
use crate::{InputValueError, InputValueResult, Scalar, ScalarType, Value};
#[Scalar(
internal,
name = "UUID",
specified_by_url = "http://tools.ietf.org/html/rfc4122"
)]
/// A UUID is a unique 128-bit number, stored as 16 octets. UUIDs are parsed as
/// Strings within GraphQL. UUIDs are used to assign unique identifiers to
/// entities without requiring a central allocating authority.
///
/// # References
///
/// * [Wikipedia: Universally Unique Identifier](http://en.wikipedia.org/wiki/Universally_unique_identifier)
/// * [RFC4122: A Universally Unique IDentifier (UUID) URN Namespace](http://tools.ietf.org/html/rfc4122)
impl ScalarType for Uuid {
fn parse(value: Value) -> InputValueResult<Self> {
match value {
Value::String(s) => Ok(Uuid::parse_str(&s)?),
_ => Err(InputValueError::expected_type(value)),
}
}
fn to_value(&self) -> Value {
Value::String(self.to_string())
}
}