async-graphql/docs/zh-CN/src/define_enum.md
2020-04-17 19:33:28 +08:00

22 lines
528 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 枚举(Enum)
定义枚举相当简单,直接给出一个例子。
**Async-graphql会自动把枚举项的名称转换为GraphQL标准的大写加下划线形式你也可以用`name`属性自已定义名称。**
```rust
use async_graphql::*;
#[Enum(desc = "One of the films in the Star Wars Trilogy")]
pub enum Episode {
#[item(desc = "Released in 1977.")]
NewHope,
#[item(desc = "Released in 1980.")]
Empire,
// rename to `AAA`
#[item(name="AAA", desc = "Released in 1983.")]
Jedi,
}
```