Skip to content

Commit 26c4c48

Browse files
authored
Fix that generated schemas could contain empty descriptions (v3) (#984)
1 parent d9c187f commit 26c4c48

File tree

5 files changed

+7
-60
lines changed

5 files changed

+7
-60
lines changed

graphene_django/converter.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def convert_django_field_with_choices(
119119

120120

121121
def get_django_field_description(field):
122-
return None if field.help_text is None else str(field.help_text)
122+
return str(field.help_text) if field.help_text else None
123123

124124

125125
@singledispatch
@@ -230,11 +230,10 @@ def dynamic_type():
230230
if not _type:
231231
return
232232

233-
description = (
234-
field.help_text
235-
if isinstance(field, models.ManyToManyField)
236-
else field.field.help_text
237-
)
233+
if isinstance(field, models.ManyToManyField):
234+
description = get_django_field_description(field)
235+
else:
236+
description = get_django_field_description(field.field)
238237

239238
# If there is a connection, we should transform the field
240239
# into a DjangoConnectionField

graphene_django/filter/tests/test_fields.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,6 @@ class Query(ObjectType):
845845
}
846846
847847
type PetType implements Node {
848-
\"""\"""
849848
age: Int!
850849
851850
\"""The ID of the object\"""
@@ -915,7 +914,6 @@ class Query(ObjectType):
915914
}
916915
917916
type PetType implements Node {
918-
\"""\"""
919917
age: Int!
920918
921919
\"""The ID of the object\"""

graphene_django/filter/utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ def get_filtering_args_from_filterset(filterset_class, type):
3030
form_field = filter_field.field
3131

3232
field_type = convert_form_field(form_field).Argument()
33-
field_type.description = (
34-
None if filter_field.label is None else str(filter_field.label)
35-
)
33+
field_type.description = str(filter_field.label) if filter_field.label else None
3634
args[name] = field_type
3735

3836
return args

graphene_django/forms/converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
def get_form_field_description(field):
12-
return None if field.help_text is None else str(field.help_text)
12+
return str(field.help_text) if field.help_text else None
1313

1414

1515
@singledispatch

graphene_django/tests/test_types.py

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -121,26 +121,14 @@ def test_schema_representation():
121121
type Article implements Node {
122122
\"""The ID of the object\"""
123123
id: ID!
124-
125-
\"""\"""
126124
headline: String!
127-
128-
\"""\"""
129125
pubDate: Date!
130-
131-
\"""\"""
132126
pubDateTime: DateTime!
133-
134-
\"""\"""
135127
reporter: Reporter!
136-
137-
\"""\"""
138128
editor: Reporter!
139129
140130
\"""Language\"""
141131
lang: ArticleLang!
142-
143-
\"""\"""
144132
importance: ArticleImportance
145133
}
146134
@@ -184,28 +172,13 @@ def test_schema_representation():
184172
185173
\"""Reporter description\"""
186174
type Reporter {
187-
\"""\"""
188175
id: ID!
189-
190-
\"""\"""
191176
firstName: String!
192-
193-
\"""\"""
194177
lastName: String!
195-
196-
\"""\"""
197178
email: String!
198-
199-
\"""\"""
200179
pets: [Reporter!]!
201-
202-
\"""\"""
203180
aChoice: ReporterAChoice
204-
205-
\"""\"""
206181
reporterType: ReporterReporterType
207-
208-
\"""\"""
209182
articles(before: String = null, after: String = null, first: Int = null, last: Int = null): ArticleConnection!
210183
}
211184
@@ -513,13 +486,8 @@ class Query(ObjectType):
513486
}
514487
515488
type Pet {
516-
\"""\"""
517489
id: ID!
518-
519-
\"""\"""
520490
kind: String!
521-
522-
\"""\"""
523491
cuteness: Int!
524492
}
525493
"""
@@ -543,13 +511,8 @@ class Query(ObjectType):
543511
}
544512
545513
type Pet {
546-
\"""\"""
547514
id: ID!
548-
549-
\"""\"""
550515
kind: PetModelKind!
551-
552-
\"""\"""
553516
cuteness: Int!
554517
}
555518
@@ -582,13 +545,8 @@ class Query(ObjectType):
582545
}
583546
584547
type Pet {
585-
\"""\"""
586548
id: ID!
587-
588-
\"""\"""
589549
kind: String!
590-
591-
\"""\"""
592550
cuteness: Int!
593551
}
594552
"""
@@ -616,10 +574,7 @@ class Query(ObjectType):
616574
}
617575
618576
type PetModelKind {
619-
\"""\"""
620577
id: ID!
621-
622-
\"""\"""
623578
kind: TestsPetModelKindChoices!
624579
}
625580
@@ -658,10 +613,7 @@ class Query(ObjectType):
658613
}
659614
660615
type PetModelKind {
661-
\"""\"""
662616
id: ID!
663-
664-
\"""\"""
665617
kind: CustomEnumKind!
666618
}
667619

0 commit comments

Comments
 (0)