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.dev34978.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.dev34978-py3-none-any.whl (28.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bootgraph-1.21.0.dev34978.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.dev34978.tar.gz
Algorithm Hash digest
SHA256 46fe376862a5095be8d7532eba42022d9a2682346b19148bb50b95c3eb476929
MD5 1d3fc59223a0be95302be59ed4fc66be
BLAKE2b-256 22dc29dcf7725a098e3fcd440b158a30431fcfdc2adb72fb7a067ee0a96912d9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bootgraph-1.21.0.dev34978-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.dev34978-py3-none-any.whl
Algorithm Hash digest
SHA256 c643258ff7146845abc90e2550ab802bc9925548533ab05100f8486dc29fa357
MD5 1fb0ad7b517647a10f461376f790f130
BLAKE2b-256 5cf711ed0c2a8def510756a8f1213f799f5e2dfa127316662cb506f77d583fcd

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