@@ -9,13 +9,17 @@ import { GraphQLError } from '../error/GraphQLError';
9
9
import type { GraphQLNamedType } from './definition' ;
10
10
import { GraphQLScalarType } from './definition' ;
11
11
12
- // As per the GraphQL Spec, Integers are only treated as valid when a valid
13
- // 32-bit signed integer, providing the broadest support across platforms.
14
- //
15
- // n.b. JavaScript's integers are safe between -(2^53 - 1) and 2^53 - 1 because
16
- // they are internally represented as IEEE 754 doubles.
17
- const MAX_INT = 2147483647 ;
18
- const MIN_INT = - 2147483648 ;
12
+ /**
13
+ * Maximum possible Int value as per GraphQL Spec (32-bit signed integer).
14
+ * n.b. This differs from JavaScript's numbers that are IEEE 754 doubles safe up-to 2^53 - 1
15
+ * */
16
+ export const GRAPHQL_MAX_INT = 2147483647 ;
17
+
18
+ /**
19
+ * Minimum possible Int value as per GraphQL Spec (32-bit signed integer).
20
+ * n.b. This differs from JavaScript's numbers that are IEEE 754 doubles safe starting at -(2^53 - 1)
21
+ * */
22
+ export const GRAPHQL_MIN_INT = - 2147483648 ;
19
23
20
24
export const GraphQLInt = new GraphQLScalarType < number > ( {
21
25
name : 'Int' ,
@@ -39,7 +43,7 @@ export const GraphQLInt = new GraphQLScalarType<number>({
39
43
`Int cannot represent non-integer value: ${ inspect ( coercedValue ) } ` ,
40
44
) ;
41
45
}
42
- if ( num > MAX_INT || num < MIN_INT ) {
46
+ if ( num > GRAPHQL_MAX_INT || num < GRAPHQL_MIN_INT ) {
43
47
throw new GraphQLError (
44
48
'Int cannot represent non 32-bit signed integer value: ' +
45
49
inspect ( coercedValue ) ,
@@ -54,7 +58,7 @@ export const GraphQLInt = new GraphQLScalarType<number>({
54
58
`Int cannot represent non-integer value: ${ inspect ( inputValue ) } ` ,
55
59
) ;
56
60
}
57
- if ( inputValue > MAX_INT || inputValue < MIN_INT ) {
61
+ if ( inputValue > GRAPHQL_MAX_INT || inputValue < GRAPHQL_MIN_INT ) {
58
62
throw new GraphQLError (
59
63
`Int cannot represent non 32-bit signed integer value: ${ inputValue } ` ,
60
64
) ;
@@ -70,7 +74,7 @@ export const GraphQLInt = new GraphQLScalarType<number>({
70
74
) ;
71
75
}
72
76
const num = parseInt ( valueNode . value , 10 ) ;
73
- if ( num > MAX_INT || num < MIN_INT ) {
77
+ if ( num > GRAPHQL_MAX_INT || num < GRAPHQL_MIN_INT ) {
74
78
throw new GraphQLError (
75
79
`Int cannot represent non 32-bit signed integer value: ${ valueNode . value } ` ,
76
80
valueNode ,
0 commit comments