Mutations
This tutorial will show you how to mutate (create/update/delete) objects in our API
Last updated
Was this helpful?
This tutorial will show you how to mutate (create/update/delete) objects in our API
Last updated
Was this helpful?
GraphQL provides the concept of , which allow users to update data on the server. Note that unlike REST, there are no distinctions between a create, update, or delete mutation. Rather GraphQL relies on the mutation name and documentation to understand what a particular mutation does.
In this example, we will loosely build off of the previous example of querying for monitors, by updating a monitor.
Here I'm using a monitor that is triggered from the previous example. You can find a monitor by following the example or by using the UI and grabbing the monitor id from the URL. (.../monitors/:
monitor_id
).
Let's say we want to update the threshold to be higher than the current value, which will clear the monitor.
Because our 3 types of monitors (Drift, Performance, and Data Quality) are all different, we have different mutations for each. This is a drift monitor, so we want the patchDriftMonitor
mutation:
Here we split the query into two parts, a templatized mutation, and its arguments. Templates are useful for reusing queries or mutations and is a much cleaner and more type-safe than string interpolation.
First, we establish the template for reusing this mutation. This template only takes the arguments monitorId
, and threshold
. Each field needs a type, and !
denotes that the field is required. Even though monitorId
looks like a string, it is a special type in GraphQL which allows further validations.
Then we call the actual mutation, using ()
. From looking at the Documentation Explorer, we can tell the shape of the input, which can be nested. Here, we only set a few of the possible fields for this input. monitorId: $monitorId
and threshold: $threshold
use the input variables defined above, while autoThresholdEnabled: false
is hardcoded.
GraphQL allows you to specify a response query at the end of a mutation. This conveniently allows you to verify your mutation in the same call.
While we only showed how to make a single change to a monitor, mutations allow you to update or create monitors in bulk.
For much more detailed and advanced examples for your use case, please consult our various .
Having trouble? Reach out to us via email or in the #arize-support channel for more support.