1INSTALLED_APPS = (
2 # ...
3 'graphene_django',
4)
5
6GRAPHENE = {
7 'SCHEMA': 'app.schema.schema' # Where your Graphene schema lives
8}
9
1#example
2from graphene_django import DjangoObjectType
3import graphene
4
5class User(DjangoObjectType):
6 class Meta:
7 model = UserModel
8
9class Query(graphene.ObjectType):
10 users = graphene.List(User)
11
12 @graphene.resolve_only_args
13 def resolve_users(self):
14 return UserModel.objects.all()
15
16schema = graphene.Schema(query=Query)
17
1from django.conf.urls import url
2from graphene_django.views import GraphQLView
3
4urlpatterns = [
5 # ...
6 url(r'^graphql$', GraphQLView.as_view(graphiql=True)),
7]
8
1# examples
2from django.db import models
3
4class UserModel(models.Model):
5 name = models.CharField(max_length=100)
6 last_name = models.CharField(max_length=100)
7