Closed dfalling closed 2 years ago
This was happening for nullable date fields, which I already have to transform for the input object. I'm making the None
value map to a Some(null)
which ensures it's sent. Feels like a hack but I'm not sure if there's another way:
let optionalDateToJson = (date: option<Js.Date.t>): option<Js.Json.t> => {
switch date {
| Some(date) => Js.Date.toJSONUnsafe(date)->Js.Json.string->Some
| None => Js.Json.null->Some
}
}
For anyone finding this issue later (and if I'm understanding correctly), each query/mutation takes a mapJsVariables
arg for this specific case of when you want to explicitly pass a null.
The tricky part for me is I'm explicitly setting a None
on an input_object
, so I'd expect that would populate the field and send it as a null.
set field to None -> send null don't set field to anything -> field is treated as an optional and omitted
Yeah, I think that's an understandable intuition to have. However, when you think about it, there's no way to differentiate between something explicitly set to None
and something that is implicitly None
by its omission which is how we ended up here. We could create a new type of optional Some | None | Missing
, but then the incompatibility with normal options would probably cause its own issues.
I have a nullable field that I'm trying to change from a value to null. The query simply drops the field, rather than passing the new null value. How can I make Apollo send a null value rather than just omitting the field? I've hunted in the Apollo docs and don't see anything, so I'm hoping there are some rescript tricks I'm missing.
Thanks!