[−][src]Attribute Macro async_graphql::SimpleObject
#[SimpleObject]
Define a GraphQL object
Similar to Object
, but defined on a structure that automatically generates getters for all fields.
Macro parameters
Attribute | description | Type | Optional |
---|---|---|---|
name | Object name | string | Y |
desc | Object description | string | Y |
cache_control | Object cache control | CacheControl | Y |
Field parameters
Attribute | description | Type | Optional |
---|---|---|---|
name | Field name | string | Y |
desc | Field description | string | Y |
deprecation | Field deprecation reason | string | Y |
cache_control | Field cache control | CacheControl | Y |
Examples
use async_graphql::*; #[SimpleObject] struct QueryRoot { #[field] value: i32, } #[async_std::main] async fn main() { let schema = Schema::new(QueryRoot{ value: 10 }, EmptyMutation, EmptySubscription); let res = schema.query("{ value }").execute().await.unwrap().data; assert_eq!(res, serde_json::json!({ "value": 10, })); }