Merge pull request #604 from Miaxos/fix-serializer-issue

FIX: Serializing issue
This commit is contained in:
Sunli 2021-08-19 09:24:09 +08:00 committed by GitHub
commit dc8a1df659
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 1 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(),
})
);
}

View File

@ -249,7 +249,7 @@ impl ser::Serializer for Serializer {
#[inline]
fn is_human_readable(&self) -> bool {
false
true
}
}