Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0 default value for argument is interpreted as false and can not be used #70

Closed
Igor-Palaguta opened this issue Oct 8, 2020 · 2 comments

Comments

@Igor-Palaguta
Copy link
Contributor

Igor-Palaguta commented Oct 8, 2020

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 boolean false is used. So arguments["offset"].int returns nil

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)

Screenshot 2020-10-09 at 01 04 55

GraphQL 1.1.7
Xcode Version 12.0 (12A7209)

@Igor-Palaguta
Copy link
Contributor Author

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

@Igor-Palaguta
Copy link
Contributor Author

Fixed here #71

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant