Description
Deployment Type
Self-hosted
NetBox Version
v4.3.0-beta1
Python Version
3.12
Steps to Reproduce
- Attempt to write a GraphQL query to filter
circuit_list
by 1 or more sites. Or filter anip_address_list
by the device or VM they belong to.
Expected Behavior
Filters exist to filter circuits by the site one of their terminations belongs to, filters exist to filter IP addresses based on the device or virtual machine they're attached to.
Example query for circuits based on site entries that works pre-4.2:
query siteCircuits($sites: [String!]) {
circuit_list(filters: {site: $sites}) {
id
cid
provider {
name
}
termination_z {
termination {
... on SiteType {
id
name
}
}
}
}
}
The $sites
variable is:
{
"sites": [
"dm-albany",
"dm-rochester"
]
}
Observed Behavior
No filters exist to do this on IPAddress or Circuit filter options in GraphQL in 4.3-beta1.
For circuits, the closest I can get is 'reversing' the query and querying circuit terminations instead.
query MyQuery {
circuit_termination_list(
filters: {termination_type: {app_label: {exact: "dcim"}, model: {exact: "site"}}, termination_id: "7"}
) {
termination {
... on SiteType {
id
name
}
}
term_side
circuit {
cid
commit_rate
install_date
id
provider {
id
name
}
provider_account {
account
id
name
}
}
}
}
However: this requires the NetBox ID of the site to be known (instead of being able to use the slug today), and the only way to filter on multiple related-object IDs is to do a verbose "OR" operator instead of being able to do termination_id: {in_list: [1, 2, 3, 4]}
(for circuit terminations, not circuits).
In the case of IP Addresses you can't even do a filter such as assigned_object_id: {in_list: [1, 2, 3, 4]}
(for IP Addresses) using multiple interface IDs from a single device.
As has always been the case since GraphQL was introduced, you could write a more "indirect" query starting with the device_list, and adding interfaces for the device, and each interface's IP Addresses nested within, but this is a significant change from previous behavior and also limits the flexibility & functionality of the GraphQL API.
There maybe be other GraphQL objects that are impacted, these are just the two most immediate cases that I've uncovered. Not being able to filter by multiple IDs (even using standard GraphQL syntax of "some_object_id: {in_list: [1, 2, 3, 4]}
") is a big hindrance, but being able to filter by indirect relationships is very valuable and is how the NetBox GraphQL API has worked for quite a while now.