Update tutorial-relay.rst structure to match plain

This commit is contained in:
Radoslav Georgiev 2017-02-21 21:32:45 +02:00
parent 0b4db6a42d
commit f15d2f6762

View File

@ -1,5 +1,5 @@
Graphene-Django Tutorial using Relay Graphene and Django Tutorial using Relay
==================================== ========================================
Graphene has a number of additional features that are designed to make Graphene has a number of additional features that are designed to make
working with Django *really simple*. working with Django *really simple*.
@ -7,6 +7,11 @@ working with Django *really simple*.
Note: The code in this quickstart is pulled from the `cookbook example Note: The code in this quickstart is pulled from the `cookbook example
app <https://github.com/graphql-python/graphene-django/tree/master/examples/cookbook>`__. app <https://github.com/graphql-python/graphene-django/tree/master/examples/cookbook>`__.
A good idea is to check the following things first:
* `Graphene Relay documentation <http://docs.graphene-python.org/en/latest/relay/>`__
* `GraphQL Relay Specification <https://facebook.github.io/relay/docs/graphql-relay-specification.html>`__
Setup the Django project Setup the Django project
------------------------ ------------------------
@ -43,7 +48,7 @@ Now sync your database for the first time:
Let's create a few simple models... Let's create a few simple models...
Defining our models Defining our models
------------------- ^^^^^^^^^^^^^^^^^^^
Let's get started with these models: Let's get started with these models:
@ -68,6 +73,33 @@ Let's get started with these models:
def __str__(self): def __str__(self):
return self.name return self.name
Don't forget to create & run migrations:
.. code:: bash
python manage.py makemigrations
python manage.py migrate
Load some test data
^^^^^^^^^^^^^^^^^^^
Now is a good time to load up some test data. The easiest option will be
to `download the
ingredients.json <https://raw.githubusercontent.com/graphql-python/graphene-django/master/examples/cookbook/cookbook/ingredients/fixtures/ingredients.json>`__
fixture and place it in
``cookbook/ingredients/fixtures/ingredients.json``. You can then run the
following:
.. code:: bash
$ python ./manage.py loaddata ingredients
Installed 6 object(s) from 1 fixture(s)
Alternatively you can use the Django admin interface to create some data
yourself. You'll need to run the development server (see below), and
create a login for yourself too (``./manage.py createsuperuser``).
Schema Schema
------ ------
@ -158,8 +190,11 @@ Create the parent project-level ``cookbook/schema.py``:
You can think of this as being something like your top-level ``urls.py`` You can think of this as being something like your top-level ``urls.py``
file (although it currently lacks any namespacing). file (although it currently lacks any namespacing).
Testing everything so far
-------------------------
Update settings Update settings
--------------- ^^^^^^^^^^^^^^^
Next, install your app and GraphiQL in your Django project. GraphiQL is Next, install your app and GraphiQL in your Django project. GraphiQL is
a web-based integrated development environment to assist in the writing a 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,
as explained below. as explained below.
Creating GraphQL and GraphiQL views Creating GraphQL and GraphiQL views
----------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Unlike a RESTful API, there is only a single URL from which GraphQL is Unlike a RESTful API, there is only a single URL from which GraphQL is
accessed. Requests to this URL are handled by Graphene's ``GraphQLView`` accessed. Requests to this URL are handled by Graphene's ``GraphQLView``
@ -230,39 +265,9 @@ as explained above, we can do so here using:
url(r'^graphql', GraphQLView.as_view(graphiql=True, schema=schema)), url(r'^graphql', GraphQLView.as_view(graphiql=True, schema=schema)),
] ]
Apply model changes to database
-------------------------------
Tell Django that we've added models and update the database schema to
reflect these additions.
.. code:: bash
python manage.py makemigrations
python manage.py migrate
Load some test data
-------------------
Now is a good time to load up some test data. The easiest option will be
to `download the
ingredients.json <https://raw.githubusercontent.com/graphql-python/graphene-django/master/examples/cookbook/cookbook/ingredients/fixtures/ingredients.json>`__
fixture and place it in
``cookbook/ingredients/fixtures/ingredients.json``. You can then run the
following:
.. code:: bash
$ python ./manage.py loaddata ingredients
Installed 6 object(s) from 1 fixture(s)
Alternatively you can use the Django admin interface to create some data
yourself. You'll need to run the development server (see below), and
create a login for yourself too (``./manage.py createsuperuser``).
Testing our GraphQL schema Testing our GraphQL schema
-------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^
We're now ready to test the API we've built. Let's fire up the server We're now ready to test the API we've built. Let's fire up the server
from the command line. from the command line.