Derive Macro async_graphql::InputObject[][src]

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

Define a GraphQL input object

See also the Book.

Macro attributes

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

Field attributes

AttributedescriptionTypeOptional
nameField namestringY
defaultUse Default::default for default valuenoneY
defaultArgument default valueliteralY
default_withExpression to generate default valuecode stringY
validatorInput value validator See also the BookobjectY
flattenSimilar to serde (flatten)booleanY
skipSkip this field, use Default::default to get a default value for this field.boolY
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
secretMark this field as a secret, it will not output the actual value in the log.boolY

Examples

use async_graphql::*;

#[derive(InputObject)]
struct MyInputObject {
    a: i32,
    #[graphql(default = 10)]
    b: i32,
}

struct Query;

#[Object]
impl Query {
    /// value
    async fn value(&self, input: MyInputObject) -> i32 {
        input.a * input.b
    }
}

tokio::runtime::Runtime::new().unwrap().block_on(async move {
    let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
    let res = schema.execute(r#"
    {
        value1: value(input:{a:9, b:3})
        value2: value(input:{a:9})
    }"#).await.into_result().unwrap().data;
    assert_eq!(res, value!({ "value1": 27, "value2": 90 }));
});