async-graphql/tests/raw_ident.rs

78 lines
1.7 KiB
Rust
Raw Normal View History

use async_graphql::*;
2020-09-10 11:35:48 +00:00
use futures::{Stream, StreamExt, TryStreamExt};
#[async_std::test]
pub async fn test_input_value_custom_error() {
#[Enum]
#[allow(non_camel_case_types)]
enum MyEnum {
r#type,
}
#[SimpleObject]
struct MyObject {
r#i32: i32,
}
#[InputObject]
struct MyInputObject {
r#i32: i32,
}
struct Query;
#[Object]
impl Query {
async fn r#type(&self, r#i32: i32) -> i32 {
r#i32
}
async fn obj(&self, obj: MyInputObject) -> MyObject {
MyObject { r#i32: obj.r#i32 }
}
async fn enum_value(&self, value: MyEnum) -> MyEnum {
value
}
}
struct SubscriptionRoot;
#[Subscription]
impl SubscriptionRoot {
async fn r#type(&self) -> impl Stream<Item = i32> {
futures::stream::iter(0..10)
}
}
let schema = Schema::new(Query, EmptyMutation, SubscriptionRoot);
let query = r#"
{
type(i32: 99)
obj(obj: { i32: 88} ) { i32 }
enumValue(value: TYPE)
}"#;
assert_eq!(
2020-09-10 11:35:48 +00:00
schema.execute(query).await.unwrap().data,
serde_json::json!({
"type": 99,
"obj": { "i32": 88 },
"enumValue": "TYPE",
})
);
let mut stream = schema
2020-09-10 11:35:48 +00:00
.execute_stream("subscription { type }")
.await
2020-09-10 11:35:48 +00:00
.unwrap()
.map(|resp| resp.into_result())
.map_ok(|resp| resp.data);
for i in 0..10 {
assert_eq!(
Some(Ok(serde_json::json!({ "type": i }))),
stream.next().await
);
}
assert!(stream.next().await.is_none());
}