Improved choice Enum converter

This commit is contained in:
Syrus Akbary 2016-11-02 21:45:49 -07:00
parent 854aa4aa9b
commit 5289cd06d7
2 changed files with 4 additions and 4 deletions

View File

@ -6,7 +6,7 @@ from graphene import (ID, Boolean, Dynamic, Enum, Field, Float, Int, List,
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 graphene.utils.str_converters import to_camel_case, to_const
from graphql import assert_valid_name
from .compat import (ArrayField, HStoreField, JSONField, RangeField,
@ -41,7 +41,7 @@ def convert_django_field_with_choices(field, registry=None):
choices = getattr(field, 'choices', None)
if choices:
meta = field.model._meta
name = '{}{}'.format(meta.object_name, field.name.capitalize())
name = to_camel_case('{}_{}'.format(meta.object_name, field.name))
choices = list(get_choices(choices))
named_choices = [(c[0], c[1]) for c in choices]
named_choices_descriptions = {c[0]: c[2] for c in choices}

View File

@ -110,11 +110,11 @@ type Reporter {
lastName: String!
email: String!
pets: [Reporter]
aChoice: ReporterA_choice!
aChoice: ReporterAChoice!
articles(before: String, after: String, first: Int, last: Int): ArticleConnection
}
enum ReporterA_choice {
enum ReporterAChoice {
A_1
A_2
}