Merge branch 'refs/heads/feature/django'

This commit is contained in:
Syrus Akbary 2016-01-13 19:40:38 -08:00
commit 3bb0e6c005
4 changed files with 80 additions and 30 deletions

View File

@ -5,7 +5,6 @@ ga = "UA-12613282-7"
name = "Quickstart" name = "Quickstart"
pages = [ pages = [
"/docs/quickstart/", "/docs/quickstart/",
"/docs/quickstart-django/",
] ]
[docs.walkthrough] [docs.walkthrough]
@ -16,5 +15,11 @@ ga = "UA-12613282-7"
"/docs/mutations/", "/docs/mutations/",
"/docs/basic-types/", "/docs/basic-types/",
"/docs/relay/", "/docs/relay/",
"/docs/filtering/", ]
[docs.django]
name = "Django"
pages = [
"/docs/django/tutorial/",
"/docs/django/filtering/",
] ]

View File

@ -17,15 +17,17 @@
"copy-webpack-plugin": "^0.2.0", "copy-webpack-plugin": "^0.2.0",
"es6-promise": "^3.0.2", "es6-promise": "^3.0.2",
"extract-text-webpack-plugin": "^0.9.1", "extract-text-webpack-plugin": "^0.9.1",
"gatsby": "^0.7.3", "gatsby": "^0.7.7",
"graphiql": "^0.4.2", "graphiql": "^0.4.2",
"graphql": "^0.4.13", "graphql": "^0.4.13",
"jeet": "^6.1.2", "jeet": "^6.1.2",
"lodash": "^3.10.1", "lodash": "^3.10.1",
"nib": "^1.1.0", "nib": "^1.1.0",
"react": "^0.14.3", "react": "^0.14.6",
"react-burger-menu": "^1.4.2", "radium": "0.14.2",
"react-burger-menu": "^1.4.12",
"react-document-title": "^2.0.1", "react-document-title": "^2.0.1",
"react-dom": "^0.14.6",
"react-router": "^0.13.5", "react-router": "^0.13.5",
"rupture": "^0.6.1", "rupture": "^0.6.1",
"stylus-loader": "^1.4.2", "stylus-loader": "^1.4.2",

View File

@ -1,9 +1,9 @@
--- ---
title: Filtering (Django) title: Filtering
description: Details of how to perform filtering description: Details of how to perform filtering in Graphene Django
--- ---
# Filtering (Django) # Filtering
Graphene integrates with [django-filter](https://django-filter.readthedocs.org) Graphene integrates with [django-filter](https://django-filter.readthedocs.org)
to provide filtering of results. See the to provide filtering of results. See the
@ -21,7 +21,7 @@ pip install django-filter
``` ```
**Note: The techniques below are demoed in the **Note: The techniques below are demoed in the
[cookbook example app](https://github.com/graphql-python/graphene/tree/feature/django/examples/cookbook).** [cookbook example app](https://github.com/graphql-python/graphene/tree/master/examples/cookbook_django).**
## Filterable fields ## Filterable fields
@ -54,7 +54,10 @@ query {
node { node {
id, id,
name name
}}}} }
}
}
}
``` ```
You can also make more complex lookup types available: You can also make more complex lookup types available:
@ -76,12 +79,15 @@ Which you could query as follows:
```graphql ```graphql
query { query {
# Note that fields names become camelcased # Note that fields names become camelcased
allAnimals(nameIcontains: "lion") { allAnimals(name_Icontains: "lion") {
edges { edges {
node { node {
id, id,
name name
}}}} }
}
}
}
``` ```
## Orderable fields ## Orderable fields
@ -112,7 +118,10 @@ query {
node { node {
id, id,
name name
}}}} }
}
}
}
``` ```
## Custom Filtersets ## Custom Filtersets

View File

@ -1,28 +1,54 @@
--- ---
title: Django Quickstart title: Quickstart
description: A Quick guide to Graphene in Django description: A Quick guide to Graphene in Django
--- ---
# Django Tutorial # Django Tutorial
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 simple. working with Django *really simple*.
If you need help getting started with django then head over to
Django's getting started page.
First let's create a few simple models...
**Note: The code in this quickstart is pulled from the **Note: The code in this quickstart is pulled from the
[cookbook example app](https://github.com/graphql-python/graphene/tree/feature/django/examples/cookbook)**. [cookbook example app](https://github.com/graphql-python/graphene/tree/master/examples/cookbook_django)**.
## Defining our models
Before continuing, create the following: ## Setup the Django project
We will setup the project, create the following:
* A Django project called `cookbook` * A Django project called `cookbook`
* An app within `cookbook` called `ingredients` * An app within `cookbook` called `ingredients`
```bash
# Create the project directory
mkdir cookbook
cd cookbook
# Create a virtualenv to isolate our package dependencies locally
virtualenv env
source env/bin/activate # On Windows use `env\Scripts\activate`
# Install Django and Graphene with Django support
pip install django
pip install graphene[django]
pip install django-graphiql
# Set up a new project with a single application
django-admin.py startproject cookbook . # Note the trailing '.' character
django-admin.py startapp ingredients
```
Now sync your database for the first time:
```bash
python manage.py migrate
```
Let's create a few simple models...
## Defining our models
Let's get started with these models: Let's get started with these models:
```python ```python
@ -51,9 +77,9 @@ class Ingredient(models.Model):
GraphQL presents your objects to the world as a graph structure rather than a more GraphQL presents your objects to the world as a graph structure rather than a more
hierarchical structure to which you may be accustomed. In order to create this hierarchical structure to which you may be accustomed. In order to create this
representation, Graphene needs to know about each *type* of object which will appear in representation, Graphene needs to know about each *type* of object which will appear in
the graph. Below we define these as the `UserType` and `GroupType` classes. the graph.
This graph also has a 'root' through which all access begins. This is the `Query` class below. This graph also has a *root type* through which all access begins. This is the `Query` class below.
In this example, we provide the ability to list all users via `all_users`, and the In this example, we provide the ability to list all users via `all_users`, and the
ability to obtain a specific user via `get_user`. ability to obtain a specific user via `get_user`.
@ -186,7 +212,7 @@ Installed 6 object(s) from 1 fixture(s)
``` ```
Alternatively you can use the Django admin interface to create some data youself. Alternatively you can use the Django admin interface to create some data youself.
You'll need to run the development server (see below), and probably create a login You'll need to run the development server (see below), and create a login
for yourself too (`./manage.py createsuperuser`). for yourself too (`./manage.py createsuperuser`).
## Testing our GraphQL schema ## Testing our GraphQL schema
@ -238,12 +264,17 @@ query {
edges { edges {
node { node {
name, name,
ingredients { ingredients {
edges { edges {
node { node {
name name
}}}}}}} }
}
}
}
}
}
}
``` ```
Or you can get only 'meat' ingredients containing the letter 'e': Or you can get only 'meat' ingredients containing the letter 'e':
@ -251,9 +282,12 @@ Or you can get only 'meat' ingredients containing the letter 'e':
```graphql ```graphql
query { query {
# You can also use `category: "CATEGORY GLOBAL ID"` # You can also use `category: "CATEGORY GLOBAL ID"`
allIngredients(nameIcontains: "e", categoryName: "Meat") { allIngredients(name_Icontains: "e", categoryName: "Meat") {
edges { edges {
node { node {
name name
}}}} }
}
}
}
``` ```