2016-09-20 08:04:23 +03:00
|
|
|
import graphene
|
2017-07-25 08:27:50 +03:00
|
|
|
from graphene import ObjectType, Schema, annotate, Context
|
2016-09-20 08:04:23 +03:00
|
|
|
|
|
|
|
|
|
|
|
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):
|
2016-09-20 08:04:23 +03:00
|
|
|
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):
|
2016-09-20 08:04:23 +03:00
|
|
|
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')
|
2016-09-20 08:04:23 +03:00
|
|
|
|
|
|
|
|
|
|
|
class MutationRoot(ObjectType):
|
|
|
|
write_test = graphene.Field(QueryRoot)
|
|
|
|
|
2017-07-25 08:27:50 +03:00
|
|
|
def resolve_write_test(self):
|
2016-09-20 08:04:23 +03:00
|
|
|
return QueryRoot()
|
|
|
|
|
|
|
|
|
|
|
|
schema = Schema(query=QueryRoot, mutation=MutationRoot)
|