Please read
`UPGRADE-v2.0.md <https://github.com/graphql-python/graphene/blob/master/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 <http://www.sqlalchemy.org/>`__ integration for
`Graphene <http://graphene-python.org/>`__.
Installation
------------
For instaling graphene, just run this command in your shell
.. code:: bash
pip install "graphene-sqlalchemy>=2.0"
Examples
--------
Here is a simple SQLAlchemy model:
.. code:: python
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:
.. code:: python
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:
.. code:: python
query = '''
query {
users {
name,
lastName
}
}
'''
result = schema.execute(query, context_value={'session': db_session})
To learn more check out the following `examples <examples/>`__:
- **Full example**: `Flask SQLAlchemy
example <examples/flask_sqlalchemy>`__
Contributing
------------
After cloning this repo, ensure dependencies are installed by running:
.. code:: sh
python setup.py install
After developing, the full test suite can be evaluated by running:
.. code:: sh
python setup.py test # Use --pytest-args="-v -s" for verbose mode
.. |Graphene Logo| image:: http://graphene-python.org/favicon.png
.. |Build Status| image:: https://travis-ci.org/graphql-python/graphene-sqlalchemy.svg?branch=master
:target: https://travis-ci.org/graphql-python/graphene-sqlalchemy
.. |PyPI version| image:: https://badge.fury.io/py/graphene-sqlalchemy.svg
:target: https://badge.fury.io/py/graphene-sqlalchemy
.. |Coverage Status| image:: https://coveralls.io/repos/graphql-python/graphene-sqlalchemy/badge.svg?branch=master&service=github
:target: https://coveralls.io/github/graphql-python/graphene-sqlalchemy?branch=master
Raw data
{
"_id": null,
"home_page": "https://github.com/graphql-python/graphene-sqlalchemy",
"name": "graphene-sqlalchemy",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "api graphql protocol rest relay graphene",
"author": "Syrus Akbary",
"author_email": "me@syrusakbary.com",
"download_url": "https://files.pythonhosted.org/packages/68/a9/2ba20a7d9c6d34bc2bdc0b5dfdf4ff33be16fead8a0593cd3b0454bb96d1/graphene-sqlalchemy-2.3.0.tar.gz",
"platform": "",
"description": "Please read\n`UPGRADE-v2.0.md <https://github.com/graphql-python/graphene/blob/master/UPGRADE-v2.0.md>`__\nto learn how to upgrade to Graphene ``2.0``.\n\n--------------\n\n|Graphene Logo| Graphene-SQLAlchemy |Build Status| |PyPI version| |Coverage Status|\n===================================================================================\n\nA `SQLAlchemy <http://www.sqlalchemy.org/>`__ integration for\n`Graphene <http://graphene-python.org/>`__.\n\nInstallation\n------------\n\nFor instaling graphene, just run this command in your shell\n\n.. code:: bash\n\n pip install \"graphene-sqlalchemy>=2.0\"\n\nExamples\n--------\n\nHere is a simple SQLAlchemy model:\n\n.. code:: python\n\n from sqlalchemy import Column, Integer, String\n from sqlalchemy.orm import backref, relationship\n\n from sqlalchemy.ext.declarative import declarative_base\n\n Base = declarative_base()\n\n class UserModel(Base):\n __tablename__ = 'department'\n id = Column(Integer, primary_key=True)\n name = Column(String)\n last_name = Column(String)\n\nTo create a GraphQL schema for it you simply have to write the\nfollowing:\n\n.. code:: python\n\n from graphene_sqlalchemy import SQLAlchemyObjectType\n\n class User(SQLAlchemyObjectType):\n class Meta:\n model = UserModel\n\n class Query(graphene.ObjectType):\n users = graphene.List(User)\n\n def resolve_users(self, info):\n query = User.get_query(info) # SQLAlchemy query\n return query.all()\n\n schema = graphene.Schema(query=Query)\n\nThen you can simply query the schema:\n\n.. code:: python\n\n query = '''\n query {\n users {\n name,\n lastName\n }\n }\n '''\n result = schema.execute(query, context_value={'session': db_session})\n\nTo learn more check out the following `examples <examples/>`__:\n\n- **Full example**: `Flask SQLAlchemy\n example <examples/flask_sqlalchemy>`__\n\nContributing\n------------\n\nAfter cloning this repo, ensure dependencies are installed by running:\n\n.. code:: sh\n\n python setup.py install\n\nAfter developing, the full test suite can be evaluated by running:\n\n.. code:: sh\n\n python setup.py test # Use --pytest-args=\"-v -s\" for verbose mode\n\n.. |Graphene Logo| image:: http://graphene-python.org/favicon.png\n.. |Build Status| image:: https://travis-ci.org/graphql-python/graphene-sqlalchemy.svg?branch=master\n :target: https://travis-ci.org/graphql-python/graphene-sqlalchemy\n.. |PyPI version| image:: https://badge.fury.io/py/graphene-sqlalchemy.svg\n :target: https://badge.fury.io/py/graphene-sqlalchemy\n.. |Coverage Status| image:: https://coveralls.io/repos/graphql-python/graphene-sqlalchemy/badge.svg?branch=master&service=github\n :target: https://coveralls.io/github/graphql-python/graphene-sqlalchemy?branch=master\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Graphene SQLAlchemy integration",
"version": "2.3.0",
"project_urls": {
"Homepage": "https://github.com/graphql-python/graphene-sqlalchemy"
},
"split_keywords": [
"api",
"graphql",
"protocol",
"rest",
"relay",
"graphene"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d28d4ab1c77e46a0d1ad2bedbb4b9d514025def8cbbf1f738db4343224cda80e",
"md5": "4a5861fa89744ec3f94c987da6a72fdb",
"sha256": "97ed52bc0d01d757df50d25b5bdd490a2327778d41223d4e084d38a239925e8e"
},
"downloads": -1,
"filename": "graphene_sqlalchemy-2.3.0-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "4a5861fa89744ec3f94c987da6a72fdb",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 38774,
"upload_time": "2020-06-04T22:01:07",
"upload_time_iso_8601": "2020-06-04T22:01:07.256890Z",
"url": "https://files.pythonhosted.org/packages/d2/8d/4ab1c77e46a0d1ad2bedbb4b9d514025def8cbbf1f738db4343224cda80e/graphene_sqlalchemy-2.3.0-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "68a92ba20a7d9c6d34bc2bdc0b5dfdf4ff33be16fead8a0593cd3b0454bb96d1",
"md5": "249179c93894aed6c6c201aa1aae0395",
"sha256": "2b1a9cf4ed44aec78140605f38061a79b51be5902400d10c3d19b2cf64046215"
},
"downloads": -1,
"filename": "graphene-sqlalchemy-2.3.0.tar.gz",
"has_sig": false,
"md5_digest": "249179c93894aed6c6c201aa1aae0395",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 28369,
"upload_time": "2020-06-04T22:01:08",
"upload_time_iso_8601": "2020-06-04T22:01:08.444086Z",
"url": "https://files.pythonhosted.org/packages/68/a9/2ba20a7d9c6d34bc2bdc0b5dfdf4ff33be16fead8a0593cd3b0454bb96d1/graphene-sqlalchemy-2.3.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2020-06-04 22:01:08",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "graphql-python",
"github_project": "graphene-sqlalchemy",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"tox": true,
"lcname": "graphene-sqlalchemy"
}