mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-25 19:14: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):
|
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
|
@singledispatch
|
||||||
|
@ -230,11 +230,10 @@ def convert_field_to_list_or_connection(field, registry=None):
|
||||||
if not _type:
|
if not _type:
|
||||||
return
|
return
|
||||||
|
|
||||||
description = (
|
if isinstance(field, models.ManyToManyField):
|
||||||
field.help_text
|
description = get_django_field_description(field)
|
||||||
if isinstance(field, models.ManyToManyField)
|
else:
|
||||||
else field.field.help_text
|
description = get_django_field_description(field.field)
|
||||||
)
|
|
||||||
|
|
||||||
# If there is a connection, we should transform the field
|
# If there is a connection, we should transform the field
|
||||||
# into a DjangoConnectionField
|
# into a DjangoConnectionField
|
||||||
|
|
|
@ -845,7 +845,6 @@ def test_integer_field_filter_type():
|
||||||
}
|
}
|
||||||
|
|
||||||
type PetType implements Node {
|
type PetType implements Node {
|
||||||
\"""\"""
|
|
||||||
age: Int!
|
age: Int!
|
||||||
|
|
||||||
\"""The ID of the object\"""
|
\"""The ID of the object\"""
|
||||||
|
@ -915,7 +914,6 @@ def test_other_filter_types():
|
||||||
}
|
}
|
||||||
|
|
||||||
type PetType implements Node {
|
type PetType implements Node {
|
||||||
\"""\"""
|
|
||||||
age: Int!
|
age: Int!
|
||||||
|
|
||||||
\"""The ID of the object\"""
|
\"""The ID of the object\"""
|
||||||
|
|
|
@ -30,9 +30,7 @@ def get_filtering_args_from_filterset(filterset_class, type):
|
||||||
form_field = filter_field.field
|
form_field = filter_field.field
|
||||||
|
|
||||||
field_type = convert_form_field(form_field).Argument()
|
field_type = convert_form_field(form_field).Argument()
|
||||||
field_type.description = (
|
field_type.description = str(filter_field.label) if filter_field.label else None
|
||||||
None if filter_field.label is None else str(filter_field.label)
|
|
||||||
)
|
|
||||||
args[name] = field_type
|
args[name] = field_type
|
||||||
|
|
||||||
return args
|
return args
|
||||||
|
|
|
@ -9,7 +9,7 @@ from .forms import GlobalIDFormField, GlobalIDMultipleChoiceField
|
||||||
|
|
||||||
|
|
||||||
def get_form_field_description(field):
|
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
|
@singledispatch
|
||||||
|
|
|
@ -121,26 +121,14 @@ def test_schema_representation():
|
||||||
type Article implements Node {
|
type Article implements Node {
|
||||||
\"""The ID of the object\"""
|
\"""The ID of the object\"""
|
||||||
id: ID!
|
id: ID!
|
||||||
|
|
||||||
\"""\"""
|
|
||||||
headline: String!
|
headline: String!
|
||||||
|
|
||||||
\"""\"""
|
|
||||||
pubDate: Date!
|
pubDate: Date!
|
||||||
|
|
||||||
\"""\"""
|
|
||||||
pubDateTime: DateTime!
|
pubDateTime: DateTime!
|
||||||
|
|
||||||
\"""\"""
|
|
||||||
reporter: Reporter!
|
reporter: Reporter!
|
||||||
|
|
||||||
\"""\"""
|
|
||||||
editor: Reporter!
|
editor: Reporter!
|
||||||
|
|
||||||
\"""Language\"""
|
\"""Language\"""
|
||||||
lang: ArticleLang!
|
lang: ArticleLang!
|
||||||
|
|
||||||
\"""\"""
|
|
||||||
importance: ArticleImportance
|
importance: ArticleImportance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,28 +172,13 @@ def test_schema_representation():
|
||||||
|
|
||||||
\"""Reporter description\"""
|
\"""Reporter description\"""
|
||||||
type Reporter {
|
type Reporter {
|
||||||
\"""\"""
|
|
||||||
id: ID!
|
id: ID!
|
||||||
|
|
||||||
\"""\"""
|
|
||||||
firstName: String!
|
firstName: String!
|
||||||
|
|
||||||
\"""\"""
|
|
||||||
lastName: String!
|
lastName: String!
|
||||||
|
|
||||||
\"""\"""
|
|
||||||
email: String!
|
email: String!
|
||||||
|
|
||||||
\"""\"""
|
|
||||||
pets: [Reporter!]!
|
pets: [Reporter!]!
|
||||||
|
|
||||||
\"""\"""
|
|
||||||
aChoice: ReporterAChoice
|
aChoice: ReporterAChoice
|
||||||
|
|
||||||
\"""\"""
|
|
||||||
reporterType: ReporterReporterType
|
reporterType: ReporterReporterType
|
||||||
|
|
||||||
\"""\"""
|
|
||||||
articles(before: String = null, after: String = null, first: Int = null, last: Int = null): ArticleConnection!
|
articles(before: String = null, after: String = null, first: Int = null, last: Int = null): ArticleConnection!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -513,13 +486,8 @@ class TestDjangoObjectType:
|
||||||
}
|
}
|
||||||
|
|
||||||
type Pet {
|
type Pet {
|
||||||
\"""\"""
|
|
||||||
id: ID!
|
id: ID!
|
||||||
|
|
||||||
\"""\"""
|
|
||||||
kind: String!
|
kind: String!
|
||||||
|
|
||||||
\"""\"""
|
|
||||||
cuteness: Int!
|
cuteness: Int!
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
@ -543,13 +511,8 @@ class TestDjangoObjectType:
|
||||||
}
|
}
|
||||||
|
|
||||||
type Pet {
|
type Pet {
|
||||||
\"""\"""
|
|
||||||
id: ID!
|
id: ID!
|
||||||
|
|
||||||
\"""\"""
|
|
||||||
kind: PetModelKind!
|
kind: PetModelKind!
|
||||||
|
|
||||||
\"""\"""
|
|
||||||
cuteness: Int!
|
cuteness: Int!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -582,13 +545,8 @@ class TestDjangoObjectType:
|
||||||
}
|
}
|
||||||
|
|
||||||
type Pet {
|
type Pet {
|
||||||
\"""\"""
|
|
||||||
id: ID!
|
id: ID!
|
||||||
|
|
||||||
\"""\"""
|
|
||||||
kind: String!
|
kind: String!
|
||||||
|
|
||||||
\"""\"""
|
|
||||||
cuteness: Int!
|
cuteness: Int!
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
@ -616,10 +574,7 @@ class TestDjangoObjectType:
|
||||||
}
|
}
|
||||||
|
|
||||||
type PetModelKind {
|
type PetModelKind {
|
||||||
\"""\"""
|
|
||||||
id: ID!
|
id: ID!
|
||||||
|
|
||||||
\"""\"""
|
|
||||||
kind: TestsPetModelKindChoices!
|
kind: TestsPetModelKindChoices!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -658,10 +613,7 @@ class TestDjangoObjectType:
|
||||||
}
|
}
|
||||||
|
|
||||||
type PetModelKind {
|
type PetModelKind {
|
||||||
\"""\"""
|
|
||||||
id: ID!
|
id: ID!
|
||||||
|
|
||||||
\"""\"""
|
|
||||||
kind: CustomEnumKind!
|
kind: CustomEnumKind!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user