#[derive(GQLEnum)]
{
// Attributes available to this derive:
#[item]
#[graphql]
}
Define a GraphQL enum
See also the Book.
Attribute | description | Type | Optional |
name | Enum name | string | Y |
desc | Enum description | string | Y |
Attribute | description | Type | Optional |
name | Item name | string | Y |
desc | Item description | string | Y |
deprecation | Item deprecation reason | string | Y |
use async_graphql::*;
#[derive(GQLEnum, Copy, Clone, Eq, PartialEq)]
enum MyEnum {
A,
#[item(name = "b")] B,
}
struct QueryRoot {
value1: MyEnum,
value2: MyEnum,
}
#[GQLObject]
impl QueryRoot {
#[field(desc = "value")]
async fn value1(&self) -> MyEnum {
self.value1
}
#[field(desc = "value")]
async fn value2(&self) -> MyEnum {
self.value2
}
}
async_std::task::block_on(async move {
let schema = Schema::new(QueryRoot{ value1: MyEnum::A, value2: MyEnum::B }, EmptyMutation, EmptySubscription);
let res = schema.execute("{ value1 value2 }").await.into_result().unwrap().data;
assert_eq!(res, serde_json::json!({ "value1": "A", "value2": "b" }));
});