You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When expected as an input type, only boolean input values are accepted. All other input values must > raise a query error indicating an incorrect type.
The problem here:
If the value is a string the call Boolean.parseBoolean((String)input) returns a false if the string is not containing "true".
The value passed as the first parameter is converted to a boolean value, if necessary. If the value is omitted or is 0, -0, null, false, NaN, undefined, or the empty string (""), the object has an initial value of false. All other values, including any object or the string "false", create an object with an initial value of true.
So they accept strings / numbers and in fact any object with an idiomatic JavaScript approach.
So I dont think the current approach is incorrect.
But if you could explain more about the impact you are seeing and the inputs you think are incorrect we can discuss it
If it's true of type boolean in JSON it's correct but if it's "true" of type string in JSON it should fail because of type mismatch.
Why i did so:
The difference here between input and output in the spec. For output conversion is fine if no information is lost (this is really non specific), but for input the types have to match.
The JS Boolean(x) and Boolean.parseBoolean(x) in Java are really different in their behaviour.
In JS Boolean("false") will always return true because the string isn't empty, but in Java Boolean.parseBoolean("false") will be always false.
changed the title [-]Mutations with non matching type variables handled wrong[/-][+]Mutations with non matching Boolean type variables handled wrong[/+]on Jul 24, 2018
I am inclined to leave the behaviour as it is. That is a value for input to a boolean uses idiomatic Java boolean-ness just like the JS reference implementation uses idiomatic JS boolean-ess.
@bbakerman I ran into this bug recently, and it took me a while to figure out what was going on. For example, the following query causes isInvitable to be parsed as false instead of throwing an error. I personally feel we should change this behavior for the reasons tipok mentioned.
changed the title [-]Mutations with non matching Boolean type variables handled wrong[/-][+]Boolean scalars accept strings outside `true` and `false` (unlike literals)[/+]on Jul 3, 2021
Activity
bbakerman commentedon Jun 30, 2018
The trick here is the esoteric argument about "what is a boolean input type"
Boolean.parseBoolean is a java idiomatic way to get a Boolean value. And yes it takes Strings.
The reference graphql-js (which we tend to go to when the spec is in question) uses JavaScript Boolean parsing
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean
So they accept strings / numbers and in fact any object with an idiomatic JavaScript approach.
So I dont think the current approach is incorrect.
But if you could explain more about the impact you are seeing and the inputs you think are incorrect we can discuss it
tipok commentedon Jun 30, 2018
I've interpreted the spec this way:
If it's
trueof type boolean in JSON it's correct but if it's"true"of type string in JSON it should fail because of type mismatch.Why i did so:
The difference here between input and output in the spec. For output conversion is fine if no information is lost (this is really non specific), but for input the types have to match.
The JS
Boolean(x)andBoolean.parseBoolean(x)in Java are really different in their behaviour.In JS
Boolean("false")will always returntruebecause the string isn't empty, but in JavaBoolean.parseBoolean("false")will be always false.Now to our test:
We do have a mutation:
GraphLQ:
Variables:
{ "b": "hello", "s": "hello again" }The result is an update which is interpreted as:
{ "b": false, "s": "hello again" }[-]Mutations with non matching type variables handled wrong[/-][+]Mutations with non matching Boolean type variables handled wrong[/+]bbakerman commentedon Jul 26, 2018
I am inclined to leave the behaviour as it is. That is a value for input to a boolean uses idiomatic Java boolean-ness just like the JS reference implementation uses idiomatic JS boolean-ess.
@andimarek - thoughts?
neelkamath commentedon Jun 23, 2021
@bbakerman I ran into this bug recently, and it took me a while to figure out what was going on. For example, the following query causes
isInvitableto be parsed asfalseinstead of throwing an error. I personally feel we should change this behavior for the reasons tipok mentioned.[-]Mutations with non matching Boolean type variables handled wrong[/-][+]Boolean scalars accept strings outside `true` and `false` (unlike literals)[/+]