Derive Macro async_graphql::SimpleObject

source ·
#[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 attributes

AttributedescriptionTypeOptional
nameObject namestringY
name_typeIf true, the object name will be specified from async_graphql::TypeName traitboolY
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
shareableIndicate that an object type’s field is allowed to be resolved by multiple subgraphsboolY
inaccessibleIndicate that an object is not accessible from a supergraph when using Apollo FederationboolY
tagArbitrary string metadata that will be propagated to the supergraph when using Apollo Federation. This attribute is repeatablestringY
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
guardField of guard See also the BookstringY

Field attributes

AttributedescriptionTypeOptional
skipSkip this fieldboolY
skip_outputSkip this field, similar to skip, but avoids conflicts when this macro is used with InputObject.boolY
nameField namestringY
deprecationField deprecatedboolY
deprecationField deprecation reasonstringY
derivedGenerate derived fields See also the Book.objectY
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
shareableIndicate that a field is allowed to be resolved by multiple subgraphsboolY
inaccessibleIndicate that a field is not accessible from a supergraph when using Apollo FederationboolY
tagArbitrary string metadata that will be propagated to the supergraph when using Apollo Federation. This attribute is repeatablestringY
override_fromMark the field as overriding a field currently present on another subgraph. It is used to migrate fields between subgraphs.stringY
guardField of guard See also the BookstringY
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
flattenSimilar to serde (flatten)booleanY

Derived attributes

AttributedescriptionTypeOptional
nameGenerated derived field namestringN
intoType to derived an intostringY
ownedField resolver return a ownedship valueboolY
withFunction to apply to manage advanced use casesstringY

Examples

use async_graphql::*;

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

let schema = Schema::new(Query{ value: 10 }, EmptyMutation, EmptySubscription);
let res = schema.execute("{ value }").await.into_result().unwrap().data;
assert_eq!(res, value!({
    "value": 10,
}));