Remove default output fields from SerializerMutation

I found a little annoying that when we use a SerializerMutation all fields in the Serializer, used mostly for the Input, also gets added in the Output. 

The best reason to use a SerializerMutation is for the input validations that DRF brings to the table, the Output is very easy to set and most of the times we want to return our own ObjectType, not all fields used as the input.

What you guys think?
This commit is contained in:
Alisson Patricio 2023-08-22 04:01:55 +02:00 committed by GitHub
parent 0473f1a9a3
commit 98825f9a0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -99,14 +99,6 @@ class SerializerMutation(ClientIDMutation):
convert_choices_to_enum=convert_choices_to_enum,
lookup_field=lookup_field,
)
output_fields = fields_for_serializer(
serializer,
only_fields,
exclude_fields,
is_input=False,
convert_choices_to_enum=convert_choices_to_enum,
lookup_field=lookup_field,
)
if not _meta:
_meta = SerializerMutationOptions(cls)
@ -114,7 +106,6 @@ class SerializerMutation(ClientIDMutation):
_meta.model_operations = model_operations
_meta.serializer_class = serializer_class
_meta.model_class = model_class
_meta.fields = yank_fields_from_attrs(output_fields, _as=Field)
input_fields = yank_fields_from_attrs(input_fields, _as=InputField)
super().__init_subclass_with_meta__(