[][src]Derive Macro async_graphql::SimpleObject

#[derive(SimpleObject)]
{
    // Attributes available to this derive:
    #[graphql]
}

Define a GraphQL object with fields

See also the Book.

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

AttributedescriptionTypeOptional
nameObject namestringY
rename_fieldsRename all the fields according to the given case convention. The possible values are "lowercase", "UPPERCASE", "PascalCase", "camelCase", "snake_case", "SCREAMING_SNAKE_CASE".stringY
cache_controlObject cache controlCacheControlY
extendsAdd fields to an entity that's defined in another serviceboolY

Field parameters

AttributedescriptionTypeOptional
skipSkip this fieldboolY
nameField namestringY
deprecationField deprecation reasonstringY
ownedField resolver return a ownedship valueboolY
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::*;

#[derive(SimpleObject)]
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, value!({
        "value": 10,
    }));
});