#[derive(Enum)]
{
// Attributes available to this derive:
#[graphql]
}
Expand description
Define a GraphQL enum
See also the Book.
Attribute | description | Type | Optional |
name | Enum name | string | Y |
rename_items | Rename all the fields according to the given case convention. The possible values are “lowercase”, “UPPERCASE”, “PascalCase”, “camelCase”, “snake_case”, “SCREAMING_SNAKE_CASE”. | string | Y |
remote | Derive a remote enum | string | Y |
visible | If false , it will not be displayed in introspection. See also the Book. | bool | Y |
visible | Call the specified function. If the return value is false , it will not be displayed in introspection. | string | Y |
Attribute | description | Type | Optional |
name | Item name | string | Y |
deprecation | Item deprecated | bool | Y |
deprecation | Item deprecation reason | string | Y |
visible | If false , it will not be displayed in introspection. See also the Book. | bool | Y |
visible | Call the specified function. If the return value is false , it will not be displayed in introspection. | string | Y |
use async_graphql::*;
#[derive(Enum, Copy, Clone, Eq, PartialEq)]
enum MyEnum {
A,
#[graphql(name = "b")] B,
}
struct QueryRoot {
value1: MyEnum,
value2: MyEnum,
}
#[Object]
impl QueryRoot {
async fn value1(&self) -> MyEnum {
self.value1
}
async fn value2(&self) -> MyEnum {
self.value2
}
}
tokio::runtime::Runtime::new().unwrap().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, value!({ "value1": "A", "value2": "b" }));
});