Skip to content

Commit 73639da

Browse files
committed
Fix #244: Support for integer-valued ID fields
1 parent 4f9a66d commit 73639da

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/main/java/graphql/Scalars.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ public Object serialize(Object input) {
171171
if (input instanceof String) {
172172
return input;
173173
}
174+
if (input instanceof Integer) {
175+
return String.valueOf(input);
176+
}
174177

175178
return null;
176179
}
@@ -182,8 +185,13 @@ public Object parseValue(Object input) {
182185

183186
@Override
184187
public Object parseLiteral(Object input) {
185-
if (!(input instanceof StringValue)) return null;
186-
return ((StringValue) input).getValue();
188+
if (input instanceof StringValue) {
189+
return ((StringValue) input).getValue();
190+
}
191+
if (input instanceof IntValue) {
192+
return ((IntValue) input).getValue().toString();
193+
}
194+
return null;
187195
}
188196
});
189197

src/test/groovy/graphql/ScalarsTest.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class ScalarsTest extends Specification {
4343
where:
4444
literal | result
4545
new StringValue("5457486ABSBHS4w646") | "5457486ABSBHS4w646"
46+
new IntValue(BigInteger.ONE) | "1"
4647
}
4748

4849
@Unroll
@@ -54,6 +55,7 @@ class ScalarsTest extends Specification {
5455
where:
5556
value | result
5657
"5457486ABSBHS4w646" | "5457486ABSBHS4w646"
58+
1 | "1"
5759
null | null
5860
}
5961

0 commit comments

Comments
 (0)