Closed zth closed 1 year ago
type Input {
a: Int!
b: Int
c: int
}
module M = %relay(`
mutation Test($input: Input!) @rescriptRelayNullableVariables {
test(input: $input) {
result
}
}
`)
M.commitMutation(~variables=M.makeVarialbes(~input=M.makeVariables_input(~a=1, ~b=Js.Nullable.null, ())))
The variables on the network request would be something like{a: 1, b: null}
?
type Input { a: Int! b: Int c: int }
module M = %relay(` mutation Test($input: Input!) @rescriptRelayNullableVariables { test(input: $input) { result } } `) M.commitMutation(~variables=M.makeVarialbes(~input=M.makeVariables_input(~a=1, ~b=Js.Nullable.null, ())))
The variables on the network request would be something like
{a: 1, b: null}
?
Not 100%, you'll need to wrap everything with Js.Nullable
. I haven't added support for object makers (most likely won't since they might be going away in the future), so it'd need to be:
M.commitMutation(~variables=(input: Js.Nullable.return({a: Js.Nullable.return(1), b: Js.Nullable.null})}, ())
But then yes, the network request would be: {input: {a: 1, b: null}}
Has anyone tried this for real yet? Cc @lozlow
Will merge this and we can iterate on it more if needed.
Closes https://github.com/zth/rescript-relay/issues/348
This introduces a directive
@rescriptRelayNullableVariables
on operations that will allow you to leverageJs.Nullable.t
to sendnull
explicitly to your APIs.You can test this in your project by running
yarn add rescript-relay@support-nullable-variables
.How it works in a nutshell:
This works for:
The reason for this being an explicit directive and not applied globally is that this isn't the default you want, working with options is still so much easier.
Notes: