Add StreamField serializer
This commit is contained in:
parent
4a3ffd9eac
commit
3ba9af1ce7
|
|
@ -35,6 +35,7 @@ query ModulesQuery($slug: String!) {
|
||||||
slug
|
slug
|
||||||
title
|
title
|
||||||
type
|
type
|
||||||
|
contents
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
)
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import graphene
|
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 api import graphene_wagtail
|
||||||
|
|
||||||
from book.schema import BookQuery
|
from book.schema import BookQuery
|
||||||
from objectives.schema import ObjectivesQuery
|
from objectives.schema import ObjectivesQuery
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ class ContentBlockNode(DjangoObjectType):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ContentBlock
|
model = ContentBlock
|
||||||
only_fields = [
|
only_fields = [
|
||||||
'slug', 'title', 'type'
|
'slug', 'title', 'type', 'contents'
|
||||||
]
|
]
|
||||||
filter_fields = [
|
filter_fields = [
|
||||||
'slug', 'title',
|
'slug', 'title',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue