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

Download files

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

Source Distribution

mja-graphene-sqlalchemy-2.2.0b0.tar.gz (27.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mja_graphene_sqlalchemy-2.2.0b0-py2.py3-none-any.whl (122.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file mja-graphene-sqlalchemy-2.2.0b0.tar.gz.

File metadata

  • Download URL: mja-graphene-sqlalchemy-2.2.0b0.tar.gz
  • Upload date:
  • Size: 27.4 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for mja-graphene-sqlalchemy-2.2.0b0.tar.gz
Algorithm Hash digest
SHA256 2c4eb4398abec80dcec88343a8c2037d91f6a33cd21c1e44c3035daf7302fcf2
MD5 3be1c6df3b1b4f502bec0c7fb90a50fc
BLAKE2b-256 77240a67ea9f16a6b29c056951b86c21cbd2f95097dc32780cabe477fd6da2a5

See more details on using hashes here.

File details

Details for the file mja_graphene_sqlalchemy-2.2.0b0-py2.py3-none-any.whl.

File metadata

  • Download URL: mja_graphene_sqlalchemy-2.2.0b0-py2.py3-none-any.whl
  • Upload date:
  • Size: 122.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using 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

File hashes

Hashes for mja_graphene_sqlalchemy-2.2.0b0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 eee56c4cd85a06e4729595d65f8665536257645d3e337bcdb08d679391704983
MD5 23ae68f55f5b78b0ebd569835d25dbed
BLAKE2b-256 424bc036c020b0a3a2e7fa7a12f88a7b6fecc9db5862d7f2523697988c522531

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

2.2.0b0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page