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

25 lines
666 B
Markdown
Raw Normal View History

2020-04-15 03:15:30 +00:00
# 输入对象(InputObject)
2020-04-16 09:06:46 +00:00
2020-04-17 11:33:28 +00:00
你可以定义一个对象作为参数类型GraphQL称之为`Input Object`,输入对象的定义方式和[简单对象](define_simple_object.md)很像,不同的是,简单对象只能用于输出,而输入对象只能用于输入。
2020-04-16 09:06:46 +00:00
2020-09-28 09:44:00 +00:00
你也通过可选的`#[graphql]`属性来给字段添加描述,重命名。
2020-04-16 09:06:46 +00:00
```rust
use async_graphql::*;
#[derive(InputObject)]
2020-04-16 09:06:46 +00:00
struct Coordinate {
latitude: f64,
2020-05-26 15:27:50 +00:00
longitude: f64,
2020-04-16 09:06:46 +00:00
}
struct Mutation;
#[Object]
2020-04-16 09:06:46 +00:00
impl Mutation {
async fn users_at_location(&self, coordinate: Coordinate, radius: f64) -> Vec<User> {
// 将坐标写入数据库
// ...
}
}
```