Skip to content

Commit 3414572

Browse files
committed
bugfix: float also accepts int input
1 parent 43d5f57 commit 3414572

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/main/java/graphql/Scalars.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,13 @@ public Object parseLiteral(Object input) {
6868

6969
public static GraphQLScalarType GraphQLFloat = new GraphQLScalarType("Float", "Built-in Float", new Coercing() {
7070
@Override
71-
public Object serialize(Object input) {
71+
public Float serialize(Object input) {
7272
if (input instanceof String) {
7373
return Float.parseFloat((String) input);
7474
} else if (input instanceof Float) {
75-
return input;
75+
return (Float) input;
76+
} else if (input instanceof Integer) {
77+
return (float) (Integer) input;
7678
} else {
7779
return null;
7880
}

src/test/groovy/graphql/ScalarsTest.groovy

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ScalarsTest extends Specification {
2727
value | result
2828
Boolean.FALSE | "false"
2929
"test" | "test"
30-
null| null
30+
null | null
3131
}
3232

3333

@@ -48,7 +48,7 @@ class ScalarsTest extends Specification {
4848
where:
4949
value | result
5050
"5457486ABSBHS4w646" | "5457486ABSBHS4w646"
51-
null | null
51+
null | null
5252
}
5353

5454
def "Long parse literal"() {
@@ -72,7 +72,7 @@ class ScalarsTest extends Specification {
7272
"42" | 42
7373
new Long(42345784398534785l) | 42345784398534785l
7474
new Integer(42) | 42
75-
null | null
75+
null | null
7676
}
7777

7878

@@ -95,7 +95,7 @@ class ScalarsTest extends Specification {
9595
value | result
9696
"42" | 42
9797
new Integer(42) | 42
98-
null | null
98+
null | null
9999
}
100100

101101
def "Float parse literal"() {
@@ -117,7 +117,8 @@ class ScalarsTest extends Specification {
117117
"42.3" | 42.3f
118118
"42.0" | 42.0f
119119
new Float(42.3) | 42.3f
120-
null | null
120+
10 | 10.0f
121+
null | null
121122
}
122123

123124
def "Boolean parse literal"() {
@@ -141,7 +142,7 @@ class ScalarsTest extends Specification {
141142
"true" | true
142143
0 | false
143144
1 | true
144-
null | null
145+
null | null
145146
}
146147

147148

0 commit comments

Comments
 (0)