|
| 1 | +You are in the ``next`` unreleased version of Graphene-Django |
| 2 | +(``1.0.dev``). Please read |
| 3 | +`UPGRADE-v1.0.md <https://github.com/graphql-python/graphene/blob/master/UPGRADE-v1.0.md>`__ |
| 4 | +to learn how to upgrade. |
| 5 | + |
| 6 | +-------------- |
| 7 | + |
| 8 | +|Graphene Logo| Graphene-Django |Build Status| |PyPI version| |Coverage Status| |
| 9 | +=============================================================================== |
| 10 | + |
| 11 | +A `Django <https://www.djangoproject.com/>`__ integration for |
| 12 | +`Graphene <http://graphene-python.org/>`__. |
| 13 | + |
| 14 | +Installation |
| 15 | +------------ |
| 16 | + |
| 17 | +For instaling graphene, just run this command in your shell |
| 18 | + |
| 19 | +.. code:: bash |
| 20 | +
|
| 21 | + pip install "graphene-django>=1.0.dev" |
| 22 | +
|
| 23 | +Examples |
| 24 | +-------- |
| 25 | + |
| 26 | +Here is a simple Django model: |
| 27 | + |
| 28 | +.. code:: python |
| 29 | +
|
| 30 | + from django.db import models |
| 31 | +
|
| 32 | + class UserModel(models.Model): |
| 33 | + name = models.CharField(max_length=100) |
| 34 | + last_name = models.CharField(max_length=100) |
| 35 | +
|
| 36 | +To create a GraphQL schema for it you simply have to write the |
| 37 | +following: |
| 38 | + |
| 39 | +.. code:: python |
| 40 | +
|
| 41 | + from graphene_django import DjangoObjectType |
| 42 | +
|
| 43 | + class User(DjangoObjectType): |
| 44 | + class Meta: |
| 45 | + model = UserModel |
| 46 | +
|
| 47 | + class Query(graphene.ObjectType): |
| 48 | + users = graphene.List(User) |
| 49 | +
|
| 50 | + @graphene.resolve_only_args |
| 51 | + def resolve_users(self): |
| 52 | + return UserModel.objects.all() |
| 53 | +
|
| 54 | + schema = graphene.Schema(query=QueryRoot) |
| 55 | +
|
| 56 | +Then you can simply query the schema: |
| 57 | + |
| 58 | +.. code:: python |
| 59 | +
|
| 60 | + query = ''' |
| 61 | + query { |
| 62 | + users { |
| 63 | + name, |
| 64 | + lastName |
| 65 | + } |
| 66 | + } |
| 67 | + ''' |
| 68 | + result = schema.execute(query) |
| 69 | +
|
| 70 | +To learn more check out the following `examples <examples/>`__: |
| 71 | + |
| 72 | +- **Schema with Filtering**: `Cookbook example <examples/cookbook>`__ |
| 73 | +- **Relay Schema**: `Starwars Relay example <examples/starwars>`__ |
| 74 | + |
| 75 | +Contributing |
| 76 | +------------ |
| 77 | + |
| 78 | +After cloning this repo, ensure dependencies are installed by running: |
| 79 | + |
| 80 | +.. code:: sh |
| 81 | +
|
| 82 | + python setup.py install |
| 83 | +
|
| 84 | +After developing, the full test suite can be evaluated by running: |
| 85 | + |
| 86 | +.. code:: sh |
| 87 | +
|
| 88 | + python setup.py test # Use --pytest-args="-v -s" for verbose mode |
| 89 | +
|
| 90 | +.. |Graphene Logo| image:: http://graphene-python.org/favicon.png |
| 91 | +.. |Build Status| image:: https://travis-ci.org/graphql-python/graphene-django.svg?branch=master |
| 92 | + :target: https://travis-ci.org/graphql-python/graphene-django |
| 93 | +.. |PyPI version| image:: https://badge.fury.io/py/graphene-django.svg |
| 94 | + :target: https://badge.fury.io/py/graphene-django |
| 95 | +.. |Coverage Status| image:: https://coveralls.io/repos/graphql-python/graphene-django/badge.svg?branch=master&service=github |
| 96 | + :target: https://coveralls.io/github/graphql-python/graphene-django?branch=master |
0 commit comments