Closed Igor-Palaguta closed 4 years ago
For proper detection what value is hidden under NSNumber can be used code from https://stackoverflow.com/a/30223989/2035054
func isBoolNumber(num: NSNumber) -> Bool
{
let boolID = CFBooleanGetTypeID() // the type ID of CFBoolean
let numID = CFGetTypeID(num) // the type ID of num
return numID == boolID
}
CFBooleanGetTypeID
is already used in several places in GraphQL
We have in application argument with default value 0
"offset": GraphQLArgument(type: GraphQLInt, defaultValue: 0),
If this argument is not passed, then instead of integer
0
booleanfalse
is used. Soarguments["offset"].int
returnsnil
In the screenshot you can see that Any 0 is casted to Bool and is interpreted as false
It happens as
try JSONSerialization.jsonObject(with: data, options: .allowFragments)
returns NSNumber, and 0 is interpreted as false (https://developer.apple.com/documentation/foundation/nsnumber/1410865-boolvalue)GraphQL 1.1.7 Xcode Version 12.0 (12A7209)