1515import graphql .language .Node ;
1616import graphql .language .ObjectTypeDefinition ;
1717import graphql .language .ObjectTypeExtensionDefinition ;
18- import graphql .language .StringValue ;
1918import graphql .language .Type ;
2019import graphql .language .TypeDefinition ;
2120import graphql .language .TypeName ;
2221import graphql .language .UnionTypeDefinition ;
2322import graphql .schema .idl .errors .DirectiveIllegalLocationError ;
24- import graphql .schema .idl .errors .InvalidDeprecationDirectiveError ;
2523import graphql .schema .idl .errors .MissingInterfaceTypeError ;
2624import graphql .schema .idl .errors .MissingScalarImplementationError ;
2725import graphql .schema .idl .errors .MissingTypeError ;
4341import java .util .function .Consumer ;
4442import java .util .function .Function ;
4543import java .util .function .Predicate ;
46- import java .util .function .Supplier ;
4744
48- import static graphql .introspection .Introspection .DirectiveLocation .ENUM_VALUE ;
49- import static graphql .introspection .Introspection .DirectiveLocation .FIELD_DEFINITION ;
5045import static graphql .introspection .Introspection .DirectiveLocation .INPUT_FIELD_DEFINITION ;
5146import static java .util .stream .Collectors .toList ;
5247
@@ -219,8 +214,6 @@ private void checkObjTypeFields(List<GraphQLError> errors, ObjectTypeDefinition
219214 (directiveName , directive ) -> new NonUniqueDirectiveError (typeDefinition , fld , directiveName )));
220215
221216 fieldDefinitions .forEach (fld -> fld .getDirectives ().forEach (directive -> {
222- checkDeprecatedDirective (errors , directive , FIELD_DEFINITION ,
223- () -> new InvalidDeprecationDirectiveError (typeDefinition , fld ));
224217
225218 checkNamedUniqueness (errors , directive .getArguments (), Argument ::getName ,
226219 (argumentName , argument ) -> new NonUniqueArgumentError (typeDefinition , fld , argumentName ));
@@ -241,14 +234,9 @@ private void checkInterfaceFields(List<GraphQLError> errors, InterfaceTypeDefini
241234 fieldDefinitions .forEach (fld -> checkNamedUniqueness (errors , fld .getDirectives (), Directive ::getName ,
242235 (directiveName , directive ) -> new NonUniqueDirectiveError (interfaceType , fld , directiveName )));
243236
244- fieldDefinitions .forEach (fld -> fld .getDirectives ().forEach (directive -> {
245- checkDeprecatedDirective (errors , directive , FIELD_DEFINITION ,
246- () -> new InvalidDeprecationDirectiveError (interfaceType , fld ));
247-
248- checkNamedUniqueness (errors , directive .getArguments (), Argument ::getName ,
249- (argumentName , argument ) -> new NonUniqueArgumentError (interfaceType , fld , argumentName ));
250-
251- }));
237+ fieldDefinitions .forEach (fld -> fld .getDirectives ().forEach (directive ->
238+ checkNamedUniqueness (errors , directive .getArguments (), Argument ::getName ,
239+ (argumentName , argument ) -> new NonUniqueArgumentError (interfaceType , fld , argumentName ))));
252240 }
253241
254242 private void checkEnumValues (List <GraphQLError > errors , EnumTypeDefinition enumType , List <EnumValueDefinition > enumValueDefinitions ) {
@@ -265,8 +253,6 @@ private void checkEnumValues(List<GraphQLError> errors, EnumTypeDefinition enumT
265253 });
266254
267255 enumValueDefinitions .forEach (enumValue -> enumValue .getDirectives ().forEach (directive -> {
268- checkDeprecatedDirective (errors , directive , ENUM_VALUE ,
269- () -> new InvalidDeprecationDirectiveError (enumType , enumValue ));
270256
271257 BiFunction <String , Argument , NonUniqueArgumentError > errorFunction = (argumentName , argument ) -> new NonUniqueArgumentError (enumType , enumValue , argumentName );
272258 checkNamedUniqueness (errors , directive .getArguments (), Argument ::getName , errorFunction );
@@ -290,53 +276,9 @@ private void checkInputValues(List<GraphQLError> errors, InputObjectTypeDefiniti
290276 inputValueDefinitions .forEach (inputValueDef -> checkNamedUniqueness (errors , inputValueDef .getDirectives (), Directive ::getName ,
291277 (directiveName , directive ) -> new NonUniqueDirectiveError (inputType , inputValueDef , directiveName )));
292278
293- inputValueDefinitions .forEach (inputValueDef -> inputValueDef .getDirectives ().forEach (directive -> {
294- checkDeprecatedDirective (errors , directive , directiveLocation ,
295- () -> new InvalidDeprecationDirectiveError (inputType , inputValueDef ));
296-
297- checkNamedUniqueness (errors , directive .getArguments (), Argument ::getName ,
298- (argumentName , argument ) -> new NonUniqueArgumentError (inputType , inputValueDef , argumentName ));
299- }));
300- }
301-
302-
303- static Set <Introspection .DirectiveLocation > DEPRECATED_ALLOWED_LOCATIONS = new LinkedHashSet <>();
304-
305- static {
306- DEPRECATED_ALLOWED_LOCATIONS .add (FIELD_DEFINITION );
307- DEPRECATED_ALLOWED_LOCATIONS .add (ENUM_VALUE );
308- }
309-
310- /**
311- * A special check for the magic @deprecated directive
312- *
313- * @param errors the list of errors
314- * @param directive the directive to check
315- * @param errorSupplier the error supplier function
316- */
317- static void checkDeprecatedDirective (List <GraphQLError > errors , Directive directive , Introspection .DirectiveLocation actualLocation , Supplier <InvalidDeprecationDirectiveError > errorSupplier ) {
318- if ("deprecated" .equals (directive .getName ())) {
319- boolean ok = false ;
320- // it can have zero args
321- List <Argument > arguments = directive .getArguments ();
322- if (arguments .size () == 0 ) {
323- ok = true ;
324- }
325- // but if has more than it must have 1 called "reason" of type StringValue
326- else if (arguments .size () == 1 ) {
327- Argument arg = arguments .get (0 );
328- if (("reason" .equals (arg .getName ()) && arg .getValue () instanceof StringValue )) {
329- ok = true ;
330- }
331- }
332- if (ok && !DEPRECATED_ALLOWED_LOCATIONS .contains (actualLocation )) {
333- ok = false ;
334- }
335- // not valid
336- if (!ok ) {
337- errors .add (errorSupplier .get ());
338- }
339- }
279+ inputValueDefinitions .forEach (inputValueDef -> inputValueDef .getDirectives ().forEach (directive ->
280+ checkNamedUniqueness (errors , directive .getArguments (), Argument ::getName ,
281+ (argumentName , argument ) -> new NonUniqueArgumentError (inputType , inputValueDef , argumentName ))));
340282 }
341283
342284 /**
0 commit comments