Skip to content

Fix that generated schemas could contain empty descriptions (v3) #984

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions graphene_django/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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