mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-22 17:47:12 +03:00
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:
parent
9cac83b168
commit
cc58b91e43
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user