diff --git a/graphene_django/rest_framework/serializer_converter.py b/graphene_django/rest_framework/serializer_converter.py index 03ef410..b8457ab 100644 --- a/graphene_django/rest_framework/serializer_converter.py +++ b/graphene_django/rest_framework/serializer_converter.py @@ -4,6 +4,7 @@ from rest_framework import serializers import graphene from ..utils import import_single_dispatch +from .types import DictType singledispatch = import_single_dispatch() @@ -80,3 +81,8 @@ def convert_serializer_field_to_list(field, is_input=True): child_type = get_graphene_type_from_serializer_field(field.child) return (graphene.List, child_type) + + +@get_graphene_type_from_serializer_field.register(serializers.DictField) +def convert_serializer_field_to_dict(field): + return DictType diff --git a/graphene_django/rest_framework/tests/test_field_converter.py b/graphene_django/rest_framework/tests/test_field_converter.py index 10b097f..a1b9be4 100644 --- a/graphene_django/rest_framework/tests/test_field_converter.py +++ b/graphene_django/rest_framework/tests/test_field_converter.py @@ -5,6 +5,7 @@ from py.test import raises import graphene from ..serializer_converter import convert_serializer_field +from ..types import DictType def _get_type(rest_framework_field, **kwargs): @@ -115,3 +116,7 @@ def test_should_list_convert_to_list(): field_b = assert_conversion(StringListField, graphene.List) assert field_b.of_type == graphene.String + + +def test_should_dict_convert_dict(): + assert_conversion(serializers.DictField, DictType) diff --git a/graphene_django/rest_framework/types.py b/graphene_django/rest_framework/types.py index 1fe33f3..956dc43 100644 --- a/graphene_django/rest_framework/types.py +++ b/graphene_django/rest_framework/types.py @@ -1,6 +1,12 @@ import graphene +from graphene.types.unmountedtype import UnmountedType class ErrorType(graphene.ObjectType): field = graphene.String() messages = graphene.List(graphene.String) + + +class DictType(UnmountedType): + key = graphene.String() + value = graphene.String()