Skip to content

Commit 06379c7

Browse files
authored
fix: Cannot convert date value to AST (#278)
* fix: Cannot convert date value to AST * fix: update Java date/time tests * fix: update Java Instant coercing serialization * fix: add queryForBooksWithWhereCriteriaExpressionDateVariables test * fix: Instance coercing
1 parent e1421ca commit 06379c7

File tree

5 files changed

+143
-106
lines changed

5 files changed

+143
-106
lines changed

graphql-jpa-query-schema/src/main/java/com/introproventures/graphql/jpa/query/schema/JavaScalars.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,16 @@ public static JavaScalars register(Class<?> key, GraphQLScalarType value) {
151151
}
152152

153153
public static class GraphQLLocalDateTimeCoercing implements Coercing<Object, Object> {
154+
private static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
154155

155156
@Override
156157
public Object serialize(Object input) {
157158
if (input instanceof String) {
158159
return parseStringToLocalDateTime((String) input);
159160
} else if (input instanceof LocalDateTime) {
160-
return input;
161+
return ((LocalDateTime) input).format(formatter);
161162
}else if (input instanceof LocalDate) {
162-
return input;
163+
return ((LocalDate) input).format(formatter);
163164
} else if (input instanceof Long) {
164165
return parseLongToLocalDateTime((Long) input);
165166
} else if (input instanceof Integer) {
@@ -200,12 +201,14 @@ private LocalDateTime parseStringToLocalDateTime(String input) {
200201

201202
public static class GraphQLLocalDateCoercing implements Coercing<Object, Object> {
202203

204+
private static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
205+
203206
@Override
204207
public Object serialize(Object input) {
205208
if (input instanceof String) {
206209
return parseStringToLocalDate((String) input);
207210
} else if (input instanceof LocalDate) {
208-
return input;
211+
return ((LocalDate) input).format(formatter);
209212
} else if (input instanceof Long) {
210213
return parseLongToLocalDate((Long) input);
211214
} else if (input instanceof Integer) {
@@ -314,7 +317,7 @@ public Object serialize(Object input) {
314317
if (input instanceof String) {
315318
return parseStringToDate((String) input);
316319
} else if (input instanceof Date) {
317-
return input;
320+
return new SimpleDateFormat(dateFormatString).format(input);
318321
} else if (input instanceof Long) {
319322
return new Date(((Long) input).longValue());
320323
} else if (input instanceof Integer) {
@@ -358,7 +361,9 @@ public Object serialize(Object input) {
358361
if (input instanceof String) {
359362
return parseStringToInstant((String) input);
360363
} else if (input instanceof Instant) {
361-
return input;
364+
return input.toString();
365+
} else if (input instanceof Long) {
366+
return Instant.ofEpochMilli((Long) input);
362367
}
363368
return null;
364369
}

0 commit comments

Comments
 (0)