Add StreamField serializer

This commit is contained in:
Pawel Kowalski 2018-08-15 14:45:18 +02:00
parent 4a3ffd9eac
commit 3ba9af1ce7
4 changed files with 22 additions and 1 deletions

View File

@ -35,6 +35,7 @@ query ModulesQuery($slug: String!) {
slug
title
type
contents
}
}
}

View File

@ -0,0 +1,19 @@
# mysite/api/graphene_wagtail.py
# Taken from https://github.com/patrick91/wagtail-ql/blob/master/backend/graphene_utils/converter.py and slightly adjusted
from graphene.types import Scalar
from graphene_django.converter import convert_django_field
from wagtail.core.fields import StreamField
class GenericStreamFieldType(Scalar):
@staticmethod
def serialize(stream_value):
return stream_value.stream_data
@convert_django_field.register(StreamField)
def convert_stream_field(field, registry=None):
return GenericStreamFieldType(
description=field.help_text, required=not field.null
)

View File

@ -1,6 +1,7 @@
import graphene
from django.conf import settings
from graphene_django.debug import DjangoDebug
from api import graphene_wagtail
from book.schema import BookQuery
from objectives.schema import ObjectivesQuery

View File

@ -10,7 +10,7 @@ class ContentBlockNode(DjangoObjectType):
class Meta:
model = ContentBlock
only_fields = [
'slug', 'title', 'type'
'slug', 'title', 'type', 'contents'
]
filter_fields = [
'slug', 'title',