Skip to content

Commit f5a5fe4

Browse files
committed
Support parsing IntValue literals into GraphQLFloat
1 parent 4a908db commit f5a5fe4

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/main/java/graphql/Scalars.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,13 @@ public Object parseValue(Object input) {
100100

101101
@Override
102102
public Object parseLiteral(Object input) {
103-
return ((FloatValue) input).getValue().doubleValue();
103+
if (input instanceof IntValue) {
104+
return ((IntValue) input).getValue().doubleValue();
105+
} else if (input instanceof FloatValue) {
106+
return ((FloatValue) input).getValue().doubleValue();
107+
} else {
108+
return null;
109+
}
104110
}
105111
});
106112

src/test/groovy/graphql/ScalarsTest.groovy

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,10 @@ class ScalarsTest extends Specification {
115115
Scalars.GraphQLFloat.getCoercing().parseLiteral(literal) == result
116116

117117
where:
118-
literal | result
119-
new FloatValue(42.3) | 42.3d
118+
literal | result
119+
new FloatValue(42.3) | 42.3d
120+
new IntValue(42) | 42.0d
121+
new StringValue("foo") | null
120122
}
121123

122124
@Unroll

0 commit comments

Comments
 (0)