3
3
4
4
from django .db import models
5
5
from django .utils .encoding import force_str
6
+ from django .utils .functional import Promise
6
7
from django .utils .module_loading import import_string
7
-
8
8
from graphene import (
9
9
ID ,
10
+ UUID ,
10
11
Boolean ,
12
+ Date ,
13
+ DateTime ,
11
14
Dynamic ,
12
15
Enum ,
13
16
Field ,
16
19
List ,
17
20
NonNull ,
18
21
String ,
19
- UUID ,
20
- DateTime ,
21
- Date ,
22
22
Time ,
23
23
)
24
24
from graphene .types .json import JSONString
25
25
from graphene .utils .str_converters import to_camel_case , to_const
26
- from graphql import assert_valid_name
26
+ from graphql import GraphQLError , assert_valid_name
27
+ from graphql .pyutils import register_description
27
28
28
- from .settings import graphene_settings
29
29
from .compat import ArrayField , HStoreField , JSONField , RangeField
30
- from .fields import DjangoListField , DjangoConnectionField
30
+ from .fields import DjangoConnectionField , DjangoListField
31
+ from .settings import graphene_settings
31
32
32
33
33
34
def convert_choice_name (name ):
34
35
name = to_const (force_str (name ))
35
36
try :
36
37
assert_valid_name (name )
37
- except AssertionError :
38
+ except GraphQLError :
38
39
name = "A_%s" % name
39
40
return name
40
41
@@ -52,7 +53,9 @@ def get_choices(choices):
52
53
while name in converted_names :
53
54
name += "_" + str (len (converted_names ))
54
55
converted_names .append (name )
55
- description = help_text
56
+ description = str (
57
+ help_text
58
+ ) # TODO: translatable description: https://github.com/graphql-python/graphql-core-next/issues/58
56
59
yield name , value , description
57
60
58
61
@@ -64,7 +67,7 @@ def convert_choices_to_named_enum_with_descriptions(name, choices):
64
67
class EnumWithDescriptionsType (object ):
65
68
@property
66
69
def description (self ):
67
- return named_choices_descriptions [self .name ]
70
+ return str ( named_choices_descriptions [self .name ])
68
71
69
72
return Enum (name , list (named_choices ), type = EnumWithDescriptionsType )
70
73
@@ -276,3 +279,8 @@ def convert_postgres_range_to_string(field, registry=None):
276
279
if not isinstance (inner_type , (List , NonNull )):
277
280
inner_type = type (inner_type )
278
281
return List (inner_type , description = field .help_text , required = not field .null )
282
+
283
+
284
+ # Register Django lazy()-wrapped values as GraphQL description/help_text.
285
+ # This is needed for using lazy translations, see https://github.com/graphql-python/graphql-core-next/issues/58.
286
+ register_description (Promise )
0 commit comments