Skip to content

Commit 302ea0d

Browse files
author
Jacob Foster
committed
Account for nested ModelSerializers
1 parent 93bbc19 commit 302ea0d

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

graphene_django/rest_framework/serializer_converter.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import graphene
55

6+
from ..registry import get_global_registry
67
from ..utils import import_single_dispatch
78
from .types import DictType
89

@@ -41,6 +42,7 @@ def convert_serializer_field(field, is_input=True):
4142

4243
graphql_type = get_graphene_type_from_serializer_field(field)
4344

45+
args = []
4446
kwargs = {
4547
'description': field.help_text,
4648
'required': is_input and field.required,
@@ -52,14 +54,27 @@ def convert_serializer_field(field, is_input=True):
5254
kwargs['of_type'] = graphql_type[1]
5355
graphql_type = graphql_type[0]
5456

55-
return graphql_type(**kwargs)
57+
if isinstance(field, serializers.ModelSerializer):
58+
if is_input:
59+
graphql_type = convert_serializer_to_input_type(field.__class__)
60+
else:
61+
global_registry = get_global_registry()
62+
field_model = field.Meta.model
63+
args = [global_registry.get_type_for_model(field_model)]
64+
65+
return graphql_type(*args, **kwargs)
5666

5767

5868
@get_graphene_type_from_serializer_field.register(serializers.Field)
5969
def convert_serializer_field_to_string(field):
6070
return graphene.String
6171

6272

73+
@get_graphene_type_from_serializer_field.register(serializers.ModelSerializer)
74+
def convert_serializer_to_field(field):
75+
return graphene.Field
76+
77+
6378
@get_graphene_type_from_serializer_field.register(serializers.IntegerField)
6479
def convert_serializer_field_to_int(field):
6580
return graphene.Int

0 commit comments

Comments
 (0)