1414 */
1515package graphql .annotations .processor .retrievers .fieldBuilders ;
1616
17- import graphql .Scalars ;
17+ import java .lang .annotation .Annotation ;
18+ import java .lang .reflect .AnnotatedElement ;
19+ import java .lang .reflect .Method ;
20+ import java .util .ArrayList ;
21+ import java .util .Arrays ;
22+ import java .util .List ;
23+ import java .util .stream .Collectors ;
24+
1825import graphql .annotations .annotationTypes .directives .activation .GraphQLDirectives ;
1926import graphql .annotations .processor .ProcessingElementsContainer ;
2027import graphql .annotations .processor .exceptions .GraphQLAnnotationsException ;
2431import graphql .schema .GraphQLScalarType ;
2532import graphql .schema .GraphQLType ;
2633
27- import java .lang .annotation .Annotation ;
28- import java .lang .reflect .AnnotatedElement ;
29- import java .lang .reflect .Method ;
30- import java .math .BigDecimal ;
31- import java .util .ArrayList ;
32- import java .util .Arrays ;
33- import java .util .List ;
34- import java .util .stream .Collectors ;
35-
36- import static graphql .Assert .assertShouldNeverHappen ;
37- import static graphql .scalar .CoercingUtil .isNumberIsh ;
3834import static graphql .schema .GraphQLDirective .newDirective ;
3935
4036
@@ -139,7 +135,7 @@ private void transformArgument(Annotation annotation, GraphQLDirective.Builder d
139135 Object value ;
140136 if ( graphQLArgument .getType () instanceof GraphQLScalarType )
141137 {
142- value = parseArgumentValue ( graphQLArgument , argumentValue );
138+ value = (( GraphQLScalarType ) graphQLArgument . getType ()). getCoercing (). parseValue ( argumentValue );
143139 }
144140 else
145141 {
@@ -165,7 +161,7 @@ private void transformArgument(String[] argumentValues, GraphQLDirective.Builder
165161 if (graphQLArgument .getType () instanceof GraphQLScalarType ) {
166162
167163 try {
168- Object value = parseArgumentValue ( graphQLArgument , argumentValue );
164+ Object value = (( GraphQLScalarType ) graphQLArgument . getType ()). getCoercing (). parseValue ( argumentValue );
169165 builder .value ( value );
170166 } catch (Exception e ) {
171167 throw new GraphQLAnnotationsException (COULD_NOT_PARSE_ARGUMENT_VALUE_TO_ARGUMENT_TYPE , e );
@@ -175,56 +171,4 @@ private void transformArgument(String[] argumentValues, GraphQLDirective.Builder
175171 }
176172 }));
177173 }
178-
179- private Object parseArgumentValue ( GraphQLArgument graphQLArgument , Object argumentValue )
180- {
181- GraphQLScalarType argumentType = (GraphQLScalarType ) graphQLArgument .getType ();
182- if ( argumentType .equals ( Scalars .GraphQLBoolean ) )
183- {
184- return castToBoolean ( argumentValue );
185- }
186- else
187- {
188- return argumentType .getCoercing ().parseValue ( argumentValue );
189- }
190- }
191-
192- private Boolean castToBoolean ( Object input )
193- {
194- if ( input instanceof Boolean )
195- {
196- return (Boolean ) input ;
197- }
198- else if ( input instanceof String )
199- {
200- String lStr = ( (String ) input ).toLowerCase ();
201- if ( lStr .equals ( "true" ) )
202- {
203- return true ;
204- }
205- if ( lStr .equals ( "false" ) )
206- {
207- return false ;
208- }
209- return null ;
210- }
211- else if ( isNumberIsh ( input ) )
212- {
213- BigDecimal value ;
214- try
215- {
216- value = new BigDecimal ( input .toString () );
217- }
218- catch ( NumberFormatException e )
219- {
220- // this should never happen because String is handled above
221- return assertShouldNeverHappen ();
222- }
223- return value .compareTo ( BigDecimal .ZERO ) != 0 ;
224- }
225- else
226- {
227- return null ;
228- }
229- }
230174}
0 commit comments