Add feature(bson-uuid) which will enable Uuid's from the bson crate

This commit is contained in:
Jarrett Tierney 2022-03-22 20:43:54 -07:00
parent aec1f27ac6
commit 15deab33ee
2 changed files with 18 additions and 1 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "async-graphql"
version = "3.0.36"
version = "3.0.37"
authors = ["sunli <scott_s829@163.com>", "Koxiaet"]
edition = "2021"
description = "A GraphQL server library implemented in Rust"

View File

@ -2,6 +2,8 @@ use bson::{oid::ObjectId, Bson, Document};
#[cfg(feature = "chrono")]
use bson::DateTime as UtcDateTime;
#[cfg(feature = "bson-uuid")]
use bson::Uuid;
#[cfg(feature = "chrono")]
use chrono::{DateTime, Utc};
@ -21,6 +23,21 @@ impl ScalarType for ObjectId {
}
}
#[cfg(feature = "bson-uuid")]
#[Scalar(internal, name = "UUID")]
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())
}
}
#[cfg(feature = "chrono")]
#[Scalar(internal, name = "DateTime")]
impl ScalarType for UtcDateTime {