How can I omit optional arguments when running GraphQL mutations?

I have a mutation that takes 10 arguments but only 3 are required by the server. The rest can be present or absent depending on the situation.

The mutation is imported from the query library to my dashboard with {{ }} placeholders for each argument's value. I have a JSON form on the dashboard that has inputs for all ten attributes. When the form is submitted a script runs that performs the query and passes the values from form inputs into relevant placeholders in the query.

Everything works well when all the attribute values were filled out in the form (most cases) but some edge cases produce errors.

Is it possible to set up the mutation in Retool so that when an argument value is not provided it's not included in the API call at all? I hope this situation makes at least some sense.

Hi there @art :wave:

You know, I think I got an idea of what you mean but I'm unsure of this since I haven't seen the key/value pairs dynamically set like that. Are you able to send some sort of null, undefined, 0 or empty string value back to your resource instead? You may be able to use some ternary to by pass some empty values from your form..

Thanks for replying!

I'll look into possibly modifying what the graph expects. But I think an empty value is a valid and separate situation and that empty value will be saved. And treating an empty value differently might break a different workflow with the same form.

Maybe I am doing this in a roundabout way but I haven't found a more straightforward one. In the query library I have a mutation set up with variables like this:

userUpdate(input: {payment_id: "{{payment_id}}", payment_type: "{{payment_type}}", status: "{{status}}", customer_id: "{{customer_id}}", plan_id: "{{plan_id}}", subscription_id: "{{subscription_id}}", product_id: "{{product_id}}", admin_name: "{{admin_name}}", update_reason: "{{update_reason}}", key: "{{key}}"})

It is then imported into the dashboard where variables are set again (this is confusing to me too but this was the only way I can make it work):
Lastly, the JSON form has an event trigger that runs this script on Submit:

  additionalScope: { 
  onSuccess: function(data) {