2015-10-30 09:48:13 +03:00
|
|
|
|Graphene Logo| `Graphene <http://graphene-python.org>`__ |Build Status| |PyPI version| |Coverage Status|
|
|
|
|
=========================================================================================================
|
2015-10-07 07:04:24 +03:00
|
|
|
|
2015-10-30 09:48:13 +03:00
|
|
|
Graphene is a Python library for building GraphQL schemas/types fast and
|
2015-10-30 23:40:36 +03:00
|
|
|
easily.
|
|
|
|
|
|
|
|
- **Easy to use:** Graphene helps you use GraphQL in Python without
|
|
|
|
effort.
|
|
|
|
- **Relay:** Graphene has builtin support for Relay
|
|
|
|
- **Django:** Automatic *Django model* mapping to Graphene Types. Check
|
|
|
|
a fully working
|
|
|
|
`Django <http://github.com/graphql-python/swapi-graphene>`__
|
|
|
|
implementation
|
2015-10-07 07:04:24 +03:00
|
|
|
|
2015-10-30 10:01:44 +03:00
|
|
|
*But, what is supported in this Python version?* **Everything**:
|
|
|
|
Interfaces, ObjectTypes, Mutations and Relay (Nodes, Connections and
|
|
|
|
Mutations).
|
|
|
|
|
2015-10-07 07:04:24 +03:00
|
|
|
Installation
|
|
|
|
------------
|
|
|
|
|
|
|
|
For instaling graphene, just run this command in your shell
|
|
|
|
|
|
|
|
.. code:: bash
|
|
|
|
|
|
|
|
pip install graphene
|
2015-10-30 09:48:13 +03:00
|
|
|
# Or in case of need Django model support
|
|
|
|
pip install graphene[django]
|
2015-10-07 07:04:24 +03:00
|
|
|
|
2015-10-30 09:48:13 +03:00
|
|
|
Examples
|
|
|
|
--------
|
2015-10-07 07:04:24 +03:00
|
|
|
|
2015-10-30 09:48:13 +03:00
|
|
|
Here is one example for get you started:
|
2015-10-07 07:04:24 +03:00
|
|
|
|
|
|
|
.. code:: python
|
|
|
|
|
2015-10-30 09:48:13 +03:00
|
|
|
class Query(graphene.ObjectType):
|
|
|
|
hello = graphene.StringField(description='A typical hello world')
|
|
|
|
ping = graphene.StringField(description='Ping someone',
|
|
|
|
to=graphene.Argument(graphene.String))
|
2015-10-07 07:04:24 +03:00
|
|
|
|
2015-10-30 09:48:13 +03:00
|
|
|
def resolve_hello(self, args, info):
|
|
|
|
return 'World'
|
2015-10-07 07:04:24 +03:00
|
|
|
|
2015-10-30 09:48:13 +03:00
|
|
|
def resolve_ping(self, args, info):
|
|
|
|
return 'Pinging {}'.format(args.get('to'))
|
2015-10-07 07:04:24 +03:00
|
|
|
|
|
|
|
schema = graphene.Schema(query=Query)
|
|
|
|
|
2015-10-30 09:48:13 +03:00
|
|
|
Then Querying ``graphene.Schema`` is as simple as:
|
2015-10-07 07:04:24 +03:00
|
|
|
|
|
|
|
.. code:: python
|
|
|
|
|
|
|
|
query = '''
|
2015-10-30 09:48:13 +03:00
|
|
|
query SayHello {
|
|
|
|
hello
|
2015-10-30 23:40:36 +03:00
|
|
|
ping(to:"peter")
|
2015-10-07 07:04:24 +03:00
|
|
|
}
|
|
|
|
'''
|
|
|
|
result = schema.execute(query)
|
|
|
|
|
2015-10-30 09:48:13 +03:00
|
|
|
If you want to learn even more, you can also check the following
|
2015-10-30 10:01:44 +03:00
|
|
|
`examples <examples/>`__:
|
2015-10-07 07:04:24 +03:00
|
|
|
|
2015-10-30 10:01:44 +03:00
|
|
|
- **Basic Schema**: `Starwars example <examples/starwars>`__
|
|
|
|
- **Relay Schema**: `Starwars Relay
|
|
|
|
example <examples/starwars_relay>`__
|
|
|
|
- **Django model mapping**: `Starwars Django
|
|
|
|
example <examples/starwars_django>`__
|
2015-10-07 07:04:24 +03:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2015-10-30 09:48:13 +03:00
|
|
|
.. |Graphene Logo| image:: http://graphene-python.org/favicon.png
|
2015-10-07 07:04:24 +03:00
|
|
|
.. |Build Status| image:: https://travis-ci.org/graphql-python/graphene.svg?branch=master
|
|
|
|
:target: https://travis-ci.org/graphql-python/graphene
|
2015-10-30 09:48:13 +03:00
|
|
|
.. |PyPI version| image:: https://badge.fury.io/py/graphene.svg
|
|
|
|
:target: https://badge.fury.io/py/graphene
|
2015-10-07 07:04:24 +03:00
|
|
|
.. |Coverage Status| image:: https://coveralls.io/repos/graphql-python/graphene/badge.svg?branch=master&service=github
|
|
|
|
:target: https://coveralls.io/github/graphql-python/graphene?branch=master
|