jeddeloh / rescript-apollo-client

ReScript bindings for the Apollo Client ecosystem
MIT License
126 stars 18 forks source link

Passing explicit Null as Mutation parameter #95

Closed varstos closed 3 years ago

varstos commented 3 years ago

I have a mutation that updates an entity. When passing input parameters I want one of the fields to be sent as Null. However, when I try to running something like this:

        updateEntity({
           id: id
           exampleField: None
        })

This is the variable object I find in the network request

operationName: "UpdateEntityField"
query: "mutation UpdateEntity($id: ID!, $field: String)
variables: {id: "exampleid"}

While I wanted to send something along these lines

operationName: "UpdateEntityField"
query: "mutation UpdateEntity($id: ID!, $field: String)
variables: {id: "exampleid",  field: null}

I found a workaround for this which passes Js.Nullable.null->Obj.magic instead of None. I know this violent usage of Js.Nullable.null is not the nicest way to handle this issue, but as we are passing this straight to the Javascript world I don't think this can cause any issues down the line. I think it would be better if we could introduce a better way to handle something like this and make it type-safe.

jfrolich commented 3 years ago

Yes, this is possible using mapJsVariables here you have a function that can manipulate the Raw.t_variables which includes Js.Nullable.t's.

varstos commented 3 years ago

Yes, this is possible using mapJsVariables here you have a function that can manipulate the Raw.t_variables which includes Js.Nullable.t's.

Exactly what I needed I am closing this as this is resolved, thank you!