Querying Nested Data
This tutorial will show you how to query for nested data and collections
Now that you know how to form basic queries using the node
concept from the previous page, we will show you how to query nested collections of data. This is a very powerful concept that will allow you to quickly traverse the data objects in Arize without stopping to gather id's at every step.
This example will show you how to find all of the triggered monitors and their models within your space. The benefit of GraphQL is that the skills you learn in this tutorial will apply to all other object relationships.
We highly recommend that you type out these examples (with your own IDs) in the API explorer directly.
The explorer helps with autocompletion and will help you contextualize your queries. In the explorer, navigate to the Documentation Explorer on the right to find the exact fields for each object.
Querying collections
1. Start with the space
Grab your node id for you space from the browser (e.x. /spaces/:
space_id
), as described in the previous section
2. Get the model connection in your space:
Now, let's get the models for your space. There is a models
property on space. This returns an edge, which is a container for the actual model (which is considered a node
). There is a lot to unpack here, but first we'll show the example:
Here are the components:
models(first: 2){ totalCount }
:models
returns a connection. A connection can be thought of as a "container" for a collection of results as well as metadata. In this example, we requested thetotalCount
of the collection. Connections also can take arguments. Here we only request the first 2 models. There are also custom arguments or filters in addition to standard pagination-related arguments, for example:models(search: "arize-demo")
.edges { cursor }
: Connections returnedges
. Edges are like a container for each element in the collection, and also contain metadata. In this case, we returned thecursor
field on the edge, which can be used for pagination like thismodels(first:2, after: "YXJyYXljb25uZWN0aW9uOjE=")
.node { name }
: Finally, we get to the actual model and its fields. Note that most objects in our system implement thenode
interface (as described on the previous page). This particular node is of the typeModel
and has the fieldname
which is themodelId
that was used to ingest the model.
3. Get only triggered monitors
Finally, we can go one level deeper and get the monitors on each model. Additionally, we'll use the arguments to filter only for triggered models.
Note: you can also query for monitors on a space. We are just using space -> models to as an example of a deeply nested query. This is also helpful if you wanted to search for specific models in a space before getting their monitors.
Here we use the argument monitors(currentStatus: triggered)
(note triggered is not a string, it is an enum and should not be in quotes) to denote that we only want to view triggered monitors. Now we can view the operator, the current value of the metric and the threshold, and the current threshold.
What's next?
After you get more comfortable querying for collections and using the Documentation Explorer, you'll be querying the rest of your data in no time.
In the next section, we'll show you how to update your data through mutations
.
Having trouble? Reach out to us via email support@arize.com or Slack us in the #arize-support channel for more support.
Last updated