Skip to content

Commit 7f631d2

Browse files
committed
Address review comments
1 parent f8e8f90 commit 7f631d2

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/type/scalars.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ const MAX_INT = 2147483647;
2222
const MIN_INT = -2147483648;
2323

2424
function serializeInt(value: mixed): number {
25-
let num = value;
25+
if (typeof value === 'boolean') {
26+
return value ? 1 : 0;
27+
}
28+
29+
const num = value;
2630
if (typeof value === 'string' && value !== '') {
2731
num = Number(value);
28-
} else if (typeof value === 'boolean') {
29-
return value ? 1 : 0;
3032
}
3133

3234
if (!isInteger(num)) {
@@ -75,13 +77,14 @@ export const GraphQLInt = new GraphQLScalarType({
7577
});
7678

7779
function serializeFloat(value: mixed): number {
80+
if (typeof value === 'boolean') {
81+
return value ? 1 : 0;
82+
}
83+
7884
let num = value;
7985
if (typeof value === 'string' && value !== '') {
8086
num = Number(value);
81-
} else if (typeof value === 'boolean') {
82-
return value ? 1 : 0;
8387
}
84-
8588
if (!isFinite(num)) {
8689
throw new TypeError(
8790
`Float cannot represent non numeric value: ${inspect(value)}`,

0 commit comments

Comments
 (0)