bornhack-website/src/bornhack/schema.py

45 lines
1.1 KiB
Python
Raw Normal View History

from graphene import ObjectType, Schema, relay
from graphene_django import DjangoObjectType
from graphene_django.filter import DjangoFilterConnectionField
from camps.models import Camp
from program.schema import ProgramQuery
class CampNode(DjangoObjectType):
class Meta:
model = Camp
2019-06-16 12:32:24 +00:00
interfaces = (relay.Node,)
filter_fields = {"title": ["icontains", "iexact"]}
only_fields = (
2019-06-16 12:32:24 +00:00
"title",
"slug",
"tagline",
"shortslug",
"buildup",
"camp",
"teardown",
"colour",
)
def resolve_buildup(self, info):
return [self.buildup.lower, self.buildup.upper]
def resolve_camp(self, info):
return [self.camp.lower, self.camp.upper]
def resolve_teardown(self, info):
return [self.teardown.lower, self.teardown.upper]
class CampQuery(object):
camp = relay.Node.Field(CampNode)
all_camps = DjangoFilterConnectionField(CampNode)
class Query(CampQuery, ProgramQuery, ObjectType):
pass
schema = Schema(query=Query)