From 65931cd8db097346be7420cfa000f5728477d0dc Mon Sep 17 00:00:00 2001 From: Francisco Marques Date: Tue, 2 Nov 2021 11:18:45 +0000 Subject: [PATCH 1/3] Add exports to MAX_INT and MIN_INT in scalars.ts --- src/type/scalars.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/type/scalars.ts b/src/type/scalars.ts index 45b7dbffdf..6fc353e132 100644 --- a/src/type/scalars.ts +++ b/src/type/scalars.ts @@ -14,8 +14,8 @@ import { GraphQLScalarType } from './definition'; // // n.b. JavaScript's integers are safe between -(2^53 - 1) and 2^53 - 1 because // they are internally represented as IEEE 754 doubles. -const MAX_INT = 2147483647; -const MIN_INT = -2147483648; +export const MAX_INT = 2147483647; +export const MIN_INT = -2147483648; export const GraphQLInt = new GraphQLScalarType({ name: 'Int', From d3548b08c0543defe8a85a77a4f27512c9c6a55e Mon Sep 17 00:00:00 2001 From: Francisco Marques Date: Thu, 4 Nov 2021 09:42:26 +0000 Subject: [PATCH 2/3] Added GRAPHQL to exported MAX and MIN INT & doc improvements --- src/index.ts | 3 +++ src/type/index.ts | 3 +++ src/type/scalars.ts | 24 ++++++++++++++---------- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/index.ts b/src/index.ts index 75a1e6f0c0..c0c6b9e9d6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -61,6 +61,9 @@ export { TypeKind, /** Constant Deprecation Reason */ DEFAULT_DEPRECATION_REASON, + /** Int boundaries constants */ + GRAPHQL_MAX_INT, + GRAPHQL_MIN_INT, /** GraphQL Types for introspection. */ introspectionTypes, __Schema, diff --git a/src/type/index.ts b/src/type/index.ts index 2561426b53..220412c4f0 100644 --- a/src/type/index.ts +++ b/src/type/index.ts @@ -151,6 +151,9 @@ export { GraphQLString, GraphQLBoolean, GraphQLID, + /** Int boundaries constants */ + GRAPHQL_MAX_INT, + GRAPHQL_MIN_INT, } from './scalars'; export { diff --git a/src/type/scalars.ts b/src/type/scalars.ts index 6fc353e132..06ce25aa8b 100644 --- a/src/type/scalars.ts +++ b/src/type/scalars.ts @@ -9,13 +9,17 @@ import { GraphQLError } from '../error/GraphQLError'; import type { GraphQLNamedType } from './definition'; import { GraphQLScalarType } from './definition'; -// As per the GraphQL Spec, Integers are only treated as valid when a valid -// 32-bit signed integer, providing the broadest support across platforms. -// -// n.b. JavaScript's integers are safe between -(2^53 - 1) and 2^53 - 1 because -// they are internally represented as IEEE 754 doubles. -export const MAX_INT = 2147483647; -export const MIN_INT = -2147483648; +/** + * Maximum possible Int value as per GraphQL Spec (32-bit signed integer). + * n.b. This differs from JavaScript's numbers that are IEEE 754 doubles safe up-to 2^53 - 1 + * */ +export const GRAPHQL_MAX_INT = 2147483647; + +/** + * Minimum possible Int value as per GraphQL Spec (32-bit signed integer). + * n.b. This differs from JavaScript's numbers that are IEEE 754 doubles safe starting at -(2^53 - 1) + * */ +export const GRAPHQL_MIN_INT = -2147483648; export const GraphQLInt = new GraphQLScalarType({ name: 'Int', @@ -39,7 +43,7 @@ export const GraphQLInt = new GraphQLScalarType({ `Int cannot represent non-integer value: ${inspect(coercedValue)}`, ); } - if (num > MAX_INT || num < MIN_INT) { + if (num > GRAPHQL_MAX_INT || num < GRAPHQL_MIN_INT) { throw new GraphQLError( 'Int cannot represent non 32-bit signed integer value: ' + inspect(coercedValue), @@ -54,7 +58,7 @@ export const GraphQLInt = new GraphQLScalarType({ `Int cannot represent non-integer value: ${inspect(inputValue)}`, ); } - if (inputValue > MAX_INT || inputValue < MIN_INT) { + if (inputValue > GRAPHQL_MAX_INT || inputValue < GRAPHQL_MIN_INT) { throw new GraphQLError( `Int cannot represent non 32-bit signed integer value: ${inputValue}`, ); @@ -70,7 +74,7 @@ export const GraphQLInt = new GraphQLScalarType({ ); } const num = parseInt(valueNode.value, 10); - if (num > MAX_INT || num < MIN_INT) { + if (num > GRAPHQL_MAX_INT || num < GRAPHQL_MIN_INT) { throw new GraphQLError( `Int cannot represent non 32-bit signed integer value: ${valueNode.value}`, valueNode, From a53fcccb5019a3c77868fae0966bd7c0dd17773a Mon Sep 17 00:00:00 2001 From: Francisco Marques Date: Sun, 7 Nov 2021 11:16:21 +0000 Subject: [PATCH 3/3] Re-order exports in intex.ts Matching the order from type/index.ts --- src/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index c0c6b9e9d6..844ecaf5a2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -51,6 +51,9 @@ export { GraphQLString, GraphQLBoolean, GraphQLID, + /** Int boundaries constants */ + GRAPHQL_MAX_INT, + GRAPHQL_MIN_INT, /** Built-in Directives defined by the Spec */ specifiedDirectives, GraphQLIncludeDirective, @@ -61,9 +64,6 @@ export { TypeKind, /** Constant Deprecation Reason */ DEFAULT_DEPRECATION_REASON, - /** Int boundaries constants */ - GRAPHQL_MAX_INT, - GRAPHQL_MIN_INT, /** GraphQL Types for introspection. */ introspectionTypes, __Schema,