Register MultipleChoiceField as list type (#1033)

In general I welcome reviews even from non-maintainers to build confidence. I haven't seen any objections and this has sat with approval for a week so I am going to go ahead and merge.
This commit is contained in:
Ülgen Sarıkavak 2020-11-28 21:30:18 +03:00 committed by GitHub
parent 4b7119d691
commit 4c0c821b74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -63,6 +63,11 @@ def convert_form_field_to_list(field):
return List(ID, required=field.required)
@convert_form_field.register(forms.MultipleChoiceField)
def convert_form_field_to_string_list(field):
return List(String, required=field.required)
@convert_form_field.register(forms.DateField)
def convert_form_field_to_date(field):
return Date(description=field.help_text, required=field.required)

View File

@ -101,7 +101,14 @@ def test_should_decimal_convert_float():
assert_conversion(forms.DecimalField, Float)
def test_should_multiple_choice_convert_connectionorlist():
def test_should_multiple_choice_convert_list():
field = forms.MultipleChoiceField()
graphene_type = convert_form_field(field)
assert isinstance(graphene_type, List)
assert graphene_type.of_type == String
def test_should_model_multiple_choice_convert_connectionorlist():
field = forms.ModelMultipleChoiceField(queryset=None)
graphene_type = convert_form_field(field)
assert isinstance(graphene_type, List)