mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-25 11:04:11 +03:00
Fix that generated schemas could contain empty descriptions (v3) (#984)
This commit is contained in:
parent
d9c187ffc2
commit
26c4c48abc
|
@ -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 convert_field_to_list_or_connection(field, registry=None):
|
|||
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
|
||||
|
|
|
@ -845,7 +845,6 @@ def test_integer_field_filter_type():
|
|||
}
|
||||
|
||||
type PetType implements Node {
|
||||
\"""\"""
|
||||
age: Int!
|
||||
|
||||
\"""The ID of the object\"""
|
||||
|
@ -915,7 +914,6 @@ def test_other_filter_types():
|
|||
}
|
||||
|
||||
type PetType implements Node {
|
||||
\"""\"""
|
||||
age: Int!
|
||||
|
||||
\"""The ID of the object\"""
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -9,7 +9,7 @@ from .forms import GlobalIDFormField, GlobalIDMultipleChoiceField
|
|||
|
||||
|
||||
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
|
||||
|
|
|
@ -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 TestDjangoObjectType:
|
|||
}
|
||||
|
||||
type Pet {
|
||||
\"""\"""
|
||||
id: ID!
|
||||
|
||||
\"""\"""
|
||||
kind: String!
|
||||
|
||||
\"""\"""
|
||||
cuteness: Int!
|
||||
}
|
||||
"""
|
||||
|
@ -543,13 +511,8 @@ class TestDjangoObjectType:
|
|||
}
|
||||
|
||||
type Pet {
|
||||
\"""\"""
|
||||
id: ID!
|
||||
|
||||
\"""\"""
|
||||
kind: PetModelKind!
|
||||
|
||||
\"""\"""
|
||||
cuteness: Int!
|
||||
}
|
||||
|
||||
|
@ -582,13 +545,8 @@ class TestDjangoObjectType:
|
|||
}
|
||||
|
||||
type Pet {
|
||||
\"""\"""
|
||||
id: ID!
|
||||
|
||||
\"""\"""
|
||||
kind: String!
|
||||
|
||||
\"""\"""
|
||||
cuteness: Int!
|
||||
}
|
||||
"""
|
||||
|
@ -616,10 +574,7 @@ class TestDjangoObjectType:
|
|||
}
|
||||
|
||||
type PetModelKind {
|
||||
\"""\"""
|
||||
id: ID!
|
||||
|
||||
\"""\"""
|
||||
kind: TestsPetModelKindChoices!
|
||||
}
|
||||
|
||||
|
@ -658,10 +613,7 @@ class TestDjangoObjectType:
|
|||
}
|
||||
|
||||
type PetModelKind {
|
||||
\"""\"""
|
||||
id: ID!
|
||||
|
||||
\"""\"""
|
||||
kind: CustomEnumKind!
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user