Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support parsing IntValue literals into GraphQLFloat #113

Merged
merged 1 commit into from
Apr 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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