File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed
graphene_django/rest_framework Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ def fields_for_serializer(
26
26
exclude_fields ,
27
27
is_input = False ,
28
28
convert_choices_to_enum = True ,
29
+ lookup_field = None ,
29
30
):
30
31
fields = OrderedDict ()
31
32
for name , field in serializer .fields .items ():
@@ -35,7 +36,9 @@ def fields_for_serializer(
35
36
name in exclude_fields ,
36
37
field .write_only
37
38
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
+ field .read_only
40
+ and is_input
41
+ and lookup_field != name , # don't show read_only fields in Input
39
42
]
40
43
)
41
44
@@ -91,13 +94,15 @@ def __init_subclass_with_meta__(
91
94
exclude_fields ,
92
95
is_input = True ,
93
96
convert_choices_to_enum = convert_choices_to_enum ,
97
+ lookup_field = lookup_field ,
94
98
)
95
99
output_fields = fields_for_serializer (
96
100
serializer ,
97
101
only_fields ,
98
102
exclude_fields ,
99
103
is_input = False ,
100
104
convert_choices_to_enum = convert_choices_to_enum ,
105
+ lookup_field = lookup_field ,
101
106
)
102
107
103
108
if not _meta :
Original file line number Diff line number Diff line change @@ -143,17 +143,20 @@ class Meta:
143
143
144
144
def test_read_only_fields ():
145
145
class ReadOnlyFieldModelSerializer (serializers .ModelSerializer ):
146
+ id = serializers .CharField (read_only = True )
146
147
cool_name = serializers .CharField (read_only = True )
147
148
148
149
class Meta :
149
150
model = MyFakeModelWithPassword
150
- fields = ["cool_name" , "password" ]
151
+ lookup_field = "id"
152
+ fields = ["id" , "cool_name" , "password" ]
151
153
152
154
class MyMutation (SerializerMutation ):
153
155
class Meta :
154
156
serializer_class = ReadOnlyFieldModelSerializer
155
157
156
158
assert "password" in MyMutation .Input ._meta .fields
159
+ assert "id" in MyMutation .Input ._meta .fields
157
160
assert (
158
161
"cool_name" not in MyMutation .Input ._meta .fields
159
162
), "'cool_name' is read_only field and shouldn't be on arguments"
You can’t perform that action at this time.
0 commit comments