Derive Macro async_graphql::SimpleObject[][src]

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

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
visibleIf false, it will not be displayed in introspection. See also the Book.boolY
visibleCall the specified function. If the return value is false, it will not be displayed in introspection.stringY
concretesSpecify how the concrete type of the generic SimpleObject should be implemented. *See also the BookConcreteTypeY
serialResolve each field sequentially.boolY

Field parameters

AttributedescriptionTypeOptional
skipSkip this fieldboolY
nameField namestringY
deprecationField deprecatedboolY
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
visibleIf false, it will not be displayed in introspection. See also the Book.boolY
visibleCall the specified function. If the return value is false, it will not be displayed in introspection.stringY

Examples

use async_graphql::*;

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

tokio::runtime::Runtime::new().unwrap().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,
    }));
});