|
1 | 1 | from collections import OrderedDict |
| 2 | +from functools import singledispatch |
| 3 | + |
2 | 4 | from django.db import models |
3 | 5 | from django.utils.encoding import force_str |
4 | 6 | from django.utils.module_loading import import_string |
|
21 | 23 | ) |
22 | 24 | from graphene.types.json import JSONString |
23 | 25 | from graphene.utils.str_converters import to_camel_case, to_const |
24 | | -from graphql import assert_valid_name |
| 26 | +from graphql import assert_valid_name, GraphQLError |
25 | 27 |
|
26 | 28 | from .settings import graphene_settings |
27 | 29 | from .compat import ArrayField, HStoreField, JSONField, RangeField |
28 | 30 | from .fields import DjangoListField, DjangoConnectionField |
29 | | -from .utils import import_single_dispatch |
30 | | - |
31 | | -singledispatch = import_single_dispatch() |
32 | 31 |
|
33 | 32 |
|
34 | 33 | def convert_choice_name(name): |
35 | 34 | name = to_const(force_str(name)) |
36 | 35 | try: |
37 | 36 | assert_valid_name(name) |
38 | | - except AssertionError: |
| 37 | + except GraphQLError: |
39 | 38 | name = "A_%s" % name |
40 | 39 | return name |
41 | 40 |
|
@@ -65,7 +64,7 @@ def convert_choices_to_named_enum_with_descriptions(name, choices): |
65 | 64 | class EnumWithDescriptionsType(object): |
66 | 65 | @property |
67 | 66 | def description(self): |
68 | | - return named_choices_descriptions[self.name] |
| 67 | + return str(named_choices_descriptions[self.name]) |
69 | 68 |
|
70 | 69 | return Enum(name, list(named_choices), type=EnumWithDescriptionsType) |
71 | 70 |
|
@@ -277,3 +276,12 @@ def convert_postgres_range_to_string(field, registry=None): |
277 | 276 | if not isinstance(inner_type, (List, NonNull)): |
278 | 277 | inner_type = type(inner_type) |
279 | 278 | return List(inner_type, description=field.help_text, required=not field.null) |
| 279 | + |
| 280 | + |
| 281 | +from django.utils.functional import Promise |
| 282 | +from graphql.pyutils import register_description |
| 283 | + |
| 284 | + |
| 285 | +# Register Django lazy()-wrapped values as GraphQL description/help_text. |
| 286 | +# This is needed for using lazy translations, see https://github.com/graphql-python/graphql-core-next/issues/58. |
| 287 | +register_description(Promise) |
0 commit comments