Skip to content

Commit 235a24e

Browse files
committed
Added support for deprecated fields using deprecation_reason. Fixed #93
1 parent 6a38024 commit 235a24e

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

graphene/core/types/field.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Field(NamedType, OrderedType):
1818

1919
def __init__(
2020
self, type, description=None, args=None, name=None, resolver=None,
21-
required=False, default=None, *args_list, **kwargs):
21+
required=False, default=None, deprecation_reason=None, *args_list, **kwargs):
2222
_creation_counter = kwargs.pop('_creation_counter', None)
2323
if isinstance(name, (Argument, ArgumentType)):
2424
kwargs['name'] = name
@@ -29,6 +29,7 @@ def __init__(
2929
self.required = required
3030
self.type = type
3131
self.description = description
32+
self.deprecation_reason = deprecation_reason
3233
args = OrderedDict(args or {}, **kwargs)
3334
self.arguments = ArgumentsGroup(*args_list, **args)
3435
self.object_type = None
@@ -103,6 +104,7 @@ def wrapped_func(instance, args, info):
103104
assert type, 'Internal type for field %s is None' % str(self)
104105
return GraphQLField(type, args=schema.T(arguments),
105106
resolver=self.decorate_resolver(resolver),
107+
deprecation_reason=self.deprecation_reason,
106108
description=description,)
107109

108110
def __repr__(self):

graphene/core/types/tests/test_field.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,17 @@ def resolve_hello(self, args, info):
166166
'hello': 'Hello Serkan'
167167
}
168168
assert result.data == expected
169+
170+
171+
def test_field_internal_type_deprecated():
172+
deprecation_reason = 'No more used'
173+
field = Field(String(), description='My argument',
174+
deprecation_reason=deprecation_reason)
175+
176+
class Query(ObjectType):
177+
my_field = field
178+
schema = Schema(query=Query)
179+
180+
type = schema.T(field)
181+
assert isinstance(type, GraphQLField)
182+
assert type.deprecation_reason == deprecation_reason

0 commit comments

Comments
 (0)