88 GraphQLInt , GraphQLInterfaceType , GraphQLList ,
99 GraphQLNonNull , GraphQLObjectType , GraphQLScalarType ,
1010 GraphQLSchema , GraphQLSkipDirective , GraphQLString ,
11- GraphQLUnionType )
11+ GraphQLUnionType , GraphQLDeprecatedDirective )
1212from ..type .introspection import (__Directive , __DirectiveLocation ,
1313 __EnumValue , __Field , __InputValue , __Schema ,
1414 __Type , __TypeKind )
1515from ..utils .value_from_ast import value_from_ast
16+ from ..execution .values import get_argument_values
1617
1718
1819def _build_wrapped_type (inner_type , input_type_ast ):
@@ -179,7 +180,8 @@ def make_field_def_map(definition):
179180 return OrderedDict (
180181 (f .name .value , GraphQLField (
181182 type = produce_type_def (f .type ),
182- args = make_input_values (f .arguments , GraphQLArgument )
183+ args = make_input_values (f .arguments , GraphQLArgument ),
184+ deprecation_reason = get_deprecation_reason (f .directives ),
183185 ))
184186 for f in definition .fields
185187 )
@@ -204,11 +206,11 @@ def make_interface_def(definition):
204206 )
205207
206208 def make_enum_def (definition ):
209+ values = OrderedDict ((v .name .value , GraphQLEnumValue (deprecation_reason = get_deprecation_reason (v .directives )))
210+ for v in definition .values )
207211 return GraphQLEnumType (
208212 name = definition .name .value ,
209- values = OrderedDict (
210- (v .name .value , GraphQLEnumValue ()) for v in definition .values
211- )
213+ values = values
212214 )
213215
214216 def make_union_def (definition ):
@@ -246,16 +248,20 @@ def make_input_object_def(definition):
246248 types = [type_def_named (definition .name .value ) for definition in type_defs ]
247249 directives = [get_directive (d ) for d in directive_defs ]
248250
249- # If skip and include were not explicitly declared, add them.
251+ # If specified directive were not explicitly declared, add them.
250252 find_skip_directive = (directive .name for directive in directives if directive .name == 'skip' )
251253 find_include_directive = (directive .name for directive in directives if directive .name == 'include' )
254+ find_deprecated_directive = (directive .name for directive in directives if directive .name == 'deprecated' )
252255
253256 if not next (find_skip_directive , None ):
254257 directives .append (GraphQLSkipDirective )
255258
256259 if not next (find_include_directive , None ):
257260 directives .append (GraphQLIncludeDirective )
258261
262+ if not next (find_deprecated_directive , None ):
263+ directives .append (GraphQLDeprecatedDirective )
264+
259265 schema_kwargs = {'query' : get_object_type (ast_map [query_type_name ])}
260266
261267 if mutation_type_name :
@@ -271,3 +277,15 @@ def make_input_object_def(definition):
271277 schema_kwargs ['types' ] = types
272278
273279 return GraphQLSchema (** schema_kwargs )
280+
281+
282+ def get_deprecation_reason (directives ):
283+ deprecated_ast = next ((directive for directive in directives
284+ if directive .name .value == GraphQLDeprecatedDirective .name ),
285+ None )
286+
287+ if deprecated_ast :
288+ args = get_argument_values (GraphQLDeprecatedDirective .args , deprecated_ast .arguments )
289+ return args ['reason' ]
290+ else :
291+ return None
0 commit comments