diff --git a/src/polyfills/isFinite.js b/src/polyfills/isFinite.js deleted file mode 100644 index 58f8614b9f..0000000000 --- a/src/polyfills/isFinite.js +++ /dev/null @@ -1,12 +0,0 @@ -declare function isFinitePolyfill( - value: mixed, -): boolean %checks(typeof value === 'number'); - -/* eslint-disable no-redeclare */ -// $FlowFixMe[name-already-bound] workaround for: https://github.com/facebook/flow/issues/4441 -const isFinitePolyfill = - Number.isFinite || - function (value) { - return typeof value === 'number' && isFinite(value); - }; -export default isFinitePolyfill; diff --git a/src/polyfills/isInteger.js b/src/polyfills/isInteger.js deleted file mode 100644 index fdd50ff247..0000000000 --- a/src/polyfills/isInteger.js +++ /dev/null @@ -1,15 +0,0 @@ -declare function isInteger(value: mixed): boolean %checks(typeof value === - 'number'); - -/* eslint-disable no-redeclare */ -// $FlowFixMe[name-already-bound] workaround for: https://github.com/facebook/flow/issues/4441 -const isInteger = - Number.isInteger || - function (value) { - return ( - typeof value === 'number' && - isFinite(value) && - Math.floor(value) === value - ); - }; -export default isInteger; diff --git a/src/type/scalars.js b/src/type/scalars.js index ceca14b5c3..e02d2e5c6c 100644 --- a/src/type/scalars.js +++ b/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'; @@ -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)}`, ); @@ -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)}`, ); @@ -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)}`, ); @@ -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)}`, ); @@ -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( @@ -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( @@ -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)}`); @@ -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)}`); diff --git a/src/utilities/astFromValue.js b/src/utilities/astFromValue.js index 39ab089d27..eb63cadeea 100644 --- a/src/utilities/astFromValue.js +++ b/src/utilities/astFromValue.js @@ -1,4 +1,3 @@ -import isFinite from '../polyfills/isFinite'; import arrayFrom from '../polyfills/arrayFrom'; import objectValues from '../polyfills/objectValues'; @@ -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 }