33
44from django .db import models
55from django .utils .encoding import force_str
6+ from django .utils .functional import Promise
67from django .utils .module_loading import import_string
7-
88from graphene import (
99 ID ,
10+ UUID ,
1011 Boolean ,
12+ Date ,
13+ DateTime ,
1114 Dynamic ,
1215 Enum ,
1316 Field ,
1619 List ,
1720 NonNull ,
1821 String ,
19- UUID ,
20- DateTime ,
21- Date ,
2222 Time ,
2323)
2424from graphene .types .json import JSONString
2525from 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
2728
28- from .settings import graphene_settings
2929from .compat import ArrayField , HStoreField , JSONField , RangeField
30- from .fields import DjangoListField , DjangoConnectionField
30+ from .fields import DjangoConnectionField , DjangoListField
31+ from .settings import graphene_settings
3132
3233
3334def convert_choice_name (name ):
3435 name = to_const (force_str (name ))
3536 try :
3637 assert_valid_name (name )
37- except AssertionError :
38+ except GraphQLError :
3839 name = "A_%s" % name
3940 return name
4041
@@ -52,7 +53,9 @@ def get_choices(choices):
5253 while name in converted_names :
5354 name += "_" + str (len (converted_names ))
5455 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
5659 yield name , value , description
5760
5861
@@ -64,7 +67,7 @@ def convert_choices_to_named_enum_with_descriptions(name, choices):
6467 class EnumWithDescriptionsType (object ):
6568 @property
6669 def description (self ):
67- return named_choices_descriptions [self .name ]
70+ return str ( named_choices_descriptions [self .name ])
6871
6972 return Enum (name , list (named_choices ), type = EnumWithDescriptionsType )
7073
@@ -276,3 +279,8 @@ def convert_postgres_range_to_string(field, registry=None):
276279 if not isinstance (inner_type , (List , NonNull )):
277280 inner_type = type (inner_type )
278281 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