File tree 2 files changed +11
-12
lines changed
Tests/GraphQLTests/TypeTests
2 files changed +11
-12
lines changed Original file line number Diff line number Diff line change @@ -201,6 +201,11 @@ public let GraphQLBoolean = try! GraphQLScalarType(
201
201
if case let . bool( value) = inputValue {
202
202
return inputValue
203
203
}
204
+ // NOTE: We deviate from graphql-js and allow numeric conversions here because
205
+ // the MapCoder's round-trip conversion to NSObject for Bool converts to 0/1 numbers.
206
+ if case let . number( value) = inputValue {
207
+ return . bool( value. intValue != 0 )
208
+ }
204
209
throw GraphQLError (
205
210
message: " Boolean cannot represent a non boolean value: \( inputValue) "
206
211
)
Original file line number Diff line number Diff line change @@ -300,18 +300,12 @@ class ScalarTests: XCTestCase {
300
300
GraphQLBoolean . parseValue ( . null) ,
301
301
" Boolean cannot represent a non boolean value: null "
302
302
)
303
- try XCTAssertThrowsError (
304
- GraphQLBoolean . parseValue ( 0 ) ,
305
- " Boolean cannot represent a non boolean value: 0 "
306
- )
307
- try XCTAssertThrowsError (
308
- GraphQLBoolean . parseValue ( 1 ) ,
309
- " Boolean cannot represent a non boolean value: 1 "
310
- )
311
- try XCTAssertThrowsError (
312
- GraphQLBoolean . parseValue ( . double( Double . nan) ) ,
313
- " Boolean cannot represent a non boolean value: NaN "
314
- )
303
+ // NOTE: We deviate from graphql-js and allow numeric conversions here because
304
+ // the MapCoder's round-trip conversion to NSObject for Bool converts to 0/1 numbers.
305
+ try XCTAssertNoThrow ( GraphQLBoolean . parseValue ( 0 ) )
306
+ try XCTAssertNoThrow ( GraphQLBoolean . parseValue ( 1 ) )
307
+ try XCTAssertNoThrow ( GraphQLBoolean . parseValue ( . double( Double . nan) ) )
308
+
315
309
try XCTAssertThrowsError (
316
310
GraphQLBoolean . parseValue ( " " ) ,
317
311
#"Boolean cannot represent a non boolean value: """#
You can’t perform that action at this time.
0 commit comments