update some docs
This commit is contained in:
parent
a7ee9e777f
commit
943aac1d31
|
@ -8,10 +8,10 @@ Therefore, the `Object`'s fields' type, arguments must match with the `Interface
|
|||
`Async-graphql` implemented auto conversion from `Object` to `Interface`, you only need to call `Into::into`.
|
||||
|
||||
Interface fields names transforms to camelCase in schema definition.
|
||||
If you need e.g. snake_cased field name, there is `method` argument in field.
|
||||
If you need e.g. snake_cased GraphQL field name, you can use both the `name` and `method` attribute.
|
||||
|
||||
- When the `name` and `method` exist together, the `name` is the graphql name and the `method` is the rust method name.
|
||||
- When only `name` exists, `name.to_camel_case()` is the graphql name and the `name` is the rust method name.
|
||||
- When the `name` and `method` exist together, the `name` is the GraphQL field name and the `method` is the resolver function name.
|
||||
- When only `name` exists, `name.to_camel_case()` is the GraphQL field name and the `name` is the resolver function name.
|
||||
|
||||
```rust
|
||||
use async_graphql::*;
|
||||
|
|
|
@ -4,6 +4,13 @@
|
|||
|
||||
`Async-graphql`自动实现了对象到接口的转换,把一个对象类型转换为接口类型只需要调用`Into::into`。
|
||||
|
||||
接口字段的`name`属性表示转发的Resolver函数,并且它将被转换为驼峰命名作为字段名称。
|
||||
如果你需要自定义GraphQL接口字段名称,可以同时使用`name`和`method`属性。
|
||||
|
||||
- 当`name`和`method`属性同时存在时,`name`是GraphQL接口字段名,而`method`是Resolver函数名。
|
||||
- 当只有`name`存在时, 转换为驼峰命名后的`name`是GraphQL接口字段名,而`name`是Resolver函数名。
|
||||
|
||||
|
||||
```rust
|
||||
use async_graphql::*;
|
||||
|
||||
|
@ -20,6 +27,11 @@ impl Circle {
|
|||
async fn scale(&self, s: f32) -> Shape {
|
||||
Circle { radius: self.radius * s }.into()
|
||||
}
|
||||
|
||||
#[field(name = "short_description")]
|
||||
async fn short_description(&self) -> String {
|
||||
"Circle".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
struct Square {
|
||||
|
@ -35,11 +47,17 @@ impl Square {
|
|||
async fn scale(&self, s: f32) -> Shape {
|
||||
Square { width: self.width * s }.into()
|
||||
}
|
||||
|
||||
#[field(name = "short_description")]
|
||||
async fn short_description(&self) -> String {
|
||||
"Square".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
#[Interface(
|
||||
field(name = "area", type = "f32"),
|
||||
field(name = "scale", type = "Shape", arg(name = "s", type = "f32"))
|
||||
field(name = "short_description", method = "short_description", type = "String")
|
||||
)]
|
||||
enum Shape {
|
||||
Circle(Circle),
|
||||
|
|
Loading…
Reference in New Issue
Block a user