I'm working with graphene
and graphene-django
and I have a problem with a IntegerField
with choices. graphene
create an Enum
and the output is "A_1" if the value is 1; "A_2" if the value is 2 and so on. Example:
# model
class Foo(models.Model):
score = models.IntegerField(choices=((1, 1), (2, 2), (3, 3), (4, 4), (5, 5)))
# query
query {
foo {
score
}
}
# response
{
"data": {
"foo": {
"source": "A_1"
}
}
}
I found a function that convert the choices values.
def convert_choice_name(name):
name = to_const(force_text(name))
try:
assert_valid_name(name)
except AssertionError:
name = "A_%s" % name
return name
And assert_valid_name
has this regular expression:
r'^[_a-zA-Z][_a-zA-Z0-9]*$'
Therefore, whatever begins with number, it will convert it to "A_...".
How I can overwrite this output?