File tree Expand file tree Collapse file tree 2 files changed +11
-12
lines changed
Tests/GraphQLTests/TypeTests Expand file tree Collapse file tree 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(
201201 if case let . bool( value) = inputValue {
202202 return inputValue
203203 }
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+ }
204209 throw GraphQLError (
205210 message: " Boolean cannot represent a non boolean value: \( inputValue) "
206211 )
Original file line number Diff line number Diff line change @@ -300,18 +300,12 @@ class ScalarTests: XCTestCase {
300300 GraphQLBoolean . parseValue ( . null) ,
301301 " Boolean cannot represent a non boolean value: null "
302302 )
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+
315309 try XCTAssertThrowsError (
316310 GraphQLBoolean . parseValue ( " " ) ,
317311 #"Boolean cannot represent a non boolean value: """#
You can’t perform that action at this time.
0 commit comments