[][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

AttributedescriptionTypeOptional
nameObject namestringY
descObject descriptionstringY
cache_controlObject cache controlCacheControlY

Field parameters

AttributedescriptionTypeOptional
nameField namestringY
descField descriptionstringY
deprecationField deprecation reasonstringY
cache_controlField cache controlCacheControlY
externalMark 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.boolY
providesAnnotate the expected returned fieldset from a field on a base type that is guaranteed to be selectable by the gateway.stringY
requiresAnnotate 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.stringY
guardField of guardGuardY

Examples

use async_graphql::*;

#[SimpleObject]
struct QueryRoot {
    value: i32,
}

#[async_std::main]
async fn main() {
    let schema = Schema::new(QueryRoot{ value: 10 }, EmptyMutation, EmptySubscription);
    let res = schema.execute("{ value }").await.unwrap().data;
    assert_eq!(res, serde_json::json!({
        "value": 10,
    }));
}