@@ -55,18 +55,18 @@ private static Temporal convertEpochSecondsToTemporal(long epochSeconds) {
5555 }
5656
5757 static {
58- Coercing <TemporalAccessor , String > coercing = new Coercing <>() {
58+ Coercing <TemporalAccessor , Long > coercing = new Coercing <>() {
5959 @ Override
60- public String serialize (Object input , GraphQLContext graphQLContext , Locale locale ) throws CoercingSerializeException {
60+ public Long serialize (Object input , GraphQLContext graphQLContext , Locale locale ) throws CoercingSerializeException {
6161 try {
6262 if (input instanceof Number ) {
6363 Number number = (Number ) input ;
64- return Long . toString ( number .longValue () );
64+ return number .longValue ();
6565 }
6666 if (input instanceof String ) {
6767 String string = (String ) input ;
6868 if (string .matches ("\\ d+" )) {
69- return string ;
69+ return Long . parseLong ( string ) ;
7070 }
7171 throw new CoercingSerializeException (
7272 "Invalid seconds since epoch value : '" + string + "'. Expected a string containing only digits."
@@ -76,20 +76,20 @@ public String serialize(Object input, GraphQLContext graphQLContext, Locale loca
7676 TemporalAccessor temporalAccessor = (TemporalAccessor ) input ;
7777 if (temporalAccessor instanceof Instant ) {
7878 Instant instant = (Instant ) temporalAccessor ;
79- return Long . toString ( instant .getEpochSecond () );
79+ return instant .getEpochSecond ();
8080 } else if (temporalAccessor instanceof LocalDateTime ) {
8181 LocalDateTime localDateTime = (LocalDateTime ) temporalAccessor ;
82- return Long . toString ( localDateTime .toEpochSecond (ZoneOffset .UTC ) );
82+ return localDateTime .toEpochSecond (ZoneOffset .UTC );
8383 } else if (temporalAccessor instanceof ZonedDateTime ) {
8484 ZonedDateTime zonedDateTime = (ZonedDateTime ) temporalAccessor ;
85- return Long . toString ( zonedDateTime .toEpochSecond () );
85+ return zonedDateTime .toEpochSecond ();
8686 } else if (temporalAccessor instanceof OffsetDateTime ) {
8787 OffsetDateTime offsetDateTime = (OffsetDateTime ) temporalAccessor ;
88- return Long . toString ( offsetDateTime .toEpochSecond () );
88+ return offsetDateTime .toEpochSecond ();
8989 } else {
9090 try {
9191 Instant instant = Instant .from (temporalAccessor );
92- return Long . toString ( instant .getEpochSecond () );
92+ return instant .getEpochSecond ();
9393 } catch (Exception e ) {
9494 throw new CoercingSerializeException (
9595 "Unable to convert TemporalAccessor to seconds since epoch because of : '" + e .getMessage () + "'."
@@ -158,8 +158,8 @@ public TemporalAccessor parseLiteral(Value<?> input, CoercedVariables variables,
158158
159159 @ Override
160160 public Value <?> valueToLiteral (Object input , GraphQLContext graphQLContext , Locale locale ) {
161- String s = serialize (input , graphQLContext , locale );
162- return StringValue . newStringValue ( s ).build ();
161+ Long value = serialize (input , graphQLContext , locale );
162+ return IntValue . newIntValue ( java . math . BigInteger . valueOf ( value ) ).build ();
163163 }
164164
165165 };
@@ -168,7 +168,7 @@ public Value<?> valueToLiteral(Object input, GraphQLContext graphQLContext, Loca
168168 .name ("SecondsSinceEpoch" )
169169 .description ("Scalar that represents a point in time as seconds since the Unix epoch (Unix timestamp). " +
170170 "Accepts integers or strings containing integers as input values. " +
171- "Returns a string containing the number of seconds since epoch (January 1, 1970, 00:00:00 UTC)." )
171+ "Returns a Long representing the number of seconds since epoch (January 1, 1970, 00:00:00 UTC)." )
172172 .coercing (coercing )
173173 .build ();
174174 }
0 commit comments