2016-06-17 19:29:38 +03:00
|
|
|
from django.conf.urls import url
|
|
|
|
|
|
|
|
import graphene
|
|
|
|
from graphene import Schema
|
2016-06-20 00:30:33 +03:00
|
|
|
from ..types import DjangoNode, DjangoObjectType
|
2016-06-17 19:29:38 +03:00
|
|
|
from ..views import GraphQLView
|
|
|
|
|
|
|
|
from .models import Article, Reporter
|
|
|
|
|
|
|
|
|
2016-06-20 00:30:33 +03:00
|
|
|
class Character(DjangoNode, DjangoObjectType):
|
2016-06-17 19:29:38 +03:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Reporter
|
|
|
|
|
2016-06-19 00:33:04 +03:00
|
|
|
def get_node(self, id, context, info):
|
2016-06-17 19:29:38 +03:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
2016-06-20 00:30:33 +03:00
|
|
|
class Human(DjangoNode, DjangoObjectType):
|
2016-06-17 19:29:38 +03:00
|
|
|
raises = graphene.String()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Article
|
|
|
|
|
|
|
|
def resolve_raises(self, *args):
|
|
|
|
raise Exception("This field should raise exception")
|
|
|
|
|
|
|
|
def get_node(self, id):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class Query(graphene.ObjectType):
|
|
|
|
human = graphene.Field(Human)
|
|
|
|
|
2016-06-19 00:33:04 +03:00
|
|
|
def resolve_human(self, args, context, info):
|
2016-06-17 19:29:38 +03:00
|
|
|
return Human()
|
|
|
|
|
|
|
|
|
|
|
|
schema = Schema(query=Query)
|
|
|
|
|
|
|
|
|
|
|
|
urlpatterns = [
|
|
|
|
url(r'^graphql', GraphQLView.as_view(schema=schema)),
|
|
|
|
]
|