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', () => {
4141 expect (
4242 GraphQLInt . coerce ( 1e5 )
4343 ) . 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
4452 expect (
4553 GraphQLInt . coerce ( 1e100 )
4654 ) . to . equal ( null ) ;
Original file line number Diff line number Diff line change @@ -21,7 +21,10 @@ export var GraphQLInt = new GraphQLScalarType({
2121 name : 'Int' ,
2222 coerce ( value ) {
2323 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 ;
2528 } ,
2629 coerceLiteral ( ast ) {
2730 if ( ast . kind === Kind . INT ) {
@@ -30,6 +33,7 @@ export var GraphQLInt = new GraphQLScalarType({
3033 return num ;
3134 }
3235 }
36+ return null ;
3337 }
3438} ) ;
3539
You can’t perform that action at this time.
0 commit comments