diff --git a/graphene_django/rest_framework/mutation.py b/graphene_django/rest_framework/mutation.py index 4062a44..b7393da 100644 --- a/graphene_django/rest_framework/mutation.py +++ b/graphene_django/rest_framework/mutation.py @@ -39,6 +39,9 @@ def fields_for_serializer( field.read_only and is_input and lookup_field != name, # don't show read_only fields in Input + isinstance( + field, serializers.HiddenField + ), # don't show hidden fields in Input ] ) diff --git a/graphene_django/rest_framework/tests/test_mutation.py b/graphene_django/rest_framework/tests/test_mutation.py index 5de8237..91d99f0 100644 --- a/graphene_django/rest_framework/tests/test_mutation.py +++ b/graphene_django/rest_framework/tests/test_mutation.py @@ -164,6 +164,21 @@ def test_read_only_fields(): ), "'cool_name' is read_only field and shouldn't be on arguments" +def test_hidden_fields(): + class SerializerWithHiddenField(serializers.Serializer): + cool_name = serializers.CharField() + user = serializers.HiddenField(default=serializers.CurrentUserDefault()) + + class MyMutation(SerializerMutation): + class Meta: + serializer_class = SerializerWithHiddenField + + assert "cool_name" in MyMutation.Input._meta.fields + assert ( + "user" not in MyMutation.Input._meta.fields + ), "'user' is hidden field and shouldn't be on arguments" + + def test_nested_model(): class MyFakeModelGrapheneType(DjangoObjectType): class Meta: