@@ -11,11 +11,16 @@ working with Django simple.
11
11
If you need help getting started with django then head over to
12
12
Django's getting started page.
13
13
14
- First let's create a few simple models
14
+ First let's create a few simple models...
15
15
16
- ## Some models
16
+ ## Defining our models
17
17
18
- Let's get started with these models ** in an app called ingredients** :
18
+ Before continuing, create the following:
19
+
20
+ * A Django project called ` cookbook `
21
+ * An app within ` cookbook ` called ` ingredients `
22
+
23
+ Let's get started with these models:
19
24
20
25
``` python
21
26
# cookbook/ingredients/models.py
@@ -34,24 +39,25 @@ class Ingredient(models.Model):
34
39
## Schema
35
40
36
41
GraphQL presents your objects to the world as a graph structure rather than a more
37
- heiricarcal structure to which you may be acustomed . In order to create this
42
+ hierarchical structure to which you may be accustomed . In order to create this
38
43
representation, Graphene needs to know about each * type* of object which will appear in
39
44
the graph. Below we define these as the ` UserType ` and ` GroupType ` classes.
40
45
41
46
This graph also has a 'root' through which all access begins. This is the ` Query ` class below.
42
47
In this example, we provide the ability to list all users via ` all_users ` , and the
43
- ability to obtain a single user via ` get_user ` .
48
+ ability to obtain a specific user via ` get_user ` .
44
49
45
- Open ` tutorial/quickstart /schema.py` and type the following:
50
+ Create ` cookbook/ingredients /schema.py` and type the following:
46
51
47
52
``` python
53
+ # cookbook/ingredients/schema.py
48
54
import graphene
49
55
from graphene.contrib.django import DjangoObjectType
50
56
51
57
from django.contrib.auth.models import User, Group
52
58
53
59
# Graphene will automatically map the User model's fields onto the UserType.
54
- # This is configured in the UserType's Meta class
60
+ # This is configured in the UserType's Meta class (as you can see below)
55
61
class UserType (DjangoObjectType ):
56
62
class Meta :
57
63
model = User
0 commit comments