Skip to content

Commit b69c935

Browse files
authored
Merge pull request #175 from jkimbo/add-is-deprecated
Add `is_deprecated` property to GraphQLField
2 parents b3a6bd0 + 6654cc9 commit b69c935

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

graphql/type/definition.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ def define_field_map(type, field_map):
195195

196196
for field_name, field in field_map.items():
197197
assert_valid_name(field_name)
198+
assert isinstance(field, GraphQLField), (
199+
'{}.{} must be an instance of GraphQLField.'.format(type, field_name)
200+
)
198201
field_args = getattr(field, 'args', None)
199202

200203
if field_args:
@@ -261,6 +264,10 @@ def __eq__(self, other):
261264
def __hash__(self):
262265
return id(self)
263266

267+
@property
268+
def is_deprecated(self):
269+
return bool(self.deprecation_reason)
270+
264271

265272
class GraphQLArgument(object):
266273
__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',

graphql/type/typemap.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from functools import reduce
33

44
from ..utils.type_comparators import is_equal_type, is_type_sub_type_of
5-
from .definition import (GraphQLArgument, GraphQLField,
5+
from .definition import (GraphQLArgument,
66
GraphQLInputObjectField, GraphQLInputObjectType,
77
GraphQLInterfaceType, GraphQLList, GraphQLNonNull,
88
GraphQLObjectType, GraphQLUnionType, is_input_type,
@@ -87,9 +87,6 @@ def reducer(cls, map, type):
8787
'{}.{} field type must be Input Type but got: {}.'.format(type, field_name, field.type)
8888
)
8989
else:
90-
assert isinstance(field, (GraphQLField, GraphQLField)), (
91-
'{}.{} must be an instance of GraphQLField.'.format(type, field_name)
92-
)
9390
assert is_output_type(field.type), (
9491
'{}.{} field type must be Output Type but got: {}.'.format(type, field_name, field.type)
9592
)

0 commit comments

Comments
 (0)