Description
Let's say I have a model in Django with a field that has choices. Only, because I'm Icelandic, those choices might be in Icelandic and contain utf-8 characters. Generating an enum from my model will fail.
F.ex.:
class School(models.Model):
MUNICIPALITIES = (
('Hafnarfjarðarkaupstaður', 'Hafnarfjarðarkaupstaður'),
('Reykjanesbær', 'Reykjanesbær'),
('Garðabær', 'Garðabær'),
...
)
name = models.CharField(max_length=128)
municipality = models.CharField(max_length=32, blank=True, null=True, choices=MUNICIPALITIES)
I then try to create a Query object:
class SchoolNode(DjangoObjectType):
@classmethod
class Meta:
model = School
filter_fields = [
'id',
'name',
]
exclude_fields = [
]
interfaces = (relay.Node,)
class Query(object):
school = relay.Node.Field(SchoolNode)
all_schools = DjangoFilterConnectionField(SchoolNode)
This will then fail in graphql.utils.assert_valid_name.assert_valid_name
at schema evaluation since to_const doesn't handle converting unicode characters to ascii:
Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but "A_HAFNARFJARÐARKAUPSTAÐUR" does not.
I really doubt I'm the only one running into this. Most people just handle this stuff differently I suppose? Manually switch out code, or use an actual Enum() in the choices?
My proposed solution is to use the unidecode package, specifically designed for this. I'll throw together a PR.