Skip to content

Commit 944d361

Browse files
committed
Improved docs
1 parent aed366a commit 944d361

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

docs/pages/docs/quickstart-django.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ pip install django-graphiql
2828

2929
# Set up a new project with a single application
3030
django-admin.py startproject tutorial . # Note the trailing '.' character
31-
cd tutorial
3231
django-admin.py startapp quickstart
3332
```
3433

@@ -50,14 +49,15 @@ Once you've set up a database and initial user created and ready to go, open up
5049

5150
## Schema
5251

53-
Right, we'd better write some types then. Open `tutorial/quickstart/schema.py` and get typing.
52+
Right, we'd better write some types then. Open `quickstart/schema.py` and get typing.
5453

5554
```python
5655
import graphene
5756
from graphene.contrib.django import DjangoObjectType
5857

5958
from django.contrib.auth.models import User, Group
6059

60+
6161
# Graphene will map automatically the User model to UserType with
6262
# the specified fields
6363
class UserType(DjangoObjectType):
@@ -68,25 +68,41 @@ class UserType(DjangoObjectType):
6868

6969
class GroupType(DjangoObjectType):
7070
class Meta:
71-
model = User
71+
model = Group
7272
only_fields = ('name', )
7373

7474

7575
class Query(graphene.ObjectType):
7676
all_users = graphene.List(UserType)
77-
get_user = graphene.Field(UserType
78-
id=graphene.String(required=True))
77+
get_user = graphene.Field(UserType,
78+
id=graphene.String().NonNull)
79+
get_group = graphene.Field(GroupType,
80+
id=graphene.String().NonNull)
7981

8082
def resolve_all_users(self, args, info):
8183
return User.objects.all()
8284

8385
def resolve_get_user(self, args, info):
8486
return User.objects.get(id=args.get('id'))
8587

88+
def resolve_get_group(self, args, info):
89+
return Group.objects.get(id=args.get('id'))
90+
8691
schema = graphene.Schema(query=Query)
8792
```
8893

8994

95+
## Adding GraphiQL
96+
97+
For having the GraphiQL static assets we need to append `django_graphiql` in `INSTALLED_APPS` in `tutorial/settings.py`:
98+
99+
```python
100+
INSTALLED_APPS = [
101+
# The other installed apps
102+
'django_graphiql',
103+
]
104+
```
105+
90106
## Creating GraphQL and GraphiQL views
91107

92108
Okay, now let's wire up the GraphQL and GraphiQL urls. On to `tutorial/urls.py`...
@@ -96,7 +112,7 @@ Okay, now let's wire up the GraphQL and GraphiQL urls. On to `tutorial/urls.py`.
96112
from django.conf.urls import url, include
97113
from django.views.decorators.csrf import csrf_exempt
98114
from graphene.contrib.django.views import GraphQLView
99-
from tutorial.quickstart.schema import schema
115+
from quickstart.schema import schema
100116

101117

102118
# Wire up our GraphQL schema in /graphql.

0 commit comments

Comments
 (0)