fix SerializerMutation regression for 2.x

72529b7 seems to break SerializerMutation by commenting out support for
input fields. As a result input only ever had a clientMutationId field.
This commit is contained in:
Andy Clayton 2017-08-31 11:07:05 -05:00
parent 9cac83b168
commit cc58b91e43
3 changed files with 20 additions and 6 deletions

View File

@ -55,6 +55,7 @@ class SerializerMutation(ClientIDMutation):
output_fields = fields_for_serializer(serializer, only_fields, exclude_fields, is_input=False)
_meta = SerializerMutationOptions(cls)
_meta.serializer_class = serializer_class
_meta.fields = yank_fields_from_attrs(
output_fields,
_as=Field,

View File

@ -42,8 +42,7 @@ def convert_serializer_field(field, is_input=True):
if isinstance(field, serializers.ModelSerializer):
if is_input:
return Dynamic(lambda: None)
# graphql_type = convert_serializer_to_input_type(field.__class__)
graphql_type = convert_serializer_to_input_type(field.__class__)
else:
global_registry = get_global_registry()
field_model = field.Meta.model
@ -52,6 +51,21 @@ def convert_serializer_field(field, is_input=True):
return graphql_type(*args, **kwargs)
def convert_serializer_to_input_type(serializer_class):
serializer = serializer_class()
items = {
name: convert_serializer_field(field)
for name, field in serializer.fields.items()
}
return type(
'{}Input'.format(serializer.__class__.__name__),
(graphene.InputObjectType,),
items
)
@get_graphene_type_from_serializer_field.register(serializers.Field)
def convert_serializer_field_to_string(field):
return graphene.String

View File

@ -65,7 +65,6 @@ def test_nested_model():
assert model_field.type == MyFakeModelGrapheneType
model_input = MyMutation.Input._meta.fields['model']
model_input_type = model_input.get_type()
assert not model_input_type
# assert issubclass(model_input_type, InputObjectType)
# assert 'cool_name' in model_input_type._meta.fields
model_input_type = model_input._type.of_type
assert issubclass(model_input_type, InputObjectType)
assert 'cool_name' in model_input_type._meta.fields