async-graphql/docs/zh-CN/src/define_enum.md

23 lines
505 B
Markdown
Raw Normal View History

2020-04-15 03:15:30 +00:00
# 枚举(Enum)
2020-04-16 03:06:09 +00:00
2020-04-16 03:51:23 +00:00
定义枚举相当简单,直接给出一个例子。
2020-04-16 03:06:09 +00:00
**Async-graphql会自动把枚举项的名称转换为GraphQL标准的大写加下划线形式你也可以用`name`属性自已定义名称。**
```rust
2020-04-16 07:09:09 +00:00
use async_graphql::*;
2020-09-13 04:12:32 +00:00
/// One of the films in the Star Wars Trilogy
#[derive(Enum, Copy, Clone, Eq, PartialEq)]
2020-04-16 03:06:09 +00:00
pub enum Episode {
2020-09-13 04:12:32 +00:00
/// Released in 1977.
2020-04-16 03:06:09 +00:00
NewHope,
2020-09-13 04:12:32 +00:00
/// Released in 1980.
2020-04-16 03:06:09 +00:00
Empire,
2020-09-13 04:12:32 +00:00
/// Released in 1983.
#[item(name="AAA")]
2020-04-16 03:06:09 +00:00
Jedi,
}
```