Skip to content

Commit c2ae343

Browse files
committed
Register Django's _('translatable string') as a field description in graphql-core
1 parent 4cc4add commit c2ae343

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

graphene_django/converter.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from django.db import models
22
from django.utils.encoding import force_text
3+
from django.utils.functional import Promise
34

45
from graphene import (
56
ID,
@@ -20,6 +21,7 @@
2021
from graphene.types.json import JSONString
2122
from graphene.utils.str_converters import to_camel_case, to_const
2223
from graphql import assert_valid_name, GraphQLError
24+
from graphql.pyutils import register_description
2325

2426
from .compat import ArrayField, HStoreField, JSONField, RangeField
2527
from .fields import DjangoListField, DjangoConnectionField
@@ -48,7 +50,7 @@ def get_choices(choices):
4850
while name in converted_names:
4951
name += "_" + str(len(converted_names))
5052
converted_names.append(name)
51-
description = str(help_text) # TODO: translatable description: https://github.com/graphql-python/graphql-core-next/issues/58
53+
description = help_text
5254
yield name, value, description
5355

5456

@@ -245,3 +247,8 @@ def convert_posgres_range_to_string(field, registry=None):
245247
if not isinstance(inner_type, (List, NonNull)):
246248
inner_type = type(inner_type)
247249
return List(inner_type, description=field.help_text, required=not field.null)
250+
251+
252+
# Register Django lazy()-wrapped values as GraphQL description/help_text.
253+
# This is needed for using lazy translations, see https://github.com/graphql-python/graphql-core-next/issues/58.
254+
register_description(Promise)

0 commit comments

Comments
 (0)