2424from .compat import ArrayField , HStoreField , JSONField , RangeField
2525from .fields import DjangoListField , DjangoConnectionField
2626from .utils import import_single_dispatch
27+ from .settings import graphene_settings
2728
2829singledispatch = import_single_dispatch ()
2930
@@ -58,7 +59,7 @@ def convert_django_field_with_choices(field, registry=None):
5859 if converted :
5960 return converted
6061 choices = getattr (field , "choices" , None )
61- if choices :
62+ if choices and graphene_settings . GRAPHENE_CONVERT_CHOICES_TO_ENUMS :
6263 meta = field .model ._meta
6364 name = to_camel_case ("{}_{}" .format (meta .object_name , field .name ))
6465 choices = list (get_choices (choices ))
@@ -211,10 +212,10 @@ def dynamic_type():
211212
212213@convert_django_field .register (ArrayField )
213214def convert_postgres_array_to_list (field , registry = None ):
214- base_type = convert_django_field (field .base_field )
215- if not isinstance (base_type , (List , NonNull )):
216- base_type = type (base_type )
217- return List (base_type , description = field .help_text , required = not field .null )
215+ inner_type = convert_django_field (field .base_field )
216+ if not isinstance (inner_type , (List , NonNull )):
217+ inner_type = NonNull ( type (inner_type )) if inner_type . kwargs [ 'required' ] else type ( inner_type )
218+ return List (inner_type , description = field .help_text , required = not field .null )
218219
219220
220221@convert_django_field .register (HStoreField )
@@ -227,5 +228,5 @@ def convert_posgres_field_to_string(field, registry=None):
227228def convert_posgres_range_to_string (field , registry = None ):
228229 inner_type = convert_django_field (field .base_field )
229230 if not isinstance (inner_type , (List , NonNull )):
230- inner_type = type (inner_type )
231+ inner_type = NonNull ( type ( inner_type )) if inner_type . kwargs [ 'required' ] else type (inner_type )
231232 return List (inner_type , description = field .help_text , required = not field .null )
0 commit comments