All Collections
Versions 3.0 and 2.0
Implement
Workspaces
Nullable Variables in GraphQL Mutation Hooks
Nullable Variables in GraphQL Mutation Hooks
Elisa Dinsmore avatar
Written by Elisa Dinsmore
Updated over a week ago

This article is for Flatfile's Workspaces. If you'd like to check out the latest version of the Flatfile Data Exchange Platform, click here!

If you have a GraphQL mutation hook with custom variables, you can control whether empty or null properties are sent to you by including just a few lines of code in a JSON payload.

If your mutation hook looks like this:

mutation Test($myData: JSON!) {
createPayment(
input: $myData
){
id
name
email
 }
}

The payload should look something like this:

"name": "myData","value": {
"name": "$field_name",
"email": "$field_email"
},
"includeNullProperties": true
// determines whether or not to send empty or null properties

This payload should be a POST request to the /rest/mutations/[ID]/variables endpoint (where [ID] is your endpoint ID).

The custom variables in your mutation hook (in this example, they are “name” and “email”) should be included in “value” in the payload that you are sending.

“includeNullproperties” can be set to “true” or “false” depending on the desired behavior.

After sending the payload, you should verify that your GraphQL mutation now has the correct variable by reloading the GraphQL mutations page of your data template. You should see the new variables under the Variables header.

mceclip0.png

All that’s left to do is create a new Workspace and add a GraphQL mutation authorization header, and you’re done! 🚀

Did this answer your question?