Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Please read UPGRADE-v2.0.md to learn how to upgrade to Graphene 2.0.


Graphene Logo Graphene-SQLAlchemy Build Status PyPI version Coverage Status

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:

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

Release files for mja-graphene-sqlalchemy 2.2.0b0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mja-graphene-sqlalchemy 2.2.0b0
File Size Uploaded
mja-graphene-sqlalchemy-2.2.0b0.tar.gz 27.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mja-graphene-sqlalchemy 2.2.0b0
File Interpreter ABI Platform
mja_graphene_sqlalchemy-2.2.0b0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 149.7 kB

Release files / mja-graphene-sqlalchemy-2.2.0b0.tar.gz

Download URL mja-graphene-sqlalchemy-2.2.0b0.tar.gz
Size 27.4 kB
Tags Source
SHA-256 checksum
How to use checksums
2c4eb4398abec80dcec88343a8c2037d91f6a33cd21c1e44c3035daf7302fcf2
BLAKE2b-256 checksum
How to use checksums
77240a67ea9f16a6b29c056951b86c21cbd2f95097dc32780cabe477fd6da2a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.0

Release files / mja_graphene_sqlalchemy-2.2.0b0-py2.py3-none-any.whl

Download URL mja_graphene_sqlalchemy-2.2.0b0-py2.py3-none-any.whl
Size 122.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
eee56c4cd85a06e4729595d65f8665536257645d3e337bcdb08d679391704983
BLAKE2b-256 checksum
How to use checksums
424bc036c020b0a3a2e7fa7a12f88a7b6fecc9db5862d7f2523697988c522531
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.0

Release history Release notifications | RSS feed

This release

2.2.0b0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page