From c9766a8faed2b380e4166f322d4e6738bcc34b45 Mon Sep 17 00:00:00 2001 From: DoctorJohn Date: Mon, 8 Jun 2020 03:06:20 +0200 Subject: [PATCH] Fix that generated schemas could contain empty descriptions --- graphene_django/converter.py | 13 +++--- graphene_django/filter/tests/test_fields.py | 2 - graphene_django/filter/utils.py | 4 +- graphene_django/forms/converter.py | 2 +- graphene_django/tests/test_types.py | 48 --------------------- 5 files changed, 8 insertions(+), 61 deletions(-) diff --git a/graphene_django/converter.py b/graphene_django/converter.py index d8d37db7b..03452b7b6 100644 --- a/graphene_django/converter.py +++ b/graphene_django/converter.py @@ -98,7 +98,7 @@ def convert_choice_field_to_enum(field, name=None): def convert_django_field_with_choices( - field, registry=None, convert_choices_to_enum=True + field, registry=None, convert_choices_to_enum=True ): if registry is not None: converted = registry.get_converted_field(field) @@ -119,7 +119,7 @@ def convert_django_field_with_choices( def get_django_field_description(field): - return None if field.help_text is None else str(field.help_text) + return str(field.help_text) if field.help_text else None @singledispatch @@ -230,11 +230,10 @@ def dynamic_type(): if not _type: return - description = ( - field.help_text - if isinstance(field, models.ManyToManyField) - else field.field.help_text - ) + if isinstance(field, models.ManyToManyField): + description = get_django_field_description(field) + else: + description = get_django_field_description(field.field) # If there is a connection, we should transform the field # into a DjangoConnectionField diff --git a/graphene_django/filter/tests/test_fields.py b/graphene_django/filter/tests/test_fields.py index 59cc30b39..918a4d6e3 100644 --- a/graphene_django/filter/tests/test_fields.py +++ b/graphene_django/filter/tests/test_fields.py @@ -845,7 +845,6 @@ class Query(ObjectType): } type PetType implements Node { - \"""\""" age: Int! \"""The ID of the object\""" @@ -915,7 +914,6 @@ class Query(ObjectType): } type PetType implements Node { - \"""\""" age: Int! \"""The ID of the object\""" diff --git a/graphene_django/filter/utils.py b/graphene_django/filter/utils.py index 426bae28f..f234d6a70 100644 --- a/graphene_django/filter/utils.py +++ b/graphene_django/filter/utils.py @@ -30,9 +30,7 @@ def get_filtering_args_from_filterset(filterset_class, type): form_field = filter_field.field field_type = convert_form_field(form_field).Argument() - field_type.description = ( - None if filter_field.label is None else str(filter_field.label) - ) + field_type.description = str(filter_field.label) if filter_field.label else None args[name] = field_type return args diff --git a/graphene_django/forms/converter.py b/graphene_django/forms/converter.py index df3708f58..b64e4783b 100644 --- a/graphene_django/forms/converter.py +++ b/graphene_django/forms/converter.py @@ -9,7 +9,7 @@ def get_form_field_description(field): - return None if field.help_text is None else str(field.help_text) + return str(field.help_text) if field.help_text else None @singledispatch diff --git a/graphene_django/tests/test_types.py b/graphene_django/tests/test_types.py index 1986568c7..21ee6cab6 100644 --- a/graphene_django/tests/test_types.py +++ b/graphene_django/tests/test_types.py @@ -121,26 +121,14 @@ def test_schema_representation(): type Article implements Node { \"""The ID of the object\""" id: ID! - - \"""\""" headline: String! - - \"""\""" pubDate: Date! - - \"""\""" pubDateTime: DateTime! - - \"""\""" reporter: Reporter! - - \"""\""" editor: Reporter! \"""Language\""" lang: ArticleLang! - - \"""\""" importance: ArticleImportance } @@ -184,28 +172,13 @@ def test_schema_representation(): \"""Reporter description\""" type Reporter { - \"""\""" id: ID! - - \"""\""" firstName: String! - - \"""\""" lastName: String! - - \"""\""" email: String! - - \"""\""" pets: [Reporter!]! - - \"""\""" aChoice: ReporterAChoice - - \"""\""" reporterType: ReporterReporterType - - \"""\""" articles(before: String = null, after: String = null, first: Int = null, last: Int = null): ArticleConnection! } @@ -513,13 +486,8 @@ class Query(ObjectType): } type Pet { - \"""\""" id: ID! - - \"""\""" kind: String! - - \"""\""" cuteness: Int! } """ @@ -543,13 +511,8 @@ class Query(ObjectType): } type Pet { - \"""\""" id: ID! - - \"""\""" kind: PetModelKind! - - \"""\""" cuteness: Int! } @@ -582,13 +545,8 @@ class Query(ObjectType): } type Pet { - \"""\""" id: ID! - - \"""\""" kind: String! - - \"""\""" cuteness: Int! } """ @@ -616,10 +574,7 @@ class Query(ObjectType): } type PetModelKind { - \"""\""" id: ID! - - \"""\""" kind: TestsPetModelKindChoices! } @@ -658,10 +613,7 @@ class Query(ObjectType): } type PetModelKind { - \"""\""" id: ID! - - \"""\""" kind: CustomEnumKind! }