Using args
Arguments let a client pass values to a field. In gurafi they are a Rust struct, not a separate
declaration. The resolver receives the struct by value, already coerced and validated.
Scalars and required arguments
name: String is required and non-null: the generated argument is name: String!. An
Option<T> is optional and nullable:
The query can omit times or pass null; the resolver sees None in both cases.
Defaults
#[graphql(default = ...)] gives an omitted argument a value. An explicit null is still
None; a default does not replace it.
For a computed default, use #[graphql(default_with = "path")], where path() returns the field
type.
Lists
Vec<T> produces a list argument. Items are non-null unless the Rust item is Option:
The same nullability overrides are available on FieldConfig, but the safest form is to make the
Rust type express the contract.
Enums and input objects
Input enums and named input objects are ordinary derived types:
An input type used outside the top-level argument position must have a name
(#[graphql(name = "...")]). An unnamed Args type is a field's argument list, not a reusable
input object. Using one nested inside another is a build error that names the fix.
Output objects, interfaces and unions cannot be argument types.
Nested lists
Use nested Vecs, with Option for the positions that can be null:
This is groups: [[String]!]!: the outer list and each inner list are non-null, while strings
inside the inner lists may be null.
Validation
There are two validation hooks.
#[graphql(validate = "path")] runs after coercion. On a field it receives &FieldType; on the
type it receives &Self:
When the rule needs request state, validate on the field builder:
The type parameter must be the field's argument type. The hook runs after input-level validation and before the resolver. The arguments are coerced once; subscription events reuse the args validated at setup, and the field validator runs once per event.
Validation errors are client errors. gurafi attaches BAD_USER_INPUT so a server-side
mask_internal does not hide them.
One-of inputs
Every field must be Option<T>, no field may have a default, and a caller must provide exactly
one non-null field. Because a one-of input is an input object, use it inside an args type rather
than as the field's top-level argument list.
No arguments
Use gurafi::NoArgs when a field takes no arguments:
NoArgs avoids allocating an empty argument object on the hot path.
