1
- import isFinite from '../polyfills/isFinite' ;
2
- import isInteger from '../polyfills/isInteger' ;
3
-
4
1
import inspect from '../jsutils/inspect' ;
5
2
import isObjectLike from '../jsutils/isObjectLike' ;
6
3
@@ -32,7 +29,7 @@ function serializeInt(outputValue: mixed): number {
32
29
num = Number ( coercedValue ) ;
33
30
}
34
31
35
- if ( ! isInteger ( num ) ) {
32
+ if ( typeof num !== 'number' || ! Number . isInteger ( num ) ) {
36
33
throw new GraphQLError (
37
34
`Int cannot represent non-integer value: ${ inspect ( coercedValue ) } ` ,
38
35
) ;
@@ -47,7 +44,7 @@ function serializeInt(outputValue: mixed): number {
47
44
}
48
45
49
46
function coerceInt ( inputValue : mixed ) : number {
50
- if ( ! isInteger ( inputValue ) ) {
47
+ if ( typeof inputValue !== 'number' || ! Number . isInteger ( inputValue ) ) {
51
48
throw new GraphQLError (
52
49
`Int cannot represent non-integer value: ${ inspect ( inputValue ) } ` ,
53
50
) ;
@@ -96,7 +93,7 @@ function serializeFloat(outputValue: mixed): number {
96
93
num = Number ( coercedValue ) ;
97
94
}
98
95
99
- if ( ! isFinite ( num ) ) {
96
+ if ( typeof num !== 'number' || ! Number . isFinite ( num ) ) {
100
97
throw new GraphQLError (
101
98
`Float cannot represent non numeric value: ${ inspect ( coercedValue ) } ` ,
102
99
) ;
@@ -105,7 +102,7 @@ function serializeFloat(outputValue: mixed): number {
105
102
}
106
103
107
104
function coerceFloat ( inputValue : mixed ) : number {
108
- if ( ! isFinite ( inputValue ) ) {
105
+ if ( typeof inputValue !== 'number' || ! Number . isFinite ( inputValue ) ) {
109
106
throw new GraphQLError (
110
107
`Float cannot represent non numeric value: ${ inspect ( inputValue ) } ` ,
111
108
) ;
@@ -160,7 +157,7 @@ function serializeString(outputValue: mixed): string {
160
157
if ( typeof coercedValue === 'boolean' ) {
161
158
return coercedValue ? 'true' : 'false' ;
162
159
}
163
- if ( isFinite ( coercedValue ) ) {
160
+ if ( typeof coercedValue === 'number' && Number . isFinite ( coercedValue ) ) {
164
161
return coercedValue . toString ( ) ;
165
162
}
166
163
throw new GraphQLError (
@@ -200,7 +197,7 @@ function serializeBoolean(outputValue: mixed): boolean {
200
197
if ( typeof coercedValue === 'boolean' ) {
201
198
return coercedValue ;
202
199
}
203
- if ( isFinite ( coercedValue ) ) {
200
+ if ( Number . isFinite ( coercedValue ) ) {
204
201
return coercedValue !== 0 ;
205
202
}
206
203
throw new GraphQLError (
@@ -239,7 +236,7 @@ function serializeID(outputValue: mixed): string {
239
236
if ( typeof coercedValue === 'string' ) {
240
237
return coercedValue ;
241
238
}
242
- if ( isInteger ( coercedValue ) ) {
239
+ if ( Number . isInteger ( coercedValue ) ) {
243
240
return String ( coercedValue ) ;
244
241
}
245
242
throw new GraphQLError ( `ID cannot represent value: ${ inspect ( outputValue ) } ` ) ;
@@ -249,7 +246,7 @@ function coerceID(inputValue: mixed): string {
249
246
if ( typeof inputValue === 'string' ) {
250
247
return inputValue ;
251
248
}
252
- if ( isInteger ( inputValue ) ) {
249
+ if ( typeof inputValue === 'number' && Number . isInteger ( inputValue ) ) {
253
250
return inputValue . toString ( ) ;
254
251
}
255
252
throw new GraphQLError ( `ID cannot represent value: ${ inspect ( inputValue ) } ` ) ;
0 commit comments