Add new class instead of dict

This commit is contained in:
Ramon Wenger 2022-05-19 15:35:29 +02:00
parent 6e1501f33b
commit 775bff5c1b
3 changed files with 14 additions and 3 deletions

View File

@ -6,6 +6,10 @@ from graphene_django.filter import DjangoFilterConnectionField
from books.models import Topic, Module
from books.schema.nodes import ModuleNode
class NotFoundFailure:
reason = 'Not Found'
NOT_FOUND = { 'reason': 'Not Found'}
class NotFound(graphene.ObjectType):

View File

@ -5,7 +5,8 @@ from graphene_django.filter import DjangoFilterConnectionField
from api.utils import get_object
from core.logger import get_logger
from .connections import TopicConnection, ModuleConnection
from .nodes import ContentBlockNode, ChapterNode, ModuleNode, NOT_FOUND, TopicNode, SnapshotNode, TopicOr404Node
from .nodes import ContentBlockNode, ChapterNode, ModuleNode, NOT_FOUND, NotFoundFailure, TopicNode, SnapshotNode, \
TopicOr404Node
from ..models import Book, Topic, Module, Chapter, Snapshot
logger = get_logger(__name__)
@ -66,5 +67,5 @@ class BookQuery(object):
try:
return Topic.objects.get(slug=slug)
except Topic.DoesNotExist:
return NOT_FOUND
return NotFoundFailure
return None

View File

@ -702,6 +702,10 @@ interface Node {
id: ID!
}
type NotFound {
reason: String
}
type NoteNode implements Node {
id: ID!
text: String!
@ -852,7 +856,7 @@ type Query {
assignment(id: ID!): AssignmentNode
assignments: [AssignmentNode]
node(id: ID!): Node
topic(slug: String): TopicNode
topic(slug: String): TopicOr404Node
module(slug: String, id: ID): ModuleNode
chapter(id: ID!): ChapterNode
contentBlock(id: ID!): ContentBlockNode
@ -1127,6 +1131,8 @@ type TopicNode implements Node {
modules(offset: Int, before: String, after: String, first: Int, last: Int, slug: String, slug_Icontains: String, slug_In: [String], title: String, title_Icontains: String, title_In: [String]): ModuleNodeConnection
}
union TopicOr404Node = TopicNode | NotFound
scalar UUID
input UpdateAnswerArgument {