On boolean fields, is it possible to configure the default value to be false
instead of null
if it’s never been touched?
For example, these fields:
Using the query:
query SimpleQuery {
allAlerts {
sitewide
overrideHours
events
}
}
Returns:
"data": {
"allAlerts": [
{
"sitewide": true,
"overrideHours": true,
"events": true
},
{
"sitewide": true,
"overrideHours": false,
"events": true
},
{
"sitewide": null,
"overrideHours": null,
"events": null
}
]
}
}
The 2nd overrideHours
is false
because someone toggled it, but the 3rd is null
even though the field default value is set:
With Javascript, truthiness is a weird and confusing topic and having the API typecast booleans (or perhaps fail to, in cases where it isn’t set by a user) results in different possible responses for that field.
Might it be possible to implement this in a non-breaking way? Perhaps by adding a “required” validation for booleans, in which case non-required, unfilled fields would still return null
as before, but required booleans will return false
instead?
Or is there a better way to deal with this? Should I just implicitly convert from null
to false
on the client side?