fix: add test case for serializing issue

This commit is contained in:
Miaxos 2021-08-18 14:22:17 +00:00
parent f31b8b0a04
commit b55c432886
1 changed files with 42 additions and 0 deletions

42
tests/serializer_uuid.rs Normal file
View File

@ -0,0 +1,42 @@
use async_graphql::*;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
#[repr(transparent)]
#[serde(transparent)]
struct AssetId(pub uuid::Uuid);
async_graphql::scalar!(AssetId);
#[tokio::test]
/// Test case for
/// https://github.com/async-graphql/async-graphql/issues/603
pub async fn test_serialize_uuid() {
let generated_uuid = uuid::Uuid::new_v4();
struct Query {
data: AssetId,
}
#[Object]
impl Query {
async fn data(&self) -> &AssetId {
&self.data
}
}
let schema = Schema::new(
Query {
data: AssetId(generated_uuid),
},
EmptyMutation,
EmptySubscription,
);
let query = r#"{ data }"#;
assert_eq!(
schema.execute(query).await.data,
value!({
"data": generated_uuid.to_string(),
})
);
}