Add test code for generic object. #274
This commit is contained in:
parent
312b8f13d8
commit
5cb507ed90
49
tests/generic_types.rs
Normal file
49
tests/generic_types.rs
Normal file
|
@ -0,0 +1,49 @@
|
|||
use async_graphql::*;
|
||||
|
||||
#[async_std::test]
|
||||
pub async fn test_generic_object() {
|
||||
struct MyObj<T> {
|
||||
value: T,
|
||||
}
|
||||
|
||||
#[Object(name = "MyObjI32")]
|
||||
impl MyObj<i32> {
|
||||
async fn value(&self) -> i32 {
|
||||
self.value
|
||||
}
|
||||
}
|
||||
|
||||
#[Object(name = "MyObjBool")]
|
||||
impl MyObj<bool> {
|
||||
async fn value(&self) -> bool {
|
||||
self.value
|
||||
}
|
||||
}
|
||||
|
||||
struct Query;
|
||||
|
||||
#[Object]
|
||||
impl Query {
|
||||
async fn obj_i32(&self) -> MyObj<i32> {
|
||||
MyObj { value: 100 }
|
||||
}
|
||||
|
||||
async fn obj_bool(&self) -> MyObj<bool> {
|
||||
MyObj { value: true }
|
||||
}
|
||||
}
|
||||
|
||||
let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
|
||||
let query = r#"{
|
||||
objI32 { value }
|
||||
objBool { value }
|
||||
}"#
|
||||
.to_owned();
|
||||
assert_eq!(
|
||||
schema.execute(&query).await.into_result().unwrap().data,
|
||||
serde_json::json!({
|
||||
"objI32": {"value": 100},
|
||||
"objBool": {"value": true},
|
||||
})
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue
Block a user