File: schema_view.py

package info (click to toggle)
django-graphene 3.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 8,996 kB
  • sloc: javascript: 25,534; python: 11,992; makefile: 233; sh: 4
file content (31 lines) | stat: -rw-r--r-- 812 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import graphene
from graphene import ObjectType, Schema

from .mutations import PetFormMutation, PetMutation


class QueryRoot(ObjectType):
    thrower = graphene.String(required=True)
    request = graphene.String(required=True)
    test = graphene.String(who=graphene.String())

    def resolve_thrower(self, info):
        raise Exception("Throws!")

    def resolve_request(self, info):
        return info.context.GET.get("q")

    def resolve_test(self, info, who=None):
        return "Hello %s" % (who or "World")


class MutationRoot(ObjectType):
    pet_form_mutation = PetFormMutation.Field()
    pet_mutation = PetMutation.Field()
    write_test = graphene.Field(QueryRoot)

    def resolve_write_test(self, info):
        return QueryRoot()


schema = Schema(query=QueryRoot, mutation=MutationRoot)