Input objects
A GraphQL input object is a reusable structure accepted by a field or nested inside another
input. #[derive(Input)] implements the Rust side. #[derive(Args)] is an alias whose default
form is "this type is only a field's argument list".
Arguments versus named inputs
Args without a name produces top-level arguments and no extra GraphQL type:
The field declares friends(limit: Int! = 10, after: String). There is no FriendsArgs input
object in the schema.
When the type is nested inside another input, give it a GraphQL name:
Using an unnamed input in a nested position is a build error that tells you to add a
#[graphql(name = "...")].
Fields and defaults
Every Rust field becomes an input field:
Option<T>is optional and nullable.- A non-
Optionfield without a default is required and non-null. - A default applies when the field is omitted. An explicit
nullis stillNone. - A default can be a Rust expression.
#[derive(Input)]implementsIntoValue, so a default can be a value of that type:
Validation
Validation runs after coercion and before the resolver. On a field the function receives the
field's Rust type; on the input type it receives &Self:
For rules that need the request context, use FieldConfig::validate::<ArgsType>(...). It runs
after input-level validation and before the resolver.
One-of inputs
The generated input uses @oneOf. Every field must be Option<T>, no field may have a default,
and clients must send exactly one non-null field. A one-of input is an input object; wrap it in an
args type if a field should take it as its only argument.
Descriptions and deprecations
#[graphql(deprecated)] uses the specification's default reason.
Type mapping
Input fields use the same Rust mapping as fields: String/i32/bool/f64, Option, Vec,
derived enums, derived named inputs, custom scalars and ID. Output-only types — objects,
interfaces and unions — cannot appear in an input.
Rules for derived inputs
- Structs only. Tuple structs and enums are not input objects.
- No generics.
- Named inputs must not shadow a built-in scalar name (
String,Int,Float,Boolean,ID). #[graphql(one_of)]and#[graphql(validate)]are type-level attributes.- Field attributes are
name,description,default,default_with,deprecatedandvalidate.
