graphene-django/graphene_django/tests/schema_view.py

30 lines
703 B
Python
Raw Normal View History

import graphene
2017-07-25 08:27:50 +03:00
from graphene import ObjectType, Schema, annotate, Context
class QueryRoot(ObjectType):
thrower = graphene.String(required=True)
request = graphene.String(required=True)
test = graphene.String(who=graphene.String())
2016-09-20 08:15:10 +03:00
2017-07-25 08:27:50 +03:00
def resolve_thrower(self):
raise Exception("Throws!")
2016-09-20 08:15:10 +03:00
2017-07-25 08:27:50 +03:00
@annotate(request=Context)
def resolve_request(self, request):
return request.GET.get('q')
2017-07-25 08:27:50 +03:00
def resolve_test(self, who=None):
return 'Hello %s' % (who or 'World')
class MutationRoot(ObjectType):
write_test = graphene.Field(QueryRoot)
2017-07-25 08:27:50 +03:00
def resolve_write_test(self):
return QueryRoot()
schema = Schema(query=QueryRoot, mutation=MutationRoot)