GraftQL
SQLModel in, typed GraphQL out.
GraftQL turns your SQLModel definitions into a fully-typed GraphQL API — no schema duplication, no glue code.
Overview
GraftQL grafts a GraphQL API onto your SQL models. It builds on SQLModel, Strawberry GraphQL and FastAPI: define each model once as a GraftModel, mount a GraftRouter, and get queries, mutations, filters, pagination and N+1-safe relationships.
| You write | GraftQL gives you |
|---|---|
class Student(GraftModel, table=True) |
A table, a GraphQL type, a filter input and a paginated connection |
teacher: "Teacher" = Dl(source="teacher_id", target="id") |
A batched DataLoader-backed relationship field |
GraftRouter(engine=engine) |
A FastAPI router serving the whole schema |
Installation
Install GraftQL with pip:
pip install graftql
Or with uv:
uv add graftql
Quick Start
Create a project directory and a virtual environment:
mkdir graftql-tutorial
cd graftql-tutorial
python -m venv .venv
source .venv/bin/activate # on Windows: .venv\Scripts\activate
pip install graftql
Then follow Getting started to define your first models.