[−][src]Derive Macro async_graphql::GQLSimpleObject
#[derive(GQLSimpleObject)] { // Attributes available to this derive: #[field] #[graphql] }
Define a GraphQL object with fields
Similar to Object
, but defined on a structure that automatically generates getters for all fields. For a list of valid field types, see Object
. All fields are converted to camelCase.
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 |
owned | Field resolver return a ownedship value | bool | Y |
cache_control | Field cache control | CacheControl | Y |
external | Mark a field as owned by another service. This allows service A to use fields from service B while also knowing at runtime the types of that field. | bool | Y |
provides | Annotate the expected returned fieldset from a field on a base type that is guaranteed to be selectable by the gateway. | string | Y |
requires | Annotate the required input fieldset from a base type for a resolver. It is used to develop a query plan where the required fields may not be needed by the client, but the service may need additional information from other services. | string | Y |
guard | Field of guard | Guard | Y |
feature | It's like a #[cfg(feature = "foo")] attribute but instead of not compiling this field it will just return a proper FieldError to tell you this feature is not enabled | string ("feature1,feature2") | Y |
Examples
use async_graphql::*; #[derive(GQLSimpleObject)] struct QueryRoot { value: i32, } async_std::task::block_on(async move { let schema = Schema::new(QueryRoot{ value: 10 }, EmptyMutation, EmptySubscription); let res = schema.execute("{ value }").await.into_result().unwrap().data; assert_eq!(res, serde_json::json!({ "value": 10, })); });