1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
Define a GraphQL enum
*[See also the Book](https://async-graphql.github.io/async-graphql/en/define_enum.html).*
# Macro attributes
| Attribute | description | Type | Optional |
|--------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------|----------|
| name | Enum name | string | Y |
| name_type | If `true`, the enum name will be specified from [`async_graphql::TypeName`](https://docs.rs/async-graphql/latest/async_graphql/trait.TypeName.html) trait | bool | Y |
| display | Implements `std::fmt::Display` for the enum type | bool | 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](https://async-graphql.github.io/async-graphql/en/visibility.html).* | bool | Y |
| visible | Call the specified function. If the return value is `false`, it will not be displayed in introspection. | string | Y |
| inaccessible | Indicate that an enum is not accessible from a supergraph when using Apollo Federation | bool | Y |
| tag | Arbitrary string metadata that will be propagated to the supergraph when using Apollo Federation. This attribute is repeatable | string | Y |
| directives | Directives | expr | Y |
# Item attributes
| 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](https://async-graphql.github.io/async-graphql/en/visibility.html).* | bool | Y |
| visible | Call the specified function. If the return value is `false`, it will not be displayed in introspection. | string | Y |
| inaccessible | Indicate that an item is not accessible from a supergraph when using Apollo Federation | bool | Y |
| tag | Arbitrary string metadata that will be propagated to the supergraph when using Apollo Federation. This attribute is repeatable | string | Y |
| directives | Directives | expr | Y |
# Examples
```rust
use async_graphql::*;
#[derive(Enum, Copy, Clone, Eq, PartialEq)]
enum MyEnum {
A,
#[graphql(name = "b")] B,
}
struct Query {
value1: MyEnum,
value2: MyEnum,
}
#[Object]
impl Query {
/// value1
async fn value1(&self) -> MyEnum {
self.value1
}
/// value2
async fn value2(&self) -> MyEnum {
self.value2
}
}
# tokio::runtime::Runtime::new().unwrap().block_on(async move {
let schema = Schema::new(Query{ 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" }));
# });
```