import graphene from graphene import relay from graphene_django import DjangoObjectType from graphene_django.filter import DjangoFilterConnectionField from .chapter import SnapshotChapterNode from books.models.snapshot import Snapshot class SnapshotNode(DjangoObjectType): title = graphene.String() class Meta: model = Snapshot interfaces = (relay.Node,) # chapters = relay.ConnectionField('books.schema.connections.ChapterSnapshotConnection') chapters = DjangoFilterConnectionField(SnapshotChapterNode) def resolve_chapters(self, info, **kwargs): # return Chapter.objects.filter(chapter_snapshots__snapshot=self) return self.chapters.through.objects.all() @staticmethod def resolve_title(parent, info, **kwargs): return parent.__str__()