Adds graphql interface to objectives

This commit is contained in:
Pawel Kowalski 2018-08-14 16:26:39 +02:00
parent 1341589f89
commit e3ee972530
5 changed files with 33 additions and 6 deletions

View File

@ -0,0 +1,27 @@
query ModulesQuery($slug: String!) {
modules(slug:$slug) {
edges {
node {
id
title
aSlug: slug
objectivegroupSet {
edges {
node {
id
title
objectiveSet {
edges {
node {
id
text
}
}
}
}
}
}
}
}
}
}

View File

@ -2,11 +2,11 @@ import graphene
from django.conf import settings from django.conf import settings
from graphene_django.debug import DjangoDebug from graphene_django.debug import DjangoDebug
from book.schema import ModulesQuery from book.schema import BookQuery
from objectives.schema import ObjectivesQuery from objectives.schema import ObjectivesQuery
class Query(ObjectivesQuery, ModulesQuery, graphene.ObjectType): class Query(ObjectivesQuery, BookQuery, graphene.ObjectType):
# This class will inherit from multiple Queries # This class will inherit from multiple Queries
if settings.DEBUG: if settings.DEBUG:

View File

@ -13,7 +13,7 @@ class ModuleNode(DjangoObjectType):
class Meta: class Meta:
model = Module model = Module
only_fields = [ only_fields = [
'slug', 'title', 'meta_title', 'teaser', 'description', 'slug', 'title', 'meta_title', 'teaser', 'description', 'objectivegroup_set'
] ]
filter_fields = { filter_fields = {
'slug': ['exact', 'icontains', 'in'], 'slug': ['exact', 'icontains', 'in'],
@ -73,7 +73,7 @@ class BookNode(DjangoObjectType):
return Topic.get_book_topics(self) return Topic.get_book_topics(self)
class ModulesQuery(object): class BookQuery(object):
books = DjangoFilterConnectionField(BookNode) books = DjangoFilterConnectionField(BookNode)
topics = DjangoFilterConnectionField(TopicNode) topics = DjangoFilterConnectionField(TopicNode)
modules = DjangoFilterConnectionField(ModuleNode) modules = DjangoFilterConnectionField(ModuleNode)

View File

@ -13,7 +13,7 @@ class ObjectiveGroup(models.Model):
title = models.CharField('title', blank=True, null=False, max_length=255) title = models.CharField('title', blank=True, null=False, max_length=255)
module = models.ForeignKey(Module, blank=False, null=False, on_delete=models.CASCADE) module = models.ForeignKey(Module, blank=False, null=False, on_delete=models.CASCADE)
# a user can define her own objectives, hence this param # a user can define her own objectives, hence this optional param
user = models.ForeignKey(get_user_model(), blank=True, null=True, on_delete=models.CASCADE) user = models.ForeignKey(get_user_model(), blank=True, null=True, on_delete=models.CASCADE)
def __str__(self): def __str__(self):

View File

@ -40,4 +40,4 @@ class ObjectiveProgressStatusNode(DjangoObjectType):
class ObjectivesQuery(object): class ObjectivesQuery(object):
user_focus = DjangoFilterConnectionField(ObjectiveGroupNode) objective_groups = DjangoFilterConnectionField(ObjectiveGroupNode)