40
40
41
41
/**
42
42
* Provides Registry to resolve GraphQL Query Java Scalar Types
43
- *
43
+ *
44
44
* @author Igor Dianov
45
45
*
46
46
*/
47
47
public class JavaScalars {
48
+
48
49
static final Logger log = LoggerFactory .getLogger (JavaScalars .class );
49
50
50
51
private static HashMap <Class <?>, GraphQLScalarType > scalarsRegistry = new HashMap <Class <?>, GraphQLScalarType >();
51
-
52
+
52
53
static {
53
54
scalarsRegistry .put (String .class , Scalars .GraphQLString );
54
55
@@ -66,33 +67,39 @@ public class JavaScalars {
66
67
67
68
scalarsRegistry .put (Long .class , Scalars .GraphQLLong );
68
69
scalarsRegistry .put (long .class , Scalars .GraphQLLong );
69
-
70
+
70
71
scalarsRegistry .put (Boolean .class , Scalars .GraphQLBoolean );
71
72
scalarsRegistry .put (boolean .class , Scalars .GraphQLBoolean );
72
73
74
+ scalarsRegistry .put (BigInteger .class , Scalars .GraphQLBigInteger );
75
+
76
+ scalarsRegistry .put (char .class , Scalars .GraphQLChar );
77
+ scalarsRegistry .put (Character .class , Scalars .GraphQLChar );
78
+
73
79
scalarsRegistry .put (BigDecimal .class , Scalars .GraphQLBigDecimal );
74
-
80
+
75
81
scalarsRegistry .put (LocalDateTime .class , new GraphQLScalarType ("LocalDateTime" , "LocalDateTime type" , new GraphQLLocalDateTimeCoercing ()));
76
82
scalarsRegistry .put (LocalDate .class , new GraphQLScalarType ("LocalDate" , "LocalDate type" , new GraphQLLocalDateCoercing ()));
77
83
scalarsRegistry .put (Date .class , new GraphQLScalarType ("Date" , "Date type" , new GraphQLDateCoercing ()));
78
84
scalarsRegistry .put (UUID .class , new GraphQLScalarType ("UUID" , "UUID type" , new GraphQLUUIDCoercing ()));
79
85
scalarsRegistry .put (Object .class , new GraphQLScalarType ("Object" , "Object type" , new GraphQLObjectCoercing ()));
80
86
}
81
-
87
+
82
88
public static GraphQLScalarType of (Class <?> key ) {
83
89
return scalarsRegistry .get (key );
84
90
}
85
91
86
92
public JavaScalars register (Class <?> key , GraphQLScalarType value ) {
87
93
Assert .assertNotNull (key , "key parameter cannot be null." );
88
94
Assert .assertNotNull (value , "value parameter cannot be null." );
89
-
95
+
90
96
scalarsRegistry .put (key , value );
91
-
97
+
92
98
return this ;
93
99
}
94
-
100
+
95
101
public static class GraphQLLocalDateTimeCoercing implements Coercing <Object , Object > {
102
+
96
103
@ Override
97
104
public Object serialize (Object input ) {
98
105
if (input instanceof String ) {
@@ -136,8 +143,9 @@ private LocalDateTime parseStringToLocalDateTime(String input) {
136
143
}
137
144
}
138
145
};
139
-
146
+
140
147
public static class GraphQLLocalDateCoercing implements Coercing <Object , Object > {
148
+
141
149
@ Override
142
150
public Object serialize (Object input ) {
143
151
if (input instanceof String ) {
@@ -229,14 +237,14 @@ public static class GraphQLUUIDCoercing implements Coercing<Object, Object> {
229
237
@ Override
230
238
public Object serialize (Object input ) {
231
239
if (input instanceof UUID ) {
232
- return input ;
240
+ return input ;
233
241
}
234
242
return null ;
235
243
}
236
244
237
245
@ Override
238
246
public Object parseValue (Object input ) {
239
- if (input instanceof String ) {
247
+ if (input instanceof String ) {
240
248
return parseStringToUUID ((String ) input );
241
249
}
242
250
return null ;
@@ -277,5 +285,5 @@ public Object parseLiteral(Object input) {
277
285
return input ;
278
286
}
279
287
};
280
-
288
+
281
289
}
0 commit comments