Type inference
gurafi infers the GraphQL type from Rust. The compiler checks the resolver signature, and the
schema build checks the resulting type graph.
What is inferred
The return type of the resolver is the source of truth. The object model does not need a field with the same name; a computed field can return any supported type.
Arguments
The second resolver parameter is the argument type. Its derive supplies the GraphQL argument list:
There is no separate argument map to maintain.
Supported type constructors
Result<T, E> is deliberately not an output type. Use field_result for a GraphQL error, or
field_result_union when the error is part of the API.
Runtime names
When a type's name is only known at runtime, use ObjectRef, InterfaceRef or UnionRef:
field_ref preserves the wrapper inference from T: User is AdminUser, Vec<User> is
[AdminUser]!. For abstract types or explicit wrappers, use field_ref_type:
The build checks that the declared wrappers are compatible with the Rust type and that the named type exists.
What is not inferred
- Field names are explicit, except for
expose!, which names the GraphQL field from the Rust property. - Object fields are not derived from struct fields. This is intentional: every field needs a resolver, arguments and access policy, and deriving them would hide those decisions.
- Input types must be named when nested; the derive cannot guess a stable public name.
- A runtime type name cannot be inferred from a value. Use a reference.
Inference failures
A type that does not implement OutputType or InputType produces a compile error at the field
or argument declaration. A referenced type that is never registered is a build error:
See Troubleshooting for the common messages.
