Skip to content

Commit c4cb892

Browse files
committed
Add is_deprecated computed property
1 parent b3a6bd0 commit c4cb892

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

graphql/type/definition.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ def __eq__(self, other):
261261
def __hash__(self):
262262
return id(self)
263263

264+
@property
265+
def is_deprecated(self):
266+
return bool(self.deprecation_reason)
267+
264268

265269
class GraphQLArgument(object):
266270
__slots__ = 'type', 'default_value', 'description', 'out_name'

graphql/type/tests/test_definition.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,23 @@ def test_defines_a_subscription_schema():
118118
# assert subscription.name == 'articleSubscribe'
119119

120120

121+
def test_defines_an_object_type_with_deprecated_field():
122+
TypeWithDeprecatedField = GraphQLObjectType('foo', fields={
123+
'bar': GraphQLField(
124+
type=GraphQLString,
125+
deprecation_reason='A terrible reason'
126+
),
127+
})
128+
129+
field = TypeWithDeprecatedField.fields['bar']
130+
assert field.type == GraphQLString
131+
assert field.description is None
132+
assert field.deprecation_reason == 'A terrible reason'
133+
assert field.is_deprecated is True
134+
# assert field.name == 'bar'
135+
assert field.args == OrderedDict()
136+
137+
121138
def test_includes_nested_input_objects_in_the_map():
122139
NestedInputObject = GraphQLInputObjectType(
123140
name='NestedInputObject',

0 commit comments

Comments
 (0)