Skip to content

Commit a774602

Browse files
committed
Spec compliant Int sizing
Related GraphQL-js commit graphql/graphql-js@06f97b6
1 parent 12800cd commit a774602

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

graphql/core/type/scalars.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
from ..language.ast import BooleanValue, FloatValue, IntValue, StringValue
44
from .definition import GraphQLScalarType
55

6-
# Integers are only safe when between -(2^53 - 1) and 2^53 - 1 due to being
7-
# encoded in JavaScript and represented in JSON as double-precision floating
8-
# point numbers, as specified by IEEE 754.
9-
MAX_INT = 9007199254740991
10-
MIN_INT = -9007199254740991
6+
# As per the GraphQL Spec, Integers are only treated as valid when a valid
7+
# 32-bit signed integer, providing the broadest support across platforms.
8+
#
9+
# n.b. JavaScript's integers are safe between -(2^53 - 1) and 2^53 - 1 because
10+
# they are internally represented as IEEE 754 doubles.
11+
MAX_INT = 2147483647
12+
MIN_INT = -2147483648
1113

1214

1315
def coerce_int(value):

tests/core_type/test_serialization.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ def test_serializes_output_int():
1010
assert GraphQLInt.serialize(1.1) == 1
1111
assert GraphQLInt.serialize(-1.1) == -1
1212
assert GraphQLInt.serialize(1e5) == 100000
13+
assert GraphQLInt.serialize(9876504321) is None
14+
assert GraphQLInt.serialize(-9876504321) is None
1315
assert GraphQLInt.serialize(1e100) is None
1416
assert GraphQLInt.serialize(-1e100) is None
1517
assert GraphQLInt.serialize('-1.1') == -1

0 commit comments

Comments
 (0)