Skip to content

GraphQL

The mabat-graphql crate generates an async-graphql schema from the views and every view they reach. Each root field runs one load of exactly the fields the query selects (MPA-GQL-1, MPA-GQL-4).

let schema = mabat_graphql::schema(&pool)
.list::<TaskView>("tasks") // tasks(where, orderBy, limit, offset): [TaskView!]!
.by_key::<TaskView>("task") // task(key: UUID!): TaskView
.registry(mabat) // optional: the registry's overrides
.connections(4) // optional: each level's queries concurrently
.finish()?;
{
tasks(where: { name: { ilike: "%release%" } }, orderBy: [{ name: ASC }], limit: 10) {
name
assignee { name } # one batched query
children(orderBy: [{ position: ASC }], limit: 3) { # the first three of each task, one query
name
}
}
}
RustGraphQL
A view, an embedded structAn object type named after the Rust type, fields named as in Rust
An enum with dataA union of {Enum}{Variant} objects, each with a _variant field
An enum without dataA GraphQL enum
A map collectionA list of { key: String!, value }
ColumnsBoolean, Int, Float, String, or the scalars BigInt, UUID, Date, Time, DateTime, NaiveDateTime, Decimal, JSON, Bytes

See MPA-GQL-2.

List fields — at the root and nested — take where (eq, ne, lt, le, gt, ge, in, notIn, isNull, and like/ilike for strings, combined with and, or, not), orderBy, limit and offset; nested ones apply to the elements of each parent. by_key fields take key (MPA-GQL-3).

Terminal window
cargo run -p mabat-graphql --example chinook # Chinook on SQLite, GraphiQL at http://127.0.0.1:8000