Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export constants MAX_INT and MIN_INT #2582

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/type/scalars.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export const GraphQLString: GraphQLScalarType;
export const GraphQLBoolean: GraphQLScalarType;
export const GraphQLID: GraphQLScalarType;

export declare const MAX_INT: number;
export declare const MIN_INT: number;

export const specifiedScalarTypes: ReadonlyArray<GraphQLScalarType>;

export function isSpecifiedScalarType(type: GraphQLNamedType): boolean;
10 changes: 5 additions & 5 deletions src/type/scalars.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { type GraphQLNamedType, 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;

function serializeInt(outputValue: mixed): number {
const coercedValue = serializeObject(outputValue);
Expand All @@ -41,7 +41,7 @@ function serializeInt(outputValue: mixed): number {
if (num > MAX_INT || num < MIN_INT) {
throw new GraphQLError(
'Int cannot represent non 32-bit signed integer value: ' +
inspect(coercedValue),
inspect(coercedValue),
);
}
return num;
Expand Down Expand Up @@ -266,7 +266,7 @@ export const GraphQLID = new GraphQLScalarType({
if (valueNode.kind !== Kind.STRING && valueNode.kind !== Kind.INT) {
throw new GraphQLError(
'ID cannot represent a non-string and non-integer value: ' +
print(valueNode),
print(valueNode),
valueNode,
);
}
Expand All @@ -282,6 +282,6 @@ export const specifiedScalarTypes = Object.freeze([
GraphQLID,
]);

export function isSpecifiedScalarType(type: GraphQLNamedType): boolean %checks {
export function isSpecifiedScalarType(type: GraphQLNamedType): boolean % checks {
return specifiedScalarTypes.some(({ name }) => type.name === name);
}