Skip to content

Add is_deprecated property to GraphQLField #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions graphql/type/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ def define_field_map(type, field_map):

for field_name, field in field_map.items():
assert_valid_name(field_name)
assert isinstance(field, GraphQLField), (
'{}.{} must be an instance of GraphQLField.'.format(type, field_name)
)
field_args = getattr(field, 'args', None)

if field_args:
Expand Down Expand Up @@ -261,6 +264,10 @@ def __eq__(self, other):
def __hash__(self):
return id(self)

@property
def is_deprecated(self):
return bool(self.deprecation_reason)


class GraphQLArgument(object):
__slots__ = 'type', 'default_value', 'description', 'out_name'
Expand Down
17 changes: 17 additions & 0 deletions graphql/type/tests/test_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,23 @@ def test_defines_a_subscription_schema():
# assert subscription.name == 'articleSubscribe'


def test_defines_an_object_type_with_deprecated_field():
TypeWithDeprecatedField = GraphQLObjectType('foo', fields={
'bar': GraphQLField(
type=GraphQLString,
deprecation_reason='A terrible reason'
),
})

field = TypeWithDeprecatedField.fields['bar']
assert field.type == GraphQLString
assert field.description is None
assert field.deprecation_reason == 'A terrible reason'
assert field.is_deprecated is True
# assert field.name == 'bar'
assert field.args == OrderedDict()


def test_includes_nested_input_objects_in_the_map():
NestedInputObject = GraphQLInputObjectType(
name='NestedInputObject',
Expand Down
5 changes: 1 addition & 4 deletions graphql/type/typemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from functools import reduce

from ..utils.type_comparators import is_equal_type, is_type_sub_type_of
from .definition import (GraphQLArgument, GraphQLField,
from .definition import (GraphQLArgument,
GraphQLInputObjectField, GraphQLInputObjectType,
GraphQLInterfaceType, GraphQLList, GraphQLNonNull,
GraphQLObjectType, GraphQLUnionType, is_input_type,
Expand Down Expand Up @@ -87,9 +87,6 @@ def reducer(cls, map, type):
'{}.{} field type must be Input Type but got: {}.'.format(type, field_name, field.type)
)
else:
assert isinstance(field, (GraphQLField, GraphQLField)), (
'{}.{} must be an instance of GraphQLField.'.format(type, field_name)
)
assert is_output_type(field.type), (
'{}.{} field type must be Output Type but got: {}.'.format(type, field_name, field.type)
)
Expand Down