1- Graphene- Django Tutorial using Relay
2- ====================================
1+ Graphene and Django Tutorial using Relay
2+ ========================================
33
44Graphene has a number of additional features that are designed to make
55working with Django *really simple *.
66
77Note: The code in this quickstart is pulled from the `cookbook example
88app <https://github.com/graphql-python/graphene-django/tree/master/examples/cookbook> `__.
99
10+ A good idea is to check the following things first:
11+
12+ * `Graphene Relay documentation <http://docs.graphene-python.org/en/latest/relay/ >`__
13+ * `GraphQL Relay Specification <https://facebook.github.io/relay/docs/graphql-relay-specification.html >`__
14+
1015Setup the Django project
1116------------------------
1217
@@ -43,7 +48,7 @@ Now sync your database for the first time:
4348 Let's create a few simple models...
4449
4550Defining our models
46- -------------------
51+ ^^^^^^^^^^^^^^^^^^^
4752
4853Let's get started with these models:
4954
@@ -68,6 +73,33 @@ Let's get started with these models:
6873 def __str__ (self ):
6974 return self .name
7075
76+ Don't forget to create & run migrations:
77+
78+ .. code :: bash
79+
80+ python manage.py makemigrations
81+ python manage.py migrate
82+
83+ Load some test data
84+ ^^^^^^^^^^^^^^^^^^^
85+
86+ Now is a good time to load up some test data. The easiest option will be
87+ to `download the
88+ ingredients.json <https://raw.githubusercontent.com/graphql-python/graphene-django/master/examples/cookbook/cookbook/ingredients/fixtures/ingredients.json> `__
89+ fixture and place it in
90+ ``cookbook/ingredients/fixtures/ingredients.json ``. You can then run the
91+ following:
92+
93+ .. code :: bash
94+
95+ $ python ./manage.py loaddata ingredients
96+
97+ Installed 6 object(s) from 1 fixture(s)
98+
99+ Alternatively you can use the Django admin interface to create some data
100+ yourself. You'll need to run the development server (see below), and
101+ create a login for yourself too (``./manage.py createsuperuser ``).
102+
71103Schema
72104------
73105
@@ -158,8 +190,11 @@ Create the parent project-level ``cookbook/schema.py``:
158190 You can think of this as being something like your top-level ``urls.py ``
159191file (although it currently lacks any namespacing).
160192
193+ Testing everything so far
194+ -------------------------
195+
161196Update settings
162- ---------------
197+ ^^^^^^^^^^^^^^^
163198
164199Next, install your app and GraphiQL in your Django project. GraphiQL is
165200a web-based integrated development environment to assist in the writing
@@ -191,7 +226,7 @@ Alternatively, we can specify the schema to be used in the urls definition,
191226as explained below.
192227
193228Creating GraphQL and GraphiQL views
194- -----------------------------------
229+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
195230
196231Unlike a RESTful API, there is only a single URL from which GraphQL is
197232accessed. Requests to this URL are handled by Graphene's ``GraphQLView ``
@@ -230,39 +265,9 @@ as explained above, we can do so here using:
230265 url(r ' ^ graphql' , GraphQLView.as_view(graphiql = True , schema = schema)),
231266 ]
232267
233- Apply model changes to database
234- -------------------------------
235-
236- Tell Django that we've added models and update the database schema to
237- reflect these additions.
238-
239- .. code :: bash
240-
241- python manage.py makemigrations
242- python manage.py migrate
243-
244- Load some test data
245- -------------------
246-
247- Now is a good time to load up some test data. The easiest option will be
248- to `download the
249- ingredients.json <https://raw.githubusercontent.com/graphql-python/graphene-django/master/examples/cookbook/cookbook/ingredients/fixtures/ingredients.json> `__
250- fixture and place it in
251- ``cookbook/ingredients/fixtures/ingredients.json ``. You can then run the
252- following:
253-
254- .. code :: bash
255-
256- $ python ./manage.py loaddata ingredients
257-
258- Installed 6 object(s) from 1 fixture(s)
259-
260- Alternatively you can use the Django admin interface to create some data
261- yourself. You'll need to run the development server (see below), and
262- create a login for yourself too (``./manage.py createsuperuser ``).
263268
264269 Testing our GraphQL schema
265- --------------------------
270+ ^^^^^^^^^^^^^^^^^^^^^^^^^^
266271
267272We're now ready to test the API we've built. Let's fire up the server
268273from the command line.
0 commit comments