44import graphql .GraphQLError ;
55import graphql .PublicSpi ;
66import graphql .Scalars ;
7- import graphql .schema .GraphQLArgument ;
8- import graphql .schema .GraphQLDirective ;
9- import graphql .schema .GraphQLFieldDefinition ;
10- import graphql .schema .GraphQLFieldsContainer ;
11- import graphql .schema .GraphQLInputObjectType ;
12- import graphql .schema .GraphQLInputType ;
13- import graphql .schema .GraphQLNamedInputType ;
14- import graphql .schema .GraphQLScalarType ;
15- import graphql .schema .GraphQLTypeUtil ;
7+ import graphql .schema .*;
168import graphql .validation .rules .ValidationEnvironment ;
179import graphql .validation .util .DirectivesAndTypeWalker ;
1810import graphql .validation .util .Util ;
11+
1912import java .lang .reflect .Array ;
2013import java .math .BigDecimal ;
2114import java .util .ArrayList ;
2518import java .util .LinkedHashMap ;
2619import java .util .List ;
2720import java .util .Map ;
21+
2822import static graphql .schema .GraphQLTypeUtil .isList ;
2923import static graphql .validation .rules .ValidationEnvironment .ValidatedElement .FIELD ;
3024import static graphql .validation .util .Util .mkMap ;
@@ -138,17 +132,17 @@ private List<GraphQLError> runValidationImpl(ValidationEnvironment validationEnv
138132 private List <GraphQLError > runConstraintOnDirectives (ValidationEnvironment validationEnvironment ) {
139133
140134 List <GraphQLError > errors = new ArrayList <>();
141- List <GraphQLDirective > directives = validationEnvironment .getDirectives ();
142- directives = Util .sort (directives , GraphQLDirective ::getName );
135+ List <GraphQLAppliedDirective > directives = validationEnvironment .getDirectives ();
136+ directives = Util .sort (directives , GraphQLAppliedDirective ::getName );
143137
144- for (GraphQLDirective directive : directives ) {
138+ for (GraphQLAppliedDirective directive : directives ) {
145139 // we get called for arguments and input field and field types which can have multiple directive constraints on them and hence no just for this one
146140 boolean isOurDirective = directive .getName ().equals (this .getName ());
147141 if (!isOurDirective ) {
148142 continue ;
149143 }
150144
151- validationEnvironment = validationEnvironment .transform (b -> b .context (GraphQLDirective .class , directive ));
145+ validationEnvironment = validationEnvironment .transform (b -> b .context (GraphQLAppliedDirective .class , directive ));
152146 //
153147 // now run the directive rule with this directive instance
154148 List <GraphQLError > ruleErrors = this .runConstrainOnPossibleListElements (validationEnvironment );
@@ -201,18 +195,15 @@ protected boolean isOneOfTheseTypes(GraphQLInputType inputType, Collection<Graph
201195 * @param argName the argument name
202196 * @return a non null value
203197 */
204- protected int getIntArg (GraphQLDirective directive , String argName ) {
205- GraphQLArgument argument = directive .getArgument (argName );
198+ protected int getIntArg (GraphQLAppliedDirective directive , String argName ) {
199+ GraphQLAppliedDirectiveArgument argument = directive .getArgument (argName );
206200 if (argument == null ) {
207201 return assertExpectedArgType (argName , "Int" );
208202 }
209203
210- Number value = GraphQLArgument . getArgumentValue ( argument );
204+ Number value = argument . getValue ( );
211205 if (value == null ) {
212- value = GraphQLArgument .getArgumentDefaultValue (argument );
213- if (value == null ) {
214- return assertExpectedArgType (argName , "Int" );
215- }
206+ return assertExpectedArgType (argName , "Int" );
216207 }
217208 return value .intValue ();
218209 }
@@ -224,17 +215,14 @@ protected int getIntArg(GraphQLDirective directive, String argName) {
224215 * @param argName the argument name
225216 * @return a non null value
226217 */
227- protected String getStrArg (GraphQLDirective directive , String argName ) {
228- GraphQLArgument argument = directive .getArgument (argName );
218+ protected String getStrArg (GraphQLAppliedDirective directive , String argName ) {
219+ GraphQLAppliedDirectiveArgument argument = directive .getArgument (argName );
229220 if (argument == null ) {
230221 return assertExpectedArgType (argName , "String" );
231222 }
232- String value = GraphQLArgument . getArgumentValue ( argument );
223+ String value = argument . getValue ( );
233224 if (value == null ) {
234- value = GraphQLArgument .getArgumentDefaultValue (argument );
235- if (value == null ) {
236- return assertExpectedArgType (argName , "String" );
237- }
225+ return assertExpectedArgType (argName , "String" );
238226 }
239227 return value ;
240228 }
@@ -246,17 +234,14 @@ protected String getStrArg(GraphQLDirective directive, String argName) {
246234 * @param argName the argument name
247235 * @return a non null value
248236 */
249- protected boolean getBoolArg (GraphQLDirective directive , String argName ) {
250- GraphQLArgument argument = directive .getArgument (argName );
237+ protected boolean getBoolArg (GraphQLAppliedDirective directive , String argName ) {
238+ GraphQLAppliedDirectiveArgument argument = directive .getArgument (argName );
251239 if (argument == null ) {
252240 return assertExpectedArgType (argName , "Boolean" );
253241 }
254- Object value = GraphQLArgument . getArgumentValue ( argument );
242+ Object value = argument . getValue ( );
255243 if (value == null ) {
256- value = GraphQLArgument .getArgumentDefaultValue (argument );
257- if (value == null ) {
258- return assertExpectedArgType (argName , "Boolean" );
259- }
244+ return assertExpectedArgType (argName , "Boolean" );
260245 }
261246 return Boolean .parseBoolean (String .valueOf (value ));
262247 }
@@ -268,14 +253,11 @@ protected boolean getBoolArg(GraphQLDirective directive, String argName) {
268253 * @param directive the directive to check
269254 * @return a non null value
270255 */
271- protected String getMessageTemplate (GraphQLDirective directive ) {
256+ protected String getMessageTemplate (GraphQLAppliedDirective directive ) {
272257 String msg = null ;
273- GraphQLArgument arg = directive .getArgument ("message" );
258+ GraphQLAppliedDirectiveArgument arg = directive .getArgument ("message" );
274259 if (arg != null ) {
275- msg = GraphQLArgument .getArgumentValue (arg );
276- if (msg == null ) {
277- msg = GraphQLArgument .getArgumentDefaultValue (arg );
278- }
260+ msg = arg .getValue ();
279261 }
280262 if (msg == null ) {
281263 msg = "graphql.validation." + getName () + ".message" ;
@@ -310,14 +292,14 @@ protected Map<String, Object> mkMessageParams(Object validatedValue, ValidationE
310292 * @param msgParams the map of parameters
311293 * @return a list of a single error
312294 */
313- protected List <GraphQLError > mkError (ValidationEnvironment validationEnvironment , GraphQLDirective directive , Map <String , Object > msgParams ) {
295+ protected List <GraphQLError > mkError (ValidationEnvironment validationEnvironment , GraphQLAppliedDirective directive , Map <String , Object > msgParams ) {
314296 String messageTemplate = getMessageTemplate (directive );
315297 GraphQLError error = validationEnvironment .getInterpolator ().interpolate (messageTemplate , msgParams , validationEnvironment );
316298 return singletonList (error );
317299 }
318300
319301 protected List <GraphQLError > mkError (ValidationEnvironment validationEnvironment , Object ... messageParameters ) {
320- GraphQLDirective directive = validationEnvironment .getContextObject (GraphQLDirective .class );
302+ GraphQLAppliedDirective directive = validationEnvironment .getContextObject (GraphQLAppliedDirective .class );
321303 String messageTemplate = getMessageTemplate (directive );
322304 Object validatedValue = validationEnvironment .getValidatedValue ();
323305 GraphQLError error = validationEnvironment .getInterpolator ().interpolate (messageTemplate , mkMessageParams (validatedValue , validationEnvironment , messageParameters ), validationEnvironment );
0 commit comments