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

query {
  node(id: "space_id") {
   ... on Space {
      name
    }
  }
}

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:

query {
  node(id: "space_id"){
    ... on Space {
      models(first: 2) {
        totalCount
        edges {
          cursor
          node {
            name
          } 
        }
      }
    }
  }
}

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 the totalCount 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 return edges. Edges are like a container for each element in the collection, and also contain metadata. In this case, we returned the cursor field on the edge, which can be used for pagination like this models(first:2, after: "YXJyYXljb25uZWN0aW9uOjE=").

  • node { name }: Finally, we get to the actual model and its fields. Note that most objects in our system implement the node interface (as described on the previous page). This particular node is of the type Model and has the field name which is the modelId 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.

query {
  node(id: "space_id"){
    ... on Space {
      models(first: 1) {
        edges {
          node {
            name
            monitors(first: 1, currentStatus: triggered) {
              edges {
                node {
                  name
                  threshold
                  currentMetricValue
                  operator
                }
              }
            }
          } 
        }
      }
    }
  }
}

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

Copyright © 2023 Arize AI, Inc