Skip to content

Commit 3ee3ee5

Browse files
committed
Support deprecation via introspection
Closes #35
1 parent ba3075c commit 3ee3ee5

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed

graphql/core/utils/build_client_schema.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ def build_enum_def(enum_introspection):
150150
name=enum_introspection['name'],
151151
description=enum_introspection['description'],
152152
values=OrderedDict([(value_introspection['name'],
153-
GraphQLEnumValue(description=value_introspection['description']))
153+
GraphQLEnumValue(description=value_introspection['description'],
154+
deprecation_reason=value_introspection['deprecationReason']))
154155
for value_introspection in enum_introspection['enumValues']
155156
])
156157
)
@@ -179,6 +180,7 @@ def build_field_def_map(type_introspection):
179180
type=get_output_type(f['type']),
180181
description=f['description'],
181182
resolver=no_execution,
183+
deprecation_reason=f['deprecationReason'],
182184
args=build_input_value_def_map(f['args'], GraphQLArgument)))
183185
for f in type_introspection['fields']
184186
])

graphql/core/utils/introspection_query.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
kind
2424
name
2525
description
26-
fields {
26+
fields(includeDeprecated: true) {
2727
name
2828
description
2929
args {
@@ -41,7 +41,7 @@
4141
interfaces {
4242
...TypeRef
4343
}
44-
enumValues {
44+
enumValues(includeDeprecated: true) {
4545
name
4646
description
4747
isDeprecated

tests/core_utils/test_build_client_schema.py

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,12 @@ def test_builds_a_schema_with_an_enum():
291291
assert isinstance(clientFoodEnum, GraphQLEnumType)
292292

293293
assert clientFoodEnum.get_values() == [
294-
GraphQLEnumValue(name='VEGETABLES', value='VEGETABLES', description='Foods that are vegetables.'),
295-
GraphQLEnumValue(name='FRUITS', value='FRUITS', description='Foods that are fruits.'),
296-
GraphQLEnumValue(name='OILS', value='OILS', description='Foods that are oils.'),
297-
GraphQLEnumValue(name='DAIRY', value='DAIRY', description='Foods that are dairy.'),
298-
GraphQLEnumValue(name='MEAT', value='MEAT', description='Foods that are meat.')
294+
GraphQLEnumValue(name='VEGETABLES', value='VEGETABLES', description='Foods that are vegetables.',
295+
deprecation_reason=None),
296+
GraphQLEnumValue(name='FRUITS', value='FRUITS', description='Foods that are fruits.', deprecation_reason=None),
297+
GraphQLEnumValue(name='OILS', value='OILS', description='Foods that are oils.', deprecation_reason=None),
298+
GraphQLEnumValue(name='DAIRY', value='DAIRY', description='Foods that are dairy.', deprecation_reason=None),
299+
GraphQLEnumValue(name='MEAT', value='MEAT', description='Foods that are meat.', deprecation_reason=None)
299300
]
300301

301302

@@ -381,6 +382,40 @@ def test_builds_a_schema_with_field_arguments_with_default_values():
381382
_test_schema(schema)
382383

383384

385+
def test_builds_a_schema_aware_of_deprecation():
386+
schema = GraphQLSchema(
387+
query=GraphQLObjectType(
388+
name='Simple',
389+
description='This is a simple type',
390+
fields=OrderedDict([
391+
('shinyString', GraphQLField(
392+
type=GraphQLString,
393+
description='This is a shiny string field'
394+
)),
395+
('deprecatedString', GraphQLField(
396+
type=GraphQLString,
397+
description='This is a deprecated string field',
398+
deprecation_reason='Use shinyString'
399+
)),
400+
('color', GraphQLField(
401+
type=GraphQLEnumType(
402+
name='Color',
403+
values=OrderedDict([
404+
('RED', GraphQLEnumValue(description='So rosy')),
405+
('GREEN', GraphQLEnumValue(description='So grassy')),
406+
('BLUE', GraphQLEnumValue(description='So calming')),
407+
('MAUVE', GraphQLEnumValue(description='So sickening',
408+
deprecation_reason='No longer in fashion')),
409+
])
410+
)
411+
))
412+
])
413+
)
414+
)
415+
416+
_test_schema(schema)
417+
418+
384419
def test_cannot_use_client_schema_for_general_execution():
385420
customScalar = GraphQLScalarType(
386421
name='CustomScalar',

0 commit comments

Comments
 (0)