Skip to content

Commit

Permalink
Merge pull request #113 from Macroz/floatfix
Browse files Browse the repository at this point in the history
Support parsing IntValue literals into GraphQLFloat
  • Loading branch information
andimarek committed Apr 2, 2016
2 parents 4a908db + f5a5fe4 commit 018bd2e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/main/java/graphql/Scalars.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,13 @@ public Object parseValue(Object input) {

@Override
public Object parseLiteral(Object input) {
return ((FloatValue) input).getValue().doubleValue();
if (input instanceof IntValue) {
return ((IntValue) input).getValue().doubleValue();
} else if (input instanceof FloatValue) {
return ((FloatValue) input).getValue().doubleValue();
} else {
return null;
}
}
});

Expand Down
6 changes: 4 additions & 2 deletions src/test/groovy/graphql/ScalarsTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ class ScalarsTest extends Specification {
Scalars.GraphQLFloat.getCoercing().parseLiteral(literal) == result

where:
literal | result
new FloatValue(42.3) | 42.3d
literal | result
new FloatValue(42.3) | 42.3d
new IntValue(42) | 42.0d
new StringValue("foo") | null
}

@Unroll
Expand Down

0 comments on commit 018bd2e

Please sign in to comment.