File tree Expand file tree Collapse file tree 2 files changed +26
-6
lines changed
graphene_django/rest_framework Expand file tree Collapse file tree 2 files changed +26
-6
lines changed Original file line number Diff line number Diff line change @@ -30,12 +30,13 @@ def fields_for_serializer(
3030 fields = OrderedDict ()
3131 for name , field in serializer .fields .items ():
3232 is_not_in_only = only_fields and name not in only_fields
33- is_excluded = (
34- name
35- in exclude_fields # or
36- # name in already_created_fields
37- ) or (
38- field .write_only and not is_input # don't show write_only fields in Query
33+ is_excluded = any (
34+ [
35+ name in exclude_fields ,
36+ field .write_only
37+ and not is_input , # don't show write_only fields in Query
38+ field .read_only and is_input , # don't show read_only fields in Input
39+ ]
3940 )
4041
4142 if is_not_in_only or is_excluded :
Original file line number Diff line number Diff line change @@ -144,6 +144,25 @@ class Meta:
144144 ), "'password' is write_only field and shouldn't be visible"
145145
146146
147+ @mark .django_db
148+ def test_read_only_fields ():
149+ class ReadOnlyFieldModelSerializer (serializers .ModelSerializer ):
150+ cool_name = serializers .CharField (read_only = True )
151+
152+ class Meta :
153+ model = MyFakeModelWithPassword
154+ fields = ["cool_name" , "password" ]
155+
156+ class MyMutation (SerializerMutation ):
157+ class Meta :
158+ serializer_class = ReadOnlyFieldModelSerializer
159+
160+ assert "password" in MyMutation .Input ._meta .fields
161+ assert (
162+ "cool_name" not in MyMutation .Input ._meta .fields
163+ ), "'cool_name' is read_only field and shouldn't be on arguments"
164+
165+
147166def test_nested_model ():
148167 class MyFakeModelGrapheneType (DjangoObjectType ):
149168 class Meta :
You can’t perform that action at this time.
0 commit comments