Skip to content

Commit 373aeca

Browse files
authored
Merge branch 'master' into update-enum-tests
2 parents 4f3bd94 + 2692232 commit 373aeca

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,20 @@ from graphql.execution.execute import execute
114114
execute(schema, ast, executor=SyncExecutor())
115115
```
116116

117+
### Development
118+
119+
Install development and test dependencies:
120+
121+
```sh
122+
pip install -e ".[test]"
123+
```
124+
125+
Run test suite:
126+
127+
```sh
128+
pytest
129+
```
130+
117131
## Main Contributors
118132

119133
* [@syrusakbary](https://github.com/syrusakbary/)

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
@@ -142,6 +142,23 @@ def test_defines_an_enum_type_with_a_value_of_none():
142142
assert value.deprecation_reason is None
143143
assert value.value is None
144144

145+
146+
def test_defines_an_object_type_with_deprecated_field():
147+
TypeWithDeprecatedField = GraphQLObjectType('foo', fields={
148+
'bar': GraphQLField(
149+
type=GraphQLString,
150+
deprecation_reason='A terrible reason'
151+
),
152+
})
153+
154+
field = TypeWithDeprecatedField.fields['bar']
155+
assert field.type == GraphQLString
156+
assert field.description is None
157+
assert field.deprecation_reason == 'A terrible reason'
158+
assert field.is_deprecated is True
159+
# assert field.name == 'bar'
160+
assert field.args == OrderedDict()
161+
145162

146163
def test_includes_nested_input_objects_in_the_map():
147164
NestedInputObject = GraphQLInputObjectType(

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)