Turbograph
PostGraphile-style GraphQL generation for PostgreSQL, implemented in Rust.
Turbograph introspects your PostgreSQL schema and builds an async-graphql schema automatically, so you can ship a production-grade GraphQL API without hand-writing CRUD resolvers.
Why Turbograph
- PostgreSQL-first approach with schema introspection.
- Rust performance and safety, powered by Tokio.
- GraphQL schema generated from database structure and relationships.
- Optional PostgreSQL watch mode for schema rebuilds on DDL changes.
- Request-level transaction settings (role, isolation, timeout, local settings).
Installation
Add the crate to your project:
Or add it manually to Cargo.toml:
[]
= "0.1"
Quick Start (Example Server)
The repository includes a runnable example server under examples/server.
- Start PostgreSQL:
- Run the example GraphQL server:
- Open GraphiQL:
http://localhost:4000/graphql
The sample database schema and seed data are in db/init.sql.
Library Usage
Minimal setup
use ;
async
Integration with Axum
use ;
use ;
async
async
async
Generated GraphQL API
For every table or view that Turbograph discovers it generates:
Queries
# List all rows with optional filtering, ordering, and pagination.
allUsers(
condition: UserCondition # per-column filter
orderBy: [UserOrderBy!] # e.g. [ID_DESC, NAME_ASC]
first: Int # LIMIT
offset: Int # OFFSET
): UserConnection!
# UserConnection exposes pagination metadata and the rows themselves.
type UserConnection {
totalCount: Int!
pageInfo: PageInfo!
edges: [UserEdge!]!
nodes: [User!]!
}
type PageInfo {
hasNextPage: Boolean!
hasPreviousPage: Boolean!
startCursor: String
endCursor: String
}
Mutations
# Insert a single row.
createUser(input: CreateUserInput!): User
# Update rows matching the condition.
updateUser(patch: UpdateUserPatch!, condition: UserCondition): [User!]!
# Delete rows matching the condition.
deleteUser(condition: UserCondition): [User!]!
Filtering
query {
allUsers(
condition: {
email: { equal: "alice@example.com" }
age: { greaterThanEqual: 18 }
}
orderBy: [CREATED_AT_DESC]
first: 10
offset: 0
) {
totalCount
nodes { id name email }
pageInfo { hasNextPage endCursor }
}
}
Every column filter supports equal, notEqual, and in.
Numeric and date/time columns also support greaterThan, greaterThanEqual,
lessThan, and lessThanEqual.
Controlling Generated Fields with @omit
Add @omit to a PostgreSQL object comment to suppress specific operations:
-- Hide all operations on a table (e.g. internal/audit tables).
COMMENT ON TABLE audit_log IS '@omit';
-- Suppress only write mutations; the table is still queryable.
COMMENT ON TABLE view_only IS '@omit create,update,delete';
-- Hide a column from the API (e.g. a password hash).
COMMENT ON COLUMN users.password_hash IS '@omit';
Materialized views automatically suppress create, update, and delete.
Request Transaction Context
Turbograph supports per-request transaction settings via TransactionConfig.
This is useful for row-level security (RLS), role switching, and session-like
values forwarded to PostgreSQL functions.
use TransactionConfig;
let tx_config = TransactionConfig ;
Inject it into the GraphQL request so Turbograph picks it up automatically:
use ;
async
Any PostgreSQL row-level security policy that reads current_setting('app.current_user_id')
will automatically see the value you set.
Release Process
Crates.io publishing is automated with GitHub Actions.
- Publishing runs when a GitHub Release is published.
- The release tag (for example
v0.1.0) must match the crate version inCargo.toml. - The workflow performs
cargo publish --dry-runbefore publishing.
Required repository secret:
CARGO_REGISTRY_TOKEN
Project Status
Turbograph is in early development and already supports:
- Database introspection and GraphQL schema generation.
- Query and mutation execution.
- Row-level security patterns through transaction-scoped context.
- Example server and integration tests.
Planned improvements include broader PostgreSQL feature coverage, richer filtering/ordering support, and more extension hooks.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgements
Inspired by PostGraphile.