mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-25 11:04:11 +03:00
Merge pull request #23 from morgante/fix_choice_enums
Fix #19 by using choice keys as enum keys, not choice descriptions
This commit is contained in:
commit
3a9ffba560
|
@ -7,6 +7,7 @@ from graphene.relay import is_node
|
|||
from graphene.types.datetime import DateTime
|
||||
from graphene.types.json import JSONString
|
||||
from graphene.utils.str_converters import to_const
|
||||
from graphql import assert_valid_name
|
||||
|
||||
from .compat import (ArrayField, HStoreField, JSONField, RangeField,
|
||||
RelatedObject, UUIDField)
|
||||
|
@ -17,7 +18,12 @@ singledispatch = import_single_dispatch()
|
|||
|
||||
|
||||
def convert_choice_name(name):
|
||||
return to_const(force_text(name))
|
||||
name = to_const(force_text(name))
|
||||
try:
|
||||
assert_valid_name(name)
|
||||
except AssertionError:
|
||||
name = "A_%s" % name
|
||||
return name
|
||||
|
||||
|
||||
def get_choices(choices):
|
||||
|
@ -26,7 +32,7 @@ def get_choices(choices):
|
|||
for choice in get_choices(help_text):
|
||||
yield choice
|
||||
else:
|
||||
name = convert_choice_name(help_text)
|
||||
name = convert_choice_name(value)
|
||||
description = help_text
|
||||
yield name, value, description
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user