14
14
*/
15
15
package graphql .annotations .processor .retrievers .fieldBuilders ;
16
16
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
+
18
25
import graphql .annotations .annotationTypes .directives .activation .GraphQLDirectives ;
19
26
import graphql .annotations .processor .ProcessingElementsContainer ;
20
27
import graphql .annotations .processor .exceptions .GraphQLAnnotationsException ;
24
31
import graphql .schema .GraphQLScalarType ;
25
32
import graphql .schema .GraphQLType ;
26
33
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 ;
38
34
import static graphql .schema .GraphQLDirective .newDirective ;
39
35
40
36
@@ -139,7 +135,7 @@ private void transformArgument(Annotation annotation, GraphQLDirective.Builder d
139
135
Object value ;
140
136
if ( graphQLArgument .getType () instanceof GraphQLScalarType )
141
137
{
142
- value = parseArgumentValue ( graphQLArgument , argumentValue );
138
+ value = (( GraphQLScalarType ) graphQLArgument . getType ()). getCoercing (). parseValue ( argumentValue );
143
139
}
144
140
else
145
141
{
@@ -165,7 +161,7 @@ private void transformArgument(String[] argumentValues, GraphQLDirective.Builder
165
161
if (graphQLArgument .getType () instanceof GraphQLScalarType ) {
166
162
167
163
try {
168
- Object value = parseArgumentValue ( graphQLArgument , argumentValue );
164
+ Object value = (( GraphQLScalarType ) graphQLArgument . getType ()). getCoercing (). parseValue ( argumentValue );
169
165
builder .value ( value );
170
166
} catch (Exception e ) {
171
167
throw new GraphQLAnnotationsException (COULD_NOT_PARSE_ARGUMENT_VALUE_TO_ARGUMENT_TYPE , e );
@@ -175,56 +171,4 @@ private void transformArgument(String[] argumentValues, GraphQLDirective.Builder
175
171
}
176
172
}));
177
173
}
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
- }
230
174
}
0 commit comments