Graft turns your SQLModel definitions into a fully-typed GraphQL API — no schema duplication, no glue code.
Project description
Graft
Graft turns your SQLModel definitions into a fully-typed GraphQL API — no schema duplication, no glue code.
Overview
Graft lets you define your data models once (as GraftModel subclasses) and get a
fully-typed GraphQL API automatically — no schema duplication, no glue code. It layers on top of
SQLModel for the ORM and Strawberry
for the GraphQL schema. Mount GraftRouter in any FastAPI app and your models are immediately
queryable and mutable over GraphQL — including paginated connections, filters, ordering, and
fine-grained permission hooks.
Async (SQLAlchemy async engines) and sync engines are both supported, and multiple database engines can be registered under different names for multi-tenant or federated setups.
Features
- Single model class — extend
GraftModelinstead of bothSQLModeland a Strawberry type. - Auto GraphQL schema — queries, mutations (PUT / DELETE), and paginated connections generated automatically.
- DataLoaders — declare relations with
DlandManyRelation; N+1 queries solved out of the box. - Composable filters — date ranges, ordering, and custom filter attributes, all typed.
- Permission hooks — override
permission_getterper-model or supply a globalget_permissionfunction. - Async support — pass an async SQLAlchemy engine and Graft handles the rest.
- Multi-engine — register multiple engines by name; each model picks its engine via
__enginename__. - Federation-ready — Strawberry federation directives can be applied through the schema DSL.
Installation
pip install bootgraph
Quick Start
from datetime import date
from fastapi import FastAPI
from sqlmodel import create_engine
from bootgraph import Field, GraftModel, GraftRouter
# 1. Define your models — once. No separate Pydantic/Strawberry types needed.
class Student(GraftModel, table=True):
id: int | None = Field(primary_key=True, default=None)
name: str
birth_date: date
# 2. Create tables and mount the router.
engine = create_engine("sqlite:///./dev.db")
GraftModel.metadata.create_all(engine)
app = FastAPI()
router = GraftRouter(
engine=engine,
enable_put_mutations=True,
enable_delete_mutations=True,
)
app.include_router(router, prefix="/graphql")
# 3. Run: uvicorn main:app --reload
# Visit: http://localhost:8000/graphql
You can now run queries like:
mutation {
students {
put(input: { name: "Alice", birthDate: "2000-01-01" }) { id }
}
}
query {
students {
many { edges { node { id name birthDate } } }
}
}
Documentation
See docs for the full guide including relations, DataLoaders, authentication, async engines, and federation.
Contributing
- Fork the repository at
<YOUR_REPO_URL>. - Create a feature branch:
git checkout -b feat/my-change. - Make your changes and add tests.
- Run the test suite:
pytest. - Open a pull request.
All contributions are welcome — bug reports, documentation fixes, and new features alike.
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bootgraph-1.21.0.dev34975.tar.gz.
File metadata
- Download URL: bootgraph-1.21.0.dev34975.tar.gz
- Upload date:
- Size: 24.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b47dfee6d04dd51cfbc82fedc3db71487b8e27c868c2f16f48fd42d308aafc3
|
|
| MD5 |
9b25fee73505f0b03f3a4d353f67475b
|
|
| BLAKE2b-256 |
133e35ca4f74880b0ecd40a013cb0f590565ebf164913a8eb1108bf91a06176c
|
File details
Details for the file bootgraph-1.21.0.dev34975-py3-none-any.whl.
File metadata
- Download URL: bootgraph-1.21.0.dev34975-py3-none-any.whl
- Upload date:
- Size: 28.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
818f85243f9453320896f78641c325c1b419ea7760f117bc105c72140551baba
|
|
| MD5 |
09400029e257343b4e2e536c9464e73e
|
|
| BLAKE2b-256 |
0c6ae8fae4ff3ccb7c66790914940d8501a33570cae76357124c816e499c269f
|