2016-09-18 02:29:00 +03:00
|
|
|
Cookbook Example Django Project
|
|
|
|
===============================
|
|
|
|
|
|
|
|
This example project demos integration between Graphene and Django.
|
|
|
|
The project contains two apps, one named `ingredients` and another
|
2017-02-23 20:08:05 +03:00
|
|
|
named `recipes`.
|
2016-09-18 02:29:00 +03:00
|
|
|
|
|
|
|
Getting started
|
|
|
|
---------------
|
|
|
|
|
|
|
|
First you'll need to get the source of the project. Do this by cloning the
|
|
|
|
whole Graphene repository:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# Get the example project code
|
2016-10-17 09:49:27 +03:00
|
|
|
git clone https://github.com/graphql-python/graphene-django.git
|
|
|
|
cd graphene-django/examples/cookbook
|
2016-09-18 02:29:00 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
It is good idea (but not required) to create a virtual environment
|
|
|
|
for this project. We'll do this using
|
|
|
|
[virtualenv](http://docs.python-guide.org/en/latest/dev/virtualenvs/)
|
|
|
|
to keep things simple,
|
|
|
|
but you may also find something like
|
|
|
|
[virtualenvwrapper](https://virtualenvwrapper.readthedocs.org/en/latest/)
|
|
|
|
to be useful:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# Create a virtualenv in which we can install the dependencies
|
|
|
|
virtualenv env
|
|
|
|
source env/bin/activate
|
|
|
|
```
|
|
|
|
|
|
|
|
Now we can install our dependencies:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
pip install -r requirements.txt
|
|
|
|
```
|
|
|
|
|
|
|
|
Now setup our database:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# Setup the database
|
|
|
|
./manage.py migrate
|
|
|
|
|
|
|
|
# Load some example data
|
|
|
|
./manage.py loaddata ingredients
|
|
|
|
|
|
|
|
# Create an admin user (useful for logging into the admin UI
|
|
|
|
# at http://127.0.0.1:8000/admin)
|
|
|
|
./manage.py createsuperuser
|
|
|
|
```
|
|
|
|
|
|
|
|
Now you should be ready to start the server:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
./manage.py runserver
|
|
|
|
```
|
|
|
|
|
|
|
|
Now head on over to
|
2016-10-05 23:21:01 +03:00
|
|
|
[http://127.0.0.1:8000/graphql](http://127.0.0.1:8000/graphql)
|
2016-09-18 02:29:00 +03:00
|
|
|
and run some queries!
|
2017-12-30 14:29:23 +03:00
|
|
|
(See the [Graphene-Django Tutorial](http://docs.graphene-python.org/projects/django/en/latest/tutorial-plain/#testing-our-graphql-schema)
|
2016-09-18 02:29:00 +03:00
|
|
|
for some example queries)
|