async-graphql/docs/en/src/define_simple_object.md

22 lines
525 B
Markdown
Raw Normal View History

2020-04-15 03:15:30 +00:00
# SimpleObject
2020-09-01 05:47:22 +00:00
`SimpleObject` directly maps all the fields of a struct to GraphQL object. You cannot define a resolver function on it - for that, see [Object](define_complex_object.html).
2020-09-28 09:44:00 +00:00
The example below defines an object `MyObject` which includes the fields `a` and `b`. `c` will be not mapped to GraphQL as it is labelled as `#[graphql(skip)]`
```rust
use async_graphql::*;
#[derive(SimpleObject)]
struct MyObject {
2020-09-13 04:12:32 +00:00
/// Value a
a: i32,
2020-09-13 04:12:32 +00:00
2020-09-28 09:44:00 +00:00
/// Value b
b: i32,
2020-09-28 09:44:00 +00:00
#[graphql(skip)]
c: i32,
}
```