• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

examples/H31-Dec-2020-22

graphene_django/H31-Dec-2020-10,3257,921

graphene_django.egg-info/H03-May-2022-151110

LICENSEH A D31-Dec-20201.1 KiB2217

MANIFEST.inH A D31-Dec-2020267 65

PKG-INFOH A D31-Dec-20204.9 KiB151110

README.mdH A D31-Dec-20203.1 KiB12586

README.rstH A D31-Dec-20202.9 KiB12383

setup.cfgH A D31-Dec-2020469 3932

setup.pyH A D03-May-20222.3 KiB8273

README.md

1# ![Graphene Logo](http://graphene-python.org/favicon.png) Graphene-Django
2
3
4A [Django](https://www.djangoproject.com/) integration for [Graphene](http://graphene-python.org/).
5
6[![build][build-image]][build-url]
7[![pypi][pypi-image]][pypi-url]
8[![Anaconda-Server Badge][conda-image]][conda-url]
9[![coveralls][coveralls-image]][coveralls-url]
10
11[build-image]: https://github.com/graphql-python/graphene-django/workflows/Tests/badge.svg
12[build-url]: https://github.com/graphql-python/graphene-django/actions
13[pypi-image]: https://img.shields.io/pypi/v/graphene-django.svg?style=flat
14[pypi-url]: https://pypi.org/project/graphene-django/
15[coveralls-image]: https://coveralls.io/repos/github/graphql-python/graphene-django/badge.svg?branch=master
16[coveralls-url]: https://coveralls.io/github/graphql-python/graphene-django?branch=master
17[conda-image]: https://img.shields.io/conda/vn/conda-forge/graphene-django.svg
18[conda-url]: https://anaconda.org/conda-forge/graphene-django
19
20[�� Join the community on Slack](https://join.slack.com/t/graphenetools/shared_invite/enQtOTE2MDQ1NTg4MDM1LTA4Nzk0MGU0NGEwNzUxZGNjNDQ4ZjAwNDJjMjY0OGE1ZDgxZTg4YjM2ZTc4MjE2ZTAzZjE2ZThhZTQzZTkyMmM)
21
22## Documentation
23
24[Visit the documentation to get started!](https://docs.graphene-python.org/projects/django/en/latest/)
25
26## Quickstart
27
28For installing graphene, just run this command in your shell
29
30```bash
31pip install "graphene-django>=2.0"
32```
33
34### Settings
35
36```python
37INSTALLED_APPS = (
38    # ...
39    'django.contrib.staticfiles', # Required for GraphiQL
40    'graphene_django',
41)
42
43GRAPHENE = {
44    'SCHEMA': 'app.schema.schema' # Where your Graphene schema lives
45}
46```
47
48### Urls
49
50We need to set up a `GraphQL` endpoint in our Django app, so we can serve the queries.
51
52```python
53from django.urls import path
54from graphene_django.views import GraphQLView
55
56urlpatterns = [
57    # ...
58    path('graphql', GraphQLView.as_view(graphiql=True)),
59]
60```
61
62## Examples
63
64Here is a simple Django model:
65
66```python
67from django.db import models
68
69class UserModel(models.Model):
70    name = models.CharField(max_length=100)
71    last_name = models.CharField(max_length=100)
72```
73
74To create a GraphQL schema for it you simply have to write the following:
75
76```python
77from graphene_django import DjangoObjectType
78import graphene
79
80class User(DjangoObjectType):
81    class Meta:
82        model = UserModel
83
84class Query(graphene.ObjectType):
85    users = graphene.List(User)
86
87    def resolve_users(self, info):
88        return UserModel.objects.all()
89
90schema = graphene.Schema(query=Query)
91```
92
93Then you can query the schema:
94
95```python
96query = '''
97    query {
98      users {
99        name,
100        lastName
101      }
102    }
103'''
104result = schema.execute(query)
105```
106
107To learn more check out the following [examples](examples/):
108
109* **Schema with Filtering**: [Cookbook example](examples/cookbook)
110* **Relay Schema**: [Starwars Relay example](examples/starwars)
111
112
113## GraphQL testing clients
114 - [Firecamp](https://firecamp.io/graphql)
115 - [GraphiQL](https://github.com/graphql/graphiql)
116
117
118## Contributing
119
120See [CONTRIBUTING.md](CONTRIBUTING.md)
121
122## Release Notes
123
124* See [Releases page on github](https://github.com/graphql-python/graphene-django/releases)
125

README.rst

1Please read
2`UPGRADE-v2.0.md <https://github.com/graphql-python/graphene/blob/master/UPGRADE-v2.0.md>`__
3to learn how to upgrade to Graphene ``2.0``.
4
5--------------
6
7|Graphene Logo| Graphene-Django |Build Status| |PyPI version| |Coverage Status|
8===============================================================================
9
10A `Django <https://www.djangoproject.com/>`__ integration for
11`Graphene <http://graphene-python.org/>`__.
12
13
14Documentation
15-------------
16
17`Visit the documentation to get started! <https://docs.graphene-python.org/projects/django/en/latest/>`__
18
19Quickstart
20----------
21
22For installing graphene, just run this command in your shell
23
24.. code:: bash
25
26    pip install "graphene-django>=2.0"
27
28Settings
29~~~~~~~~
30
31.. code:: python
32
33    INSTALLED_APPS = (
34        # ...
35        'graphene_django',
36    )
37
38    GRAPHENE = {
39        'SCHEMA': 'app.schema.schema' # Where your Graphene schema lives
40    }
41
42Urls
43~~~~
44
45We need to set up a ``GraphQL`` endpoint in our Django app, so we can
46serve the queries.
47
48.. code:: python
49
50    from django.conf.urls import url
51    from graphene_django.views import GraphQLView
52
53    urlpatterns = [
54        # ...
55        url(r'^graphql$', GraphQLView.as_view(graphiql=True)),
56    ]
57
58Examples
59--------
60
61Here is a simple Django model:
62
63.. code:: python
64
65    from django.db import models
66
67    class UserModel(models.Model):
68        name = models.CharField(max_length=100)
69        last_name = models.CharField(max_length=100)
70
71To create a GraphQL schema for it you simply have to write the
72following:
73
74.. code:: python
75
76    from graphene_django import DjangoObjectType
77    import graphene
78
79    class User(DjangoObjectType):
80        class Meta:
81            model = UserModel
82
83    class Query(graphene.ObjectType):
84        users = graphene.List(User)
85
86        @graphene.resolve_only_args
87        def resolve_users(self):
88            return UserModel.objects.all()
89
90    schema = graphene.Schema(query=Query)
91
92Then you can simply query the schema:
93
94.. code:: python
95
96    query = '''
97        query {
98          users {
99            name,
100            lastName
101          }
102        }
103    '''
104    result = schema.execute(query)
105
106To learn more check out the following `examples <examples/>`__:
107
108-  **Schema with Filtering**: `Cookbook example <examples/cookbook>`__
109-  **Relay Schema**: `Starwars Relay example <examples/starwars>`__
110
111Contributing
112------------
113
114See `CONTRIBUTING.md <CONTRIBUTING.md>`__.
115
116.. |Graphene Logo| image:: http://graphene-python.org/favicon.png
117.. |Build Status| image:: https://github.com/graphql-python/graphene-django/workflows/Tests/badge.svg
118   :target: https://github.com/graphql-python/graphene-django/actions
119.. |PyPI version| image:: https://badge.fury.io/py/graphene-django.svg
120   :target: https://badge.fury.io/py/graphene-django
121.. |Coverage Status| image:: https://coveralls.io/repos/graphql-python/graphene-django/badge.svg?branch=master&service=github
122   :target: https://coveralls.io/github/graphql-python/graphene-django?branch=master
123