File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,14 @@ describe('Type System: Scalar coercion', () => {
41
41
expect (
42
42
GraphQLInt . coerce ( 1e5 )
43
43
) . to . equal ( 100000 ) ;
44
+ // Bigger than 2^32, but still representable as an Int
45
+ expect (
46
+ GraphQLInt . coerce ( 9876504321 )
47
+ ) . to . equal ( 9876504321 ) ;
48
+ expect (
49
+ GraphQLInt . coerce ( - 9876504321 )
50
+ ) . to . equal ( - 9876504321 ) ;
51
+ // Too big to represent as an Int
44
52
expect (
45
53
GraphQLInt . coerce ( 1e100 )
46
54
) . to . equal ( null ) ;
Original file line number Diff line number Diff line change @@ -21,7 +21,10 @@ export var GraphQLInt = new GraphQLScalarType({
21
21
name : 'Int' ,
22
22
coerce ( value ) {
23
23
var num = + value ;
24
- return num === num && num <= MAX_INT && num >= MIN_INT ? num | 0 : null ;
24
+ if ( num === num && num <= MAX_INT && num >= MIN_INT ) {
25
+ return ( num < 0 ? Math . ceil : Math . floor ) ( num ) ;
26
+ }
27
+ return null ;
25
28
} ,
26
29
coerceLiteral ( ast ) {
27
30
if ( ast . kind === Kind . INT ) {
@@ -30,6 +33,7 @@ export var GraphQLInt = new GraphQLScalarType({
30
33
return num ;
31
34
}
32
35
}
36
+ return null ;
33
37
}
34
38
} ) ;
35
39
You can’t perform that action at this time.
0 commit comments