Skip to content

Commit 51a3bd5

Browse files
committed
Allow empty string as valid 'deprecation_reason'
Replicates graphql/graphql-js@43b7645
1 parent 0ef2251 commit 51a3bd5

File tree

5 files changed

+28
-12
lines changed

5 files changed

+28
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The current stable version 3.0.1 of GraphQL-core is up-to-date
1616
with GraphQL.js version 14.5.8.
1717

1818
All parts of the API are covered by an extensive test suite
19-
of currently 1991 unit tests.
19+
of currently 1992 unit tests.
2020

2121

2222
## Documentation

src/graphql/type/definition.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ def to_kwargs(self) -> Dict[str, Any]:
527527

528528
@property
529529
def is_deprecated(self) -> bool:
530-
return bool(self.deprecation_reason)
530+
return self.deprecation_reason is not None
531531

532532

533533
class GraphQLResolveInfo(NamedTuple):
@@ -1177,7 +1177,7 @@ def to_kwargs(self) -> Dict[str, Any]:
11771177

11781178
@property
11791179
def is_deprecated(self) -> bool:
1180-
return bool(self.deprecation_reason)
1180+
return self.deprecation_reason is not None
11811181

11821182

11831183
GraphQLInputFieldMap = Dict[str, "GraphQLInputField"]

src/graphql/utilities/schema_printer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def print_deprecated(field_or_enum_value: Union[GraphQLField, GraphQLEnumValue])
250250
return ""
251251
reason = field_or_enum_value.deprecation_reason
252252
reason_ast = ast_from_value(reason, GraphQLString)
253-
if not reason_ast or reason == "" or reason == DEFAULT_DEPRECATION_REASON:
253+
if not reason_ast or reason == DEFAULT_DEPRECATION_REASON:
254254
return " @deprecated"
255255
return f" @deprecated(reason: {print_ast(reason_ast)})"
256256

tests/type/test_definition.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -330,22 +330,23 @@ def does_not_mutate_passed_field_definitions():
330330
def defines_an_object_type_with_deprecated_field():
331331
TypeWithDeprecatedField = GraphQLObjectType(
332332
"foo",
333-
{"bar": GraphQLField(ScalarType, deprecation_reason="A terrible reason")},
333+
{
334+
"bar": GraphQLField(ScalarType, deprecation_reason="A terrible reason"),
335+
"baz": GraphQLField(ScalarType, deprecation_reason=""),
336+
},
334337
)
335338

336339
deprecated_field = TypeWithDeprecatedField.fields["bar"]
337340
assert deprecated_field == GraphQLField(
338341
ScalarType, deprecation_reason="A terrible reason"
339342
)
340-
assert deprecated_field.description is None
341-
assert deprecated_field.type is ScalarType
342-
assert deprecated_field.args == {}
343-
assert deprecated_field.resolve is None
344-
assert deprecated_field.subscribe is None
345343
assert deprecated_field.is_deprecated is True
346344
assert deprecated_field.deprecation_reason == "A terrible reason"
347-
assert deprecated_field.extensions is None
348-
assert deprecated_field.ast_node is None
345+
346+
deprecated_field = TypeWithDeprecatedField.fields["baz"]
347+
assert deprecated_field == GraphQLField(ScalarType, deprecation_reason="")
348+
assert deprecated_field.is_deprecated is True
349+
assert deprecated_field.deprecation_reason == ""
349350

350351
def accepts_an_object_type_with_output_type_as_field():
351352
# this is a shortcut syntax for simple fields

tests/utilities/test_build_client_schema.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,21 @@ def builds_a_schema_aware_of_deprecation():
478478

479479
assert cycle_introspection(sdl) == sdl
480480

481+
def builds_a_schema_with_empty_deprecation_reasons():
482+
sdl = dedent(
483+
"""
484+
type Query {
485+
someField: String @deprecated(reason: "")
486+
}
487+
488+
enum SomeEnum {
489+
SOME_VALUE @deprecated(reason: "")
490+
}
491+
"""
492+
)
493+
494+
assert cycle_introspection(sdl) == sdl
495+
481496
def can_use_client_schema_for_limited_execution():
482497
schema = build_schema(
483498
"""

0 commit comments

Comments
 (0)