Skip to content

Commit 68f6281

Browse files
committed
Add support for dict field
1 parent f747102 commit 68f6281

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

graphene_django/rest_framework/serializer_converter.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import graphene
55

66
from ..utils import import_single_dispatch
7+
from .types import DictType
78

89
singledispatch = import_single_dispatch()
910

@@ -80,3 +81,8 @@ def convert_serializer_field_to_list(field, is_input=True):
8081
child_type = get_graphene_type_from_serializer_field(field.child)
8182

8283
return (graphene.List, child_type)
84+
85+
86+
@get_graphene_type_from_serializer_field.register(serializers.DictField)
87+
def convert_serializer_field_to_dict(field):
88+
return DictType

graphene_django/rest_framework/tests/test_field_converter.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import graphene
66

77
from ..serializer_converter import convert_serializer_field
8+
from ..types import DictType
89

910

1011
def _get_type(rest_framework_field, **kwargs):
@@ -115,3 +116,7 @@ class StringListField(serializers.ListField):
115116
field_b = assert_conversion(StringListField, graphene.List)
116117

117118
assert field_b.of_type == graphene.String
119+
120+
121+
def test_should_dict_convert_dict():
122+
assert_conversion(serializers.DictField, DictType)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import graphene
2+
from graphene.types.unmountedtype import UnmountedType
23

34

45
class ErrorType(graphene.ObjectType):
56
field = graphene.String()
67
messages = graphene.List(graphene.String)
8+
9+
10+
class DictType(UnmountedType):
11+
key = graphene.String()
12+
value = graphene.String()

0 commit comments

Comments
 (0)