Graphene SQLAlchemy integration
Project description
Please read UPGRADE-v2.0.md to learn how to upgrade to Graphene 2.0.
Graphene-SQLAlchemy

A SQLAlchemy integration for Graphene.
Installation
For instaling graphene, just run this command in your shell
pip install "graphene-sqlalchemy>=2.0"
Examples
Here is a simple SQLAlchemy model:
from sqlalchemy import Column, Integer, String from sqlalchemy.orm import backref, relationship from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class UserModel(Base): __tablename__ = 'department' id = Column(Integer, primary_key=True) name = Column(String) last_name = Column(String)
To create a GraphQL schema for it you simply have to write the following:
from graphene_sqlalchemy import SQLAlchemyObjectType class User(SQLAlchemyObjectType): class Meta: model = UserModel class Query(graphene.ObjectType): users = graphene.List(User) def resolve_users(self, info): query = User.get_query(info) # SQLAlchemy query return query.all() schema = graphene.Schema(query=Query)
Then you can simply query the schema:
query = ''' query { users { name, lastName } } ''' result = schema.execute(query, context_value={'session': db_session})
To learn more check out the following examples:
- Full example: Flask SQLAlchemy example
Contributing
After cloning this repo, ensure dependencies are installed by running:
python setup.py install
After developing, the full test suite can be evaluated by running:
python setup.py test # Use --pytest-args="-v -s" for verbose mode
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.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size mja_graphene_sqlalchemy-2.2.0b0-py2.py3-none-any.whl (122.3 kB) | File type Wheel | Python version py2.py3 | Upload date | Hashes View |
Filename, size mja-graphene-sqlalchemy-2.2.0b0.tar.gz (27.4 kB) | File type Source | Python version None | Upload date | Hashes View |
Close
Hashes for mja_graphene_sqlalchemy-2.2.0b0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eee56c4cd85a06e4729595d65f8665536257645d3e337bcdb08d679391704983 |
|
MD5 | 23ae68f55f5b78b0ebd569835d25dbed |
|
BLAKE2-256 | 424bc036c020b0a3a2e7fa7a12f88a7b6fecc9db5862d7f2523697988c522531 |
Close
Hashes for mja-graphene-sqlalchemy-2.2.0b0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c4eb4398abec80dcec88343a8c2037d91f6a33cd21c1e44c3035daf7302fcf2 |
|
MD5 | 3be1c6df3b1b4f502bec0c7fb90a50fc |
|
BLAKE2-256 | 77240a67ea9f16a6b29c056951b86c21cbd2f95097dc32780cabe477fd6da2a5 |