Skip to content

Commit 644dcce

Browse files
committed
Merge branch 'okorz001-allow-longs'
2 parents a5e011d + 9e59bda commit 644dcce

4 files changed

Lines changed: 22 additions & 13 deletions

File tree

src/main/java/graphql/Scalars.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import graphql.schema.Coercing;
99
import graphql.schema.GraphQLScalarType;
1010

11+
import java.math.BigInteger;
12+
1113
public class Scalars {
1214

1315

@@ -31,7 +33,8 @@ public Object parseValue(Object input) {
3133
@Override
3234
public Object parseLiteral(Object input) {
3335
if (!(input instanceof IntValue)) return null;
34-
return ((IntValue) input).getValue();
36+
BigInteger value = ((IntValue) input).getValue();
37+
return value.intValue();
3538
}
3639
});
3740

@@ -60,7 +63,10 @@ public Object parseLiteral(Object input) {
6063
if (input instanceof StringValue) {
6164
return Long.parseLong(((StringValue) input).getValue());
6265
} else if (input instanceof IntValue) {
63-
return ((IntValue) input).getValue();
66+
BigInteger value = ((IntValue) input).getValue();
67+
// Check if out of bounds.
68+
Long.parseLong(value.toString());
69+
return value.longValue();
6470
}
6571
return null;
6672
}

src/main/java/graphql/language/IntValue.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
package graphql.language;
22

33

4+
import java.math.BigInteger;
45
import java.util.ArrayList;
56
import java.util.List;
67

78
public class IntValue extends AbstractNode implements Value {
89

9-
private int value;
10+
private BigInteger value;
1011

11-
public IntValue(int value) {
12+
public IntValue(BigInteger value) {
1213
this.value = value;
1314
}
1415

15-
public int getValue() {
16+
public BigInteger getValue() {
1617
return value;
1718
}
1819

19-
public void setValue(int value) {
20+
public void setValue(BigInteger value) {
2021
this.value = value;
2122
}
2223

@@ -30,9 +31,9 @@ public boolean isEqualTo(Node o) {
3031
if (this == o) return true;
3132
if (o == null || getClass() != o.getClass()) return false;
3233

33-
IntValue intValue = (IntValue) o;
34+
IntValue that = (IntValue) o;
3435

35-
return value == intValue.value;
36+
return !(value != null ? !value.equals(that.value) : that.value != null);
3637

3738
}
3839

src/main/java/graphql/parser/GraphqlAntlrToLanguage.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.antlr.v4.runtime.ParserRuleContext;
99

1010
import java.math.BigDecimal;
11+
import java.math.BigInteger;
1112
import java.util.ArrayDeque;
1213
import java.util.Deque;
1314

@@ -321,7 +322,7 @@ public Void visitDirective(GraphqlParser.DirectiveContext ctx) {
321322

322323
private Value getValue(GraphqlParser.ValueWithVariableContext ctx) {
323324
if (ctx.IntValue() != null) {
324-
IntValue intValue = new IntValue(Integer.parseInt(ctx.IntValue().getText()));
325+
IntValue intValue = new IntValue(new BigInteger(ctx.IntValue().getText()));
325326
newNode(intValue, ctx);
326327
return intValue;
327328
} else if (ctx.FloatValue() != null) {
@@ -366,7 +367,7 @@ private Value getValue(GraphqlParser.ValueWithVariableContext ctx) {
366367

367368
private Value getValue(GraphqlParser.ValueContext ctx) {
368369
if (ctx.IntValue() != null) {
369-
IntValue intValue = new IntValue(Integer.parseInt(ctx.IntValue().getText()));
370+
IntValue intValue = new IntValue(new BigInteger(ctx.IntValue().getText()));
370371
newNode(intValue, ctx);
371372
return intValue;
372373
} else if (ctx.FloatValue() != null) {

src/test/groovy/graphql/ScalarsTest.groovy

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ class ScalarsTest extends Specification {
5656
Scalars.GraphQLLong.getCoercing().parseLiteral(literal) == result
5757

5858
where:
59-
literal | result
60-
new StringValue("42") | 42
61-
new IntValue(42) | 42
59+
literal | result
60+
new StringValue("42") | 42
61+
new IntValue(new BigInteger("42")) | 42
62+
new IntValue(new BigInteger("42345784398534785")) | 42345784398534785l
6263
}
6364

6465

0 commit comments

Comments
 (0)