Skip to content

Commit 1b33f57

Browse files
committed
Export GRAPHQL_MAX_INT and GRAPHQL_MIN_INT
Replicates graphql/graphql-js@11a0802
1 parent e8b3940 commit 1b33f57

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

docs/modules/type.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,13 @@ Definitions
172172
.. autoclass:: GraphQLInt
173173
.. autoclass:: GraphQLString
174174

175-
A tuple with all specified directives is available as :data:`specified_directives`.
175+
.. data:: GRAPHQL_MAX_INT
176+
177+
Maximum possible Int value as per GraphQL Spec (32-bit signed integer)
178+
179+
.. data:: GRAPHQL_MIN_INT
180+
181+
Minimum possible Int value as per GraphQL Spec (32-bit signed integer)
176182

177183

178184
Schema

src/graphql/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@
247247
GraphQLString,
248248
GraphQLBoolean,
249249
GraphQLID,
250+
# Int boundaries constants
251+
GRAPHQL_MAX_INT,
252+
GRAPHQL_MIN_INT,
250253
# Built-in Directives defined by the Spec
251254
specified_directives,
252255
GraphQLIncludeDirective,
@@ -471,6 +474,8 @@
471474
"GraphQLString",
472475
"GraphQLBoolean",
473476
"GraphQLID",
477+
"GRAPHQL_MAX_INT",
478+
"GRAPHQL_MIN_INT",
474479
"specified_directives",
475480
"GraphQLIncludeDirective",
476481
"GraphQLSkipDirective",

src/graphql/type/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@
147147
GraphQLString,
148148
GraphQLBoolean,
149149
GraphQLID,
150+
# Int boundaries constants
151+
GRAPHQL_MAX_INT,
152+
GRAPHQL_MIN_INT,
150153
)
151154

152155
from .introspection import (
@@ -279,6 +282,8 @@
279282
"GraphQLString",
280283
"GraphQLBoolean",
281284
"GraphQLID",
285+
"GRAPHQL_MAX_INT",
286+
"GRAPHQL_MIN_INT",
282287
"is_introspection_type",
283288
"introspection_types",
284289
"TypeKind",

src/graphql/type/scalars.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,22 @@
2121
"GraphQLString",
2222
"GraphQLBoolean",
2323
"GraphQLID",
24+
"GRAPHQL_MAX_INT",
25+
"GRAPHQL_MIN_INT",
2426
]
2527

26-
27-
# As per the GraphQL Spec, Integers are only treated as valid when a valid
28-
# 32-bit signed integer, providing the broadest support across platforms.
29-
#
30-
# n.b. JavaScript's integers are safe between -(2^53 - 1) and 2^53 - 1 because
31-
# they are internally represented as IEEE 754 doubles,
28+
# As per the GraphQL Spec, Integers are only treated as valid
29+
# when they can be represented as a 32-bit signed integer,
30+
# providing the broadest support across platforms.
31+
# n.b. JavaScript's numbers are safe between -(2^53 - 1) and 2^53 - 1
32+
# because they are internally represented as IEEE 754 doubles,
3233
# while Python's integers may be arbitrarily large.
33-
MAX_INT = 2_147_483_647
34-
MIN_INT = -2_147_483_648
34+
35+
GRAPHQL_MAX_INT = 2_147_483_647
36+
"""Maximum possible Int value as per GraphQL Spec (32-bit signed integer)"""
37+
38+
GRAPHQL_MIN_INT = -2_147_483_648
39+
"""Minimum possible Int value as per GraphQL Spec (32-bit signed integer)"""
3540

3641

3742
def serialize_int(output_value: Any) -> int:
@@ -53,7 +58,7 @@ def serialize_int(output_value: Any) -> int:
5358
raise GraphQLError(
5459
"Int cannot represent non-integer value: " + inspect(output_value)
5560
)
56-
if not MIN_INT <= num <= MAX_INT:
61+
if not GRAPHQL_MIN_INT <= num <= GRAPHQL_MAX_INT:
5762
raise GraphQLError(
5863
"Int cannot represent non 32-bit signed integer value: "
5964
+ inspect(output_value)
@@ -72,7 +77,7 @@ def coerce_int(input_value: Any) -> int:
7277
raise GraphQLError(
7378
"Int cannot represent non-integer value: " + inspect(input_value)
7479
)
75-
if not MIN_INT <= input_value <= MAX_INT:
80+
if not GRAPHQL_MIN_INT <= input_value <= GRAPHQL_MAX_INT:
7681
raise GraphQLError(
7782
"Int cannot represent non 32-bit signed integer value: "
7883
+ inspect(input_value)
@@ -88,7 +93,7 @@ def parse_int_literal(value_node: ValueNode, _variables: Any = None) -> int:
8893
value_node,
8994
)
9095
num = int(value_node.value)
91-
if not MIN_INT <= num <= MAX_INT:
96+
if not GRAPHQL_MIN_INT <= num <= GRAPHQL_MAX_INT:
9297
raise GraphQLError(
9398
"Int cannot represent non 32-bit signed integer value: "
9499
+ print_ast(value_node),

0 commit comments

Comments
 (0)