async-graphql/tests/enum.rs

59 lines
1.1 KiB
Rust
Raw Normal View History

2020-03-07 04:40:04 +00:00
use async_graphql::*;
#[async_std::test]
pub async fn test_enum_type() {
#[Enum]
enum MyEnum {
A,
B,
}
#[InputObject]
struct MyInput {
value: MyEnum,
}
struct Root {
value: MyEnum,
}
#[Object]
impl Root {
#[field]
async fn value(&self) -> MyEnum {
self.value
}
#[field]
async fn test_arg(&self, input: MyEnum) -> MyEnum {
input
}
#[field]
async fn test_input<'a>(&self, input: MyInput) -> MyEnum {
input.value
}
}
2020-03-17 09:26:59 +00:00
let schema = Schema::new(
Root { value: MyEnum::A },
GQLEmptyMutation,
GQLEmptySubscription,
);
2020-03-07 04:40:04 +00:00
let query = format!(
r#"{{
value
2020-03-09 12:00:57 +00:00
testArg(input: A)
testInput(input: {{value: B}}) }}
2020-03-07 04:40:04 +00:00
"#
);
assert_eq!(
schema.query(&query).execute().await.unwrap(),
serde_json::json!({
"value": "A",
2020-03-09 12:00:57 +00:00
"testArg": "A",
"testInput": "B",
2020-03-07 04:40:04 +00:00
})
);
}