Add urls to graphql schema.

This commit is contained in:
Víðir Valberg Guðmundsson 2019-03-18 22:11:33 +01:00
parent 6d151b5519
commit 0f11a77a92

View file

@ -1,3 +1,4 @@
from django.db.models import Q
from graphene import relay from graphene import relay
from graphene_django import DjangoObjectType from graphene_django import DjangoObjectType
@ -10,7 +11,7 @@ from .models import (
EventTrack, EventTrack,
EventInstance, EventInstance,
Speaker, Speaker,
) Url, UrlType)
class EventTypeNode(DjangoObjectType): class EventTypeNode(DjangoObjectType):
@ -28,6 +29,7 @@ class EventLocationNode(DjangoObjectType):
interfaces = (relay.Node, ) interfaces = (relay.Node, )
filter_fields = { filter_fields = {
'name': ['iexact'], 'name': ['iexact'],
'camp__slug': ['iexact'],
} }
@ -37,6 +39,7 @@ class EventTrackNode(DjangoObjectType):
interfaces = (relay.Node, ) interfaces = (relay.Node, )
filter_fields = { filter_fields = {
'name': ['iexact'], 'name': ['iexact'],
'camp__slug': ['iexact'],
} }
@ -47,6 +50,7 @@ class EventInstanceNode(DjangoObjectType):
interfaces = (relay.Node, ) interfaces = (relay.Node, )
filter_fields = { filter_fields = {
'event__title': ['iexact'], 'event__title': ['iexact'],
'event__track__camp__slug': ['iexact'],
} }
def resolve_when(self, info): def resolve_when(self, info):
@ -58,9 +62,10 @@ class SpeakerNode(DjangoObjectType):
class Meta: class Meta:
model = Speaker model = Speaker
interfaces = (relay.Node, ) interfaces = (relay.Node, )
only_fields = ('id', 'name', 'biography', 'slug', 'camp', 'events') only_fields = ('id', 'name', 'biography', 'slug', 'camp', 'events',)
filter_fields = { filter_fields = {
'name': ['iexact'], 'name': ['iexact'],
'camp__slug': ['iexact'],
} }
@ -74,6 +79,19 @@ class EventNode(DjangoObjectType):
} }
class UrlNode(DjangoObjectType):
class Meta:
model = Url
interfaces = (relay.Node, )
only_fields = ('url', 'urltype',)
class UrlTypeNode(DjangoObjectType):
class Meta:
model = UrlType
interfaces = (relay.Node, )
class ProgramQuery(object): class ProgramQuery(object):
event_type = relay.Node.Field(EventTypeNode) event_type = relay.Node.Field(EventTypeNode)
all_event_types = DjangoFilterConnectionField(EventTypeNode) all_event_types = DjangoFilterConnectionField(EventTypeNode)
@ -93,3 +111,5 @@ class ProgramQuery(object):
speaker = relay.Node.Field(SpeakerNode) speaker = relay.Node.Field(SpeakerNode)
all_speakers = DjangoFilterConnectionField(SpeakerNode) all_speakers = DjangoFilterConnectionField(SpeakerNode)
url = relay.Node.Field(UrlNode)
url_type = relay.Node.Field(UrlTypeNode)