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

Remove 'isFinite' & 'isInteger' polyfills #2911

Merged
merged 1 commit into from Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 0 additions & 12 deletions src/polyfills/isFinite.js

This file was deleted.

15 changes: 0 additions & 15 deletions src/polyfills/isInteger.js

This file was deleted.

19 changes: 8 additions & 11 deletions src/type/scalars.js
@@ -1,6 +1,3 @@
import isFinite from '../polyfills/isFinite';
import isInteger from '../polyfills/isInteger';

import inspect from '../jsutils/inspect';
import isObjectLike from '../jsutils/isObjectLike';

Expand Down Expand Up @@ -32,7 +29,7 @@ function serializeInt(outputValue: mixed): number {
num = Number(coercedValue);
}

if (!isInteger(num)) {
if (typeof num !== 'number' || !Number.isInteger(num)) {
throw new GraphQLError(
`Int cannot represent non-integer value: ${inspect(coercedValue)}`,
);
Expand All @@ -47,7 +44,7 @@ function serializeInt(outputValue: mixed): number {
}

function coerceInt(inputValue: mixed): number {
if (!isInteger(inputValue)) {
if (typeof inputValue !== 'number' || !Number.isInteger(inputValue)) {
throw new GraphQLError(
`Int cannot represent non-integer value: ${inspect(inputValue)}`,
);
Expand Down Expand Up @@ -96,7 +93,7 @@ function serializeFloat(outputValue: mixed): number {
num = Number(coercedValue);
}

if (!isFinite(num)) {
if (typeof num !== 'number' || !Number.isFinite(num)) {
throw new GraphQLError(
`Float cannot represent non numeric value: ${inspect(coercedValue)}`,
);
Expand All @@ -105,7 +102,7 @@ function serializeFloat(outputValue: mixed): number {
}

function coerceFloat(inputValue: mixed): number {
if (!isFinite(inputValue)) {
if (typeof inputValue !== 'number' || !Number.isFinite(inputValue)) {
throw new GraphQLError(
`Float cannot represent non numeric value: ${inspect(inputValue)}`,
);
Expand Down Expand Up @@ -160,7 +157,7 @@ function serializeString(outputValue: mixed): string {
if (typeof coercedValue === 'boolean') {
return coercedValue ? 'true' : 'false';
}
if (isFinite(coercedValue)) {
if (typeof coercedValue === 'number' && Number.isFinite(coercedValue)) {
return coercedValue.toString();
}
throw new GraphQLError(
Expand Down Expand Up @@ -200,7 +197,7 @@ function serializeBoolean(outputValue: mixed): boolean {
if (typeof coercedValue === 'boolean') {
return coercedValue;
}
if (isFinite(coercedValue)) {
if (Number.isFinite(coercedValue)) {
return coercedValue !== 0;
}
throw new GraphQLError(
Expand Down Expand Up @@ -239,7 +236,7 @@ function serializeID(outputValue: mixed): string {
if (typeof coercedValue === 'string') {
return coercedValue;
}
if (isInteger(coercedValue)) {
if (Number.isInteger(coercedValue)) {
return String(coercedValue);
}
throw new GraphQLError(`ID cannot represent value: ${inspect(outputValue)}`);
Expand All @@ -249,7 +246,7 @@ function coerceID(inputValue: mixed): string {
if (typeof inputValue === 'string') {
return inputValue;
}
if (isInteger(inputValue)) {
if (typeof inputValue === 'number' && Number.isInteger(inputValue)) {
return inputValue.toString();
}
throw new GraphQLError(`ID cannot represent value: ${inspect(inputValue)}`);
Expand Down
3 changes: 1 addition & 2 deletions src/utilities/astFromValue.js
@@ -1,4 +1,3 @@
import isFinite from '../polyfills/isFinite';
import arrayFrom from '../polyfills/arrayFrom';
import objectValues from '../polyfills/objectValues';

Expand Down Expand Up @@ -114,7 +113,7 @@ export function astFromValue(value: mixed, type: GraphQLInputType): ?ValueNode {
}

// JavaScript numbers can be Int or Float values.
if (typeof serialized === 'number' && isFinite(serialized)) {
if (typeof serialized === 'number' && Number.isFinite(serialized)) {
const stringNum = String(serialized);
return integerStringRegExp.test(stringNum)
? { kind: Kind.INT, value: stringNum }
Expand Down