Getting started
Build a schema, run a query, and serve it over HTTP.
In gurafi, a GraphQL schema is ordinary Rust code. You derive a model, add fields with
resolvers, and call build() to get a gql::Schema. There is no generated resolver file and no
separate schema definition to keep in sync.
Install
Add the crates for the layers you need. For an HTTP server:
gql is the specification engine. gurafi is the Rust builder. suku serves the finished
schema over HTTP. If you only need to execute against a schema in-process, gurafi and gql
are enough.
Create a schema
Schema::<()> means the schema has no request context. The root field takes no model argument:
root resolvers receive (Args, &Ctx). NoArgs is the empty arguments type.
A model type is usually the first argument of an object field:
Fields are declared explicitly. That keeps the resolver, argument type, authorization and
complexity estimate next to each other. expose! is the shortcut for a field that reads a Rust
property.
Run a query
gql::execute is async. Use any executor, including Tokio:
The response is a normal GraphQL response: data contains the result and errors contains
field or request errors.
Serve over HTTP
Open http://127.0.0.1:3000/graphql and run:
When you have a request-specific value, replace Context::empty() with your own context. The
context guide covers that pattern.
Continue building
- Objects explains models, field declarations and reopening types across modules.
- Fields covers sync/async resolvers, lists, nullability and field options.
- Using args shows how a Rust struct becomes a field's arguments.
- Context connects the server request to your resolvers.
- Using plugins covers build-time extensions such as tracing and mocks.
A complete runnable server, including Bearer-token authentication and CORS, lives in
examples/axum.
