Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/flying-sheep/graphql-sqlalchemy
Generate GraphQL Schemas from your SQLAlchemy models
https://github.com/flying-sheep/graphql-sqlalchemy
graphql graphql-query sqlalchemy sqlalchemy-orm
Last synced: 3 months ago
JSON representation
Generate GraphQL Schemas from your SQLAlchemy models
- Host: GitHub
- URL: https://github.com/flying-sheep/graphql-sqlalchemy
- Owner: flying-sheep
- License: mit
- Created: 2023-09-30T15:56:56.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-23T17:52:28.000Z (3 months ago)
- Last Synced: 2024-09-28T21:41:16.999Z (3 months ago)
- Topics: graphql, graphql-query, sqlalchemy, sqlalchemy-orm
- Language: Python
- Homepage: https://graphql-sqlalchemy.readthedocs.io/en/latest/
- Size: 168 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# graphql-sqlalchemy
[![PyPI version](https://badge.fury.io/py/graphql-sqlalchemy.svg)](https://badge.fury.io/py/graphql-sqlalchemy)
[![Unit Tests](https://github.com/flying-sheep/graphql-sqlalchemy/actions/workflows/run_tests.yml/badge.svg)](https://github.com/flying-sheep/graphql-sqlalchemy/actions/workflows/run_tests.yml)
[![codecov](https://codecov.io/gh/flying-sheep/graphql-sqlalchemy/graph/badge.svg)](https://codecov.io/gh/flying-sheep/graphql-sqlalchemy)
[![Code Style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)Generate GraphQL Schemas from your SQLAlchemy models
# Install
```
pip install graphql-sqlalchemy
```# Usage
```python
from ariadne.asgi import GraphQL
from fastapi import FastAPI
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, declarative_base
from graphql_sqlalchemy import build_schemaengine = 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
```graphql
query {
user(where: { _or: [{ id: { _gte: 5 } }, { name: { _like: "%bob%" } }] }) {
id
name
}
user_by_pk(id: 5) {
createtime
}
}
```