Skip to content

Commit

Permalink
Fix that generated schemas could contain empty descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorJohn committed Jun 8, 2020
1 parent d9c187f commit c9766a8
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 61 deletions.
13 changes: 6 additions & 7 deletions graphene_django/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions graphene_django/filter/tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,6 @@ class Query(ObjectType):
}
type PetType implements Node {
\"""\"""
age: Int!
\"""The ID of the object\"""
Expand Down Expand Up @@ -915,7 +914,6 @@ class Query(ObjectType):
}
type PetType implements Node {
\"""\"""
age: Int!
\"""The ID of the object\"""
Expand Down
4 changes: 1 addition & 3 deletions graphene_django/filter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion graphene_django/forms/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 0 additions & 48 deletions graphene_django/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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!
}
Expand Down Expand Up @@ -513,13 +486,8 @@ class Query(ObjectType):
}
type Pet {
\"""\"""
id: ID!
\"""\"""
kind: String!
\"""\"""
cuteness: Int!
}
"""
Expand All @@ -543,13 +511,8 @@ class Query(ObjectType):
}
type Pet {
\"""\"""
id: ID!
\"""\"""
kind: PetModelKind!
\"""\"""
cuteness: Int!
}
Expand Down Expand Up @@ -582,13 +545,8 @@ class Query(ObjectType):
}
type Pet {
\"""\"""
id: ID!
\"""\"""
kind: String!
\"""\"""
cuteness: Int!
}
"""
Expand Down Expand Up @@ -616,10 +574,7 @@ class Query(ObjectType):
}
type PetModelKind {
\"""\"""
id: ID!
\"""\"""
kind: TestsPetModelKindChoices!
}
Expand Down Expand Up @@ -658,10 +613,7 @@ class Query(ObjectType):
}
type PetModelKind {
\"""\"""
id: ID!
\"""\"""
kind: CustomEnumKind!
}
Expand Down

0 comments on commit c9766a8

Please sign in to comment.