66import graphql .execution .ValuesResolver ;
77import graphql .language .Value ;
88import graphql .schema .CoercingParseValueException ;
9+ import graphql .schema .GraphQLAppliedDirective ;
10+ import graphql .schema .GraphQLAppliedDirectiveArgument ;
911import graphql .schema .GraphQLArgument ;
1012import graphql .schema .GraphQLDirective ;
1113import graphql .schema .GraphQLInputType ;
1214import graphql .schema .GraphQLSchema ;
1315import graphql .schema .GraphQLSchemaElement ;
16+ import graphql .schema .GraphQLTypeUtil ;
1417import graphql .schema .GraphQLTypeVisitorStub ;
1518import graphql .schema .InputValueWithState ;
1619import graphql .util .TraversalControl ;
@@ -32,29 +35,56 @@ public TraversalControl visitGraphQLDirective(GraphQLDirective directive, Traver
3235 // if there is no parent it means it is just a directive definition and not an applied directive
3336 if (context .getParentNode () != null ) {
3437 for (GraphQLArgument graphQLArgument : directive .getArguments ()) {
35- checkArgument (directive , graphQLArgument , context );
38+ checkArgument (
39+ directive .getName (),
40+ graphQLArgument .getName (),
41+ graphQLArgument .getArgumentValue (),
42+ graphQLArgument .getType (),
43+ context
44+ );
3645 }
3746 }
3847 return TraversalControl .CONTINUE ;
3948 }
4049
41- private void checkArgument (GraphQLDirective directive , GraphQLArgument argument , TraverserContext <GraphQLSchemaElement > context ) {
42- if (!argument .hasSetValue ()) {
43- return ;
50+ @ Override
51+ public TraversalControl visitGraphQLAppliedDirective (GraphQLAppliedDirective directive , TraverserContext <GraphQLSchemaElement > context ) {
52+ // if there is no parent it means it is just a directive definition and not an applied directive
53+ if (context .getParentNode () != null ) {
54+ for (GraphQLAppliedDirectiveArgument graphQLArgument : directive .getArguments ()) {
55+ checkArgument (
56+ directive .getName (),
57+ graphQLArgument .getName (),
58+ graphQLArgument .getArgumentValue (),
59+ graphQLArgument .getType (),
60+ context
61+ );
62+ }
4463 }
64+ return TraversalControl .CONTINUE ;
65+ }
66+
67+ private void checkArgument (
68+ String directiveName ,
69+ String argumentName ,
70+ InputValueWithState argumentValue ,
71+ GraphQLInputType argumentType ,
72+ TraverserContext <GraphQLSchemaElement > context
73+ ) {
4574 GraphQLSchema schema = context .getVarFromParents (GraphQLSchema .class );
4675 SchemaValidationErrorCollector errorCollector = context .getVarFromParents (SchemaValidationErrorCollector .class );
47- InputValueWithState argumentValue = argument .getArgumentValue ();
4876 boolean invalid = false ;
4977 if (argumentValue .isLiteral () &&
50- !validationUtil .isValidLiteralValue ((Value <?>) argumentValue .getValue (), argument . getType () , schema , GraphQLContext .getDefault (), Locale .getDefault ())) {
78+ !validationUtil .isValidLiteralValue ((Value <?>) argumentValue .getValue (), argumentType , schema , GraphQLContext .getDefault (), Locale .getDefault ())) {
5179 invalid = true ;
5280 } else if (argumentValue .isExternal () &&
53- !isValidExternalValue (schema , argumentValue .getValue (), argument .getType (), GraphQLContext .getDefault (), Locale .getDefault ())) {
81+ !isValidExternalValue (schema , argumentValue .getValue (), argumentType , GraphQLContext .getDefault (), Locale .getDefault ())) {
82+ invalid = true ;
83+ } else if (argumentValue .isNotSet () && GraphQLTypeUtil .isNonNull (argumentType )) {
5484 invalid = true ;
5585 }
5686 if (invalid ) {
57- String message = format ("Invalid argument '%s' for applied directive of name '%s'" , argument . getName (), directive . getName () );
87+ String message = format ("Invalid argument '%s' for applied directive of name '%s'" , argumentName , directiveName );
5888 errorCollector .addError (new SchemaValidationError (SchemaValidationErrorType .InvalidAppliedDirectiveArgument , message ));
5989 }
6090 }
0 commit comments