graphql-python / graphql-python/graphene-django
Should get_choices(choices) return correct name, value and description to build Enum type?
- Dominant language
- Python
- Stars
- 4.4k
- Forks
- 760
- PR merge metrics
- No merged PRs in 30d
Description
https://github.com/graphql-python/graphene-django/blob/4573d3db53529fe7ae17a0d342ff626158eb23b6/graphene_django/converter.py#L74
Currently when calling get_choices() function will generate an enum type with same name/value pairs. E.g.:
A field with choices: `((1, 'PENDING'), (2, 'RUNNING'), (3, 'COMPLETE'))` will generate an enum like this:
```python
class GeneratedEnumType:
1 = 1
2 = 2
3 = 3
```
Instead I expect it should generate an Enum like this:
```python
class GeneratedEnumType:
PENDING = 1
RUNNING = 2
COMPLETE = 3
```
So I have to change `name = convert_choice_name(help_text)` by passing `help_text` instead of `value` here:
```python
def get_choices(choices):
converted_names = []
if isinstance(choices, OrderedDict):
choices = choices.items()
for value, help_text in choices:
if isinstance(help_text, (tuple, list)):
for choice in get_choices(help_text):
yield choice
else:
name = convert_choice_name(help_text) # changed from `value` to `help_text`
while name in converted_names:
name += "_" + str(len(converted_names))
converted_names.append(name)
description = str(
help_text
) # TODO: translatable description: https://github.com/graphql-python/graphql-core-next/issues/58
yield name, value, description
```
Not sure should I change it like this?
Contributor guide
Assessment
This issue has not been assessed yet.