Skip to main content

Generate GraphQL Schemas from your SQLAlchemy models

Project description

graphql-sqlalchemy

PyPI version Build Status codecov Code Style

Generate GraphQL Schemas from your SQLAlchemy models

Install

pip install graphql-sqlalchemy

Usage

    from ariadne.asgi import GraphQL
    from fastapi import FastAPI
    from sqlalchemy import create_engine
    from sqlalchemy.ext.declarative import declarative_base
    from sqlalchemy.orm import sessionmaker
    from graphql_sqlalchemy import build_schema

    engine = create_engine('sqlite:///config.db')
    Base = declarative_base()
    Session = sessionmaker(bind=engine)

    app = FastAPI()
    session = Session()

    schema = build_schema(Base)

    app.mount("/graphql", GraphQL(schema, context_value=dict(session=session)))

Query

query {
    user(
        where: {
            _or: [
                { id: { _gte: 5 } },
                { name: { _like: "%bob%" } },
            ]
        }
    ) {
        id
        name
    }
    user_by_pk(id: 5) {
        createtime
    }
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

graphql-sqlalchemy-0.6.1.tar.gz (9.0 kB view hashes)

Uploaded Source

Built Distribution

graphql_sqlalchemy-0.6.1-py3-none-any.whl (11.2 kB view hashes)

Uploaded Python 3

Supported by

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