async-graphql/tests/list.rs

64 lines
1.4 KiB
Rust
Raw Normal View History

2020-03-07 04:40:04 +00:00
use async_graphql::*;
#[async_std::test]
pub async fn test_list_type() {
#[InputObject]
struct MyInput {
value: Vec<i32>,
}
struct Root {
value: Vec<i32>,
}
#[Object]
impl Root {
#[field]
async fn value_vec(&self) -> Vec<i32> {
self.value.clone()
}
#[field]
async fn value_slice(&self) -> &[i32] {
&self.value
}
#[field]
async fn test_arg(&self, input: Vec<i32>) -> Vec<i32> {
input
}
#[field]
async fn test_input<'a>(&self, input: MyInput) -> Vec<i32> {
input.value
}
}
let schema = Schema::new(
Root {
value: vec![1, 2, 3, 4, 5],
},
2020-03-19 09:20:12 +00:00
EmptyMutation,
EmptySubscription,
2020-03-07 04:40:04 +00:00
);
let json_value: serde_json::Value = vec![1, 2, 3, 4, 5].into();
let query = format!(
r#"{{
2020-03-09 12:00:57 +00:00
valueVec
valueSlice
testArg(input: {0})
testInput(input: {{value: {0}}}) }}
2020-03-07 04:40:04 +00:00
"#,
json_value
);
assert_eq!(
2020-04-02 04:53:53 +00:00
schema.execute(&query).await.unwrap().data,
2020-03-07 04:40:04 +00:00
serde_json::json!({
2020-03-09 12:00:57 +00:00
"valueVec": vec![1, 2, 3, 4, 5],
"valueSlice": vec![1, 2, 3, 4, 5],
"testArg": vec![1, 2, 3, 4, 5],
"testInput": vec![1, 2, 3, 4, 5],
2020-03-07 04:40:04 +00:00
})
);
}