1
1
import { inspect } from '../jsutils/inspect.js' ;
2
+ import { isInteger } from '../jsutils/isInteger.js' ;
3
+ import { isNumeric } from '../jsutils/isNumeric.js' ;
2
4
import { isObjectLike } from '../jsutils/isObjectLike.js' ;
3
5
4
6
import { GraphQLError } from '../error/GraphQLError.js' ;
@@ -40,7 +42,7 @@ export const GraphQLInt = new GraphQLScalarType<number>({
40
42
num = Number ( coercedValue ) ;
41
43
}
42
44
43
- if ( typeof num !== 'number' || ! Number . isInteger ( num ) ) {
45
+ if ( ! isInteger ( num ) ) {
44
46
throw new GraphQLError (
45
47
`Int cannot represent non-integer value: ${ inspect ( coercedValue ) } ` ,
46
48
) ;
@@ -51,21 +53,22 @@ export const GraphQLInt = new GraphQLScalarType<number>({
51
53
inspect ( coercedValue ) ,
52
54
) ;
53
55
}
54
- return num ;
56
+ return Number ( num ) ;
55
57
} ,
56
58
57
59
parseValue ( inputValue ) {
58
- if ( typeof inputValue !== 'number' || ! Number . isInteger ( inputValue ) ) {
60
+ if ( ! isInteger ( inputValue ) ) {
59
61
throw new GraphQLError (
60
62
`Int cannot represent non-integer value: ${ inspect ( inputValue ) } ` ,
61
63
) ;
62
64
}
63
- if ( inputValue > GRAPHQL_MAX_INT || inputValue < GRAPHQL_MIN_INT ) {
65
+ const coercedVal = Number ( inputValue ) ;
66
+ if ( coercedVal > GRAPHQL_MAX_INT || coercedVal < GRAPHQL_MIN_INT ) {
64
67
throw new GraphQLError (
65
68
`Int cannot represent non 32-bit signed integer value: ${ inputValue } ` ,
66
69
) ;
67
70
}
68
- return inputValue ;
71
+ return coercedVal ;
69
72
} ,
70
73
71
74
parseConstLiteral ( valueNode ) {
@@ -96,7 +99,7 @@ export const GraphQLInt = new GraphQLScalarType<number>({
96
99
} ,
97
100
} ) ;
98
101
99
- export const GraphQLFloat = new GraphQLScalarType < number > ( {
102
+ export const GraphQLFloat = new GraphQLScalarType < number | bigint > ( {
100
103
name : 'Float' ,
101
104
description :
102
105
'The `Float` scalar type represents signed double-precision fractional values as specified by [IEEE 754](https://en.wikipedia.org/wiki/IEEE_floating_point).' ,
@@ -113,16 +116,17 @@ export const GraphQLFloat = new GraphQLScalarType<number>({
113
116
num = Number ( coercedValue ) ;
114
117
}
115
118
116
- if ( typeof num !== 'number' || ! Number . isFinite ( num ) ) {
119
+ if ( ! isNumeric ( num ) ) {
117
120
throw new GraphQLError (
118
121
`Float cannot represent non numeric value: ${ inspect ( coercedValue ) } ` ,
119
122
) ;
120
123
}
124
+
121
125
return num ;
122
126
} ,
123
127
124
128
parseValue ( inputValue ) {
125
- if ( typeof inputValue !== 'number' || ! Number . isFinite ( inputValue ) ) {
129
+ if ( ! isNumeric ( inputValue ) ) {
126
130
throw new GraphQLError (
127
131
`Float cannot represent non numeric value: ${ inspect ( inputValue ) } ` ,
128
132
) ;
@@ -163,8 +167,8 @@ export const GraphQLString = new GraphQLScalarType<string>({
163
167
if ( typeof coercedValue === 'boolean' ) {
164
168
return coercedValue ? 'true' : 'false' ;
165
169
}
166
- if ( typeof coercedValue === 'number' && Number . isFinite ( coercedValue ) ) {
167
- return coercedValue . toString ( ) ;
170
+ if ( isNumeric ( coercedValue ) ) {
171
+ return String ( coercedValue ) ;
168
172
}
169
173
throw new GraphQLError (
170
174
`String cannot represent value: ${ inspect ( outputValue ) } ` ,
@@ -207,8 +211,8 @@ export const GraphQLBoolean = new GraphQLScalarType<boolean>({
207
211
if ( typeof coercedValue === 'boolean' ) {
208
212
return coercedValue ;
209
213
}
210
- if ( Number . isFinite ( coercedValue ) ) {
211
- return coercedValue !== 0 ;
214
+ if ( isNumeric ( coercedValue ) ) {
215
+ return Number ( coercedValue ) !== 0 ;
212
216
}
213
217
throw new GraphQLError (
214
218
`Boolean cannot represent a non boolean value: ${ inspect ( coercedValue ) } ` ,
@@ -252,7 +256,7 @@ export const GraphQLID = new GraphQLScalarType<string>({
252
256
if ( typeof coercedValue === 'string' ) {
253
257
return coercedValue ;
254
258
}
255
- if ( Number . isInteger ( coercedValue ) ) {
259
+ if ( isInteger ( coercedValue ) ) {
256
260
return String ( coercedValue ) ;
257
261
}
258
262
throw new GraphQLError (
@@ -264,8 +268,8 @@ export const GraphQLID = new GraphQLScalarType<string>({
264
268
if ( typeof inputValue === 'string' ) {
265
269
return inputValue ;
266
270
}
267
- if ( typeof inputValue === 'number' && Number . isInteger ( inputValue ) ) {
268
- return inputValue . toString ( ) ;
271
+ if ( isInteger ( inputValue ) ) {
272
+ return String ( inputValue ) ;
269
273
}
270
274
throw new GraphQLError ( `ID cannot represent value: ${ inspect ( inputValue ) } ` ) ;
271
275
} ,
0 commit comments