3535
3636
3737public class DirectivesBuilder implements Builder <GraphQLDirective []> {
38+ public static final String NOT_FOUND_IN_DIRECTIVE_REGISTRY_ERROR = "No directive named %s is found in the directive registry" ;
39+ public static final String TOO_MUCH_ARGUMENTS_ERROR = "Directive '%s' is supplied with more argument values than it supports" ;
40+ public static final String DIRECTIVE_ARGUMENT_TYPE_MUST_BE_A_SCALAR = "Directive argument type must be a scalar!" ;
41+ public static final String COULD_NOT_PARSE_ARGUMENT_VALUE_TO_ARGUMENT_TYPE = "Could not parse argument value to argument type" ;
3842 private AnnotatedElement object ;
3943 private ProcessingElementsContainer container ;
4044
@@ -54,7 +58,7 @@ public GraphQLDirective[] build() {
5458 GraphQLDirective graphQLDirective = transformArgs (container .getDirectiveRegistry ().get (name ).getDirective (), annotation );
5559 graphQLDirectives .add (graphQLDirective );
5660 } else {
57- throw new GraphQLAnnotationsException (String .format ("No directive named %s is found in the directive registry" , name ), null );
61+ throw new GraphQLAnnotationsException (String .format (NOT_FOUND_IN_DIRECTIVE_REGISTRY_ERROR , name ), null );
5862 }
5963 });
6064
@@ -66,7 +70,7 @@ public GraphQLDirective[] build() {
6670 if (container .getDirectiveRegistry ().containsKey (x .name ())) {
6771 return transformArgs (container .getDirectiveRegistry ().get (x .name ()).getDirective (), x .argumentsValues ());
6872 } else {
69- throw new GraphQLAnnotationsException (String .format ("No directive named %s is found in the directive registry" , x .name ()), null );
73+ throw new GraphQLAnnotationsException (String .format (NOT_FOUND_IN_DIRECTIVE_REGISTRY_ERROR , x .name ()), null );
7074 }
7175 }
7276 ).collect (Collectors .toList ());
@@ -84,7 +88,7 @@ private GraphQLDirective transformArgs(GraphQLDirective graphQLDirective, Annota
8488 List <GraphQLArgument > arguments = graphQLDirective .getArguments ();
8589
8690 if (annotation .annotationType ().getDeclaredMethods ().length > arguments .size ()) {
87- throw new GraphQLAnnotationsException (String .format ("Directive '%s' is supplied with more argument values than it supports" , graphQLDirective .getName ()), null );
91+ throw new GraphQLAnnotationsException (String .format (TOO_MUCH_ARGUMENTS_ERROR , graphQLDirective .getName ()), null );
8892 }
8993
9094 for (int i = 0 ; i < annotation .annotationType ().getDeclaredMethods ().length ; i ++) {
@@ -105,7 +109,7 @@ private GraphQLDirective transformArgs(GraphQLDirective graphQLDirective, String
105109 List <GraphQLArgument > arguments = graphQLDirective .getArguments ();
106110
107111 if (argumentValues .length > arguments .size ()) {
108- throw new GraphQLAnnotationsException (String .format ("Directive '%s' is supplied with more argument values than it supports" , graphQLDirective .getName ()), null );
112+ throw new GraphQLAnnotationsException (String .format (TOO_MUCH_ARGUMENTS_ERROR , graphQLDirective .getName ()), null );
109113 }
110114
111115 for (int i = 0 ; i < argumentValues .length ; i ++) {
@@ -138,10 +142,10 @@ private void transformArgument(Annotation annotation, GraphQLDirective.Builder d
138142 }
139143 builder .value (value );
140144 } catch (Exception e ) {
141- throw new GraphQLAnnotationsException ("Could not parse argument value to argument type" , e );
145+ throw new GraphQLAnnotationsException (COULD_NOT_PARSE_ARGUMENT_VALUE_TO_ARGUMENT_TYPE , e );
142146 }
143147 } else {
144- throw new GraphQLAnnotationsException ("Directive argument type must be a scalar!" , null );
148+ throw new GraphQLAnnotationsException (DIRECTIVE_ARGUMENT_TYPE_MUST_BE_A_SCALAR , null );
145149 }
146150 }));
147151 }
@@ -159,10 +163,10 @@ private void transformArgument(String[] argumentValues, GraphQLDirective.Builder
159163 Object value = ((GraphQLScalarType ) graphQLArgument .getType ()).getCoercing ().parseValue (argumentValue );
160164 builder .value (value );
161165 } catch (Exception e ) {
162- throw new GraphQLAnnotationsException ("Could not parse argument value to argument type" , e );
166+ throw new GraphQLAnnotationsException (COULD_NOT_PARSE_ARGUMENT_VALUE_TO_ARGUMENT_TYPE , e );
163167 }
164168 } else {
165- throw new GraphQLAnnotationsException ("Directive argument type must be a scalar!" , null );
169+ throw new GraphQLAnnotationsException (DIRECTIVE_ARGUMENT_TYPE_MUST_BE_A_SCALAR , null );
166170 }
167171 }));
168172 }
0 commit comments