Skip to main content

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.

CI PyPI Coverage


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 GraftModel instead of both SQLModel and a Strawberry type.
  • Auto GraphQL schema — queries, mutations (PUT / DELETE), and paginated connections generated automatically.
  • DataLoaders — declare relations with Dl and ManyRelation; N+1 queries solved out of the box.
  • Composable filters — date ranges, ordering, and custom filter attributes, all typed.
  • Permission hooks — override permission_getter per-model or supply a global get_permission function.
  • 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

  1. Fork the repository at <YOUR_REPO_URL>.
  2. Create a feature branch: git checkout -b feat/my-change.
  3. Make your changes and add tests.
  4. Run the test suite: pytest.
  5. 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

bootgraph-1.21.0.dev34977.tar.gz (24.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bootgraph-1.21.0.dev34977-py3-none-any.whl (28.0 kB view details)

Uploaded Python 3

File details

Details for the file bootgraph-1.21.0.dev34977.tar.gz.

File metadata

  • Download URL: bootgraph-1.21.0.dev34977.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

Hashes for bootgraph-1.21.0.dev34977.tar.gz
Algorithm Hash digest
SHA256 54380922cc49f46ba1357a27055ad99e989f514d61923b1a0a8ee94fbf499358
MD5 4252a3bac103554d2494ba3f83492ddc
BLAKE2b-256 14256ede2088600a277904385c143d778f0a3ccc1c0067fae36b3d2ccf3eb73f

See more details on using hashes here.

File details

Details for the file bootgraph-1.21.0.dev34977-py3-none-any.whl.

File metadata

  • Download URL: bootgraph-1.21.0.dev34977-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

Hashes for bootgraph-1.21.0.dev34977-py3-none-any.whl
Algorithm Hash digest
SHA256 b454827378ca642456933aeb65900d258e170573e73329cb5180b76e36db46d2
MD5 ddd4ab62d3c5c40fc8e82fa13ead9a8e
BLAKE2b-256 b0da34be6aeb7b51d36b8749eeb04eba5753c416393218366b2425dffae13f6c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page