GraphQL: Add filter arguments at all levels #5882

Closed
opened 2025-12-29 19:33:49 +01:00 by adam · 5 comments
Owner

Originally created by @ryanmerolle on GitHub (Jan 5, 2022).

Originally assigned to: @arthanson on GitHub.

NetBox version

v3.1.4

Feature type

New functionality

Proposed functionality

Add filter arguments at all levels for GraphQL. Currently, it's only possible to define filter arguments at the top level.

Currently the below is supported:

{
  device_list(site: "MAD1") {
    id
    name
    site{
      name
    }
    interfaces {
      name
    }
  }
  interface_list(name:"eth0", site:"MAD1") {
    name
  }
}

Proposed functionality currently not supported, but common in most GraphQL setups:

{
  device_list(site: "MAD1") {
    id
    name
    site{
      name
    }
    interfaces(name: "eth0") {
      name
    }
  }
}

Use case

Have a more powerful query engine that will be able to return only the desired results by supporting GraphQL filter functionality commonly found in other deployments.

Database changes

None

External dependencies

None

Originally created by @ryanmerolle on GitHub (Jan 5, 2022). Originally assigned to: @arthanson on GitHub. ### NetBox version v3.1.4 ### Feature type New functionality ### Proposed functionality Add filter arguments at all levels for GraphQL. Currently, it's only possible to define filter arguments at the top level. **Currently the below is supported:** ```bash { device_list(site: "MAD1") { id name site{ name } interfaces { name } } interface_list(name:"eth0", site:"MAD1") { name } } ``` **Proposed functionality currently not supported, but common in most GraphQL setups:** ```bash { device_list(site: "MAD1") { id name site{ name } interfaces(name: "eth0") { name } } } ``` ### Use case Have a more powerful query engine that will be able to return only the desired results by supporting GraphQL filter functionality commonly found in other deployments. ### Database changes None ### External dependencies None
adam added the status: acceptedtype: feature labels 2025-12-29 19:33:49 +01:00
adam closed this issue 2025-12-29 19:33:50 +01:00
Author
Owner

@github-actions[bot] commented on GitHub (Mar 9, 2022):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our contributing guide.

@github-actions[bot] commented on GitHub (Mar 9, 2022): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@jeremystretch commented on GitHub (Jun 27, 2022):

Before investing any further effort into our implementation of graphene-django, it's worth considering alternative backends, as the project is apparently dead.

@jeremystretch commented on GitHub (Jun 27, 2022): Before investing any further effort into our implementation of `graphene-django`, it's worth considering alternative backends, as the project is [apparently dead](https://github.com/graphql-python/graphene-django/issues/1324).
Author
Owner

@jeremystretch commented on GitHub (Jul 27, 2022):

Blocked by #9856

@jeremystretch commented on GitHub (Jul 27, 2022): Blocked by #9856
Author
Owner

@arthanson commented on GitHub (Oct 4, 2022):

For filtering graphene is tied to Relay, this will make a couple changes to the output scheme and how you do queries:

  1. id's become 64 bit encoded
  2. lists show up as paginated edges with nodes.

For example:

{
  device_type_list {
    id
    instances(site: "dm-camden") {
      edges {
        node {
          id
          name
          site {
            id
            name
          }
        }
      }
    }
  }
}

instead of the current:

{
  device_type_list {
    id
    instances {
          id
          name
          site {
            id
            name
          }
    }
  }
}

output new query:

{
  "data": {
    "device_type_list": [
      {
        "id": "RGV2aWNlVHlwZVR5cGU6OA==",
        "instances": {
          "edges": [
            {
              "node": {
                "id": "RGV2aWNlVHlwZTozNw==",
                "name": "dmi01-camden-pdu01",
                "site": {
                  "id": "U2l0ZVR5cGU6Ng==",
                  "name": "DM-Camden"
                }
              }
            }
          ]
        }
      },
      {
        "id": "RGV2aWNlVHlwZVR5cGU6MTY=",
        "instances": {
          "edges": []
        }
      },

Also, have to debug (probably graphene bug?) it returns items that are empty (edges: []) with what you would normally expect. Changes to codebase are to the types.py files - re-arrange ordering and add an interface line to each type definition.

There is a package graphene-django-extras that we could pull a FilterListField (just pull in that field, not the whole package) that wouldn't require Relay but it would probably need some tweaks as it hasn't been updated for a year. Looking about 600 lines of code we would need to pickup from there in a couple different files.

@arthanson commented on GitHub (Oct 4, 2022): For filtering graphene is tied to Relay, this will make a couple changes to the output scheme and how you do queries: 1. id's become 64 bit encoded 2. lists show up as paginated edges with nodes. For example: ``` { device_type_list { id instances(site: "dm-camden") { edges { node { id name site { id name } } } } } } ``` instead of the current: ``` { device_type_list { id instances { id name site { id name } } } } ``` output new query: ``` { "data": { "device_type_list": [ { "id": "RGV2aWNlVHlwZVR5cGU6OA==", "instances": { "edges": [ { "node": { "id": "RGV2aWNlVHlwZTozNw==", "name": "dmi01-camden-pdu01", "site": { "id": "U2l0ZVR5cGU6Ng==", "name": "DM-Camden" } } } ] } }, { "id": "RGV2aWNlVHlwZVR5cGU6MTY=", "instances": { "edges": [] } }, ``` Also, have to debug (probably graphene bug?) it returns items that are empty (edges: []) with what you would normally expect. Changes to codebase are to the types.py files - re-arrange ordering and add an interface line to each type definition. There is a package graphene-django-extras that we could pull a FilterListField (just pull in that field, not the whole package) that wouldn't require Relay but it would probably need some tweaks as it hasn't been updated for a year. Looking about 600 lines of code we would need to pickup from there in a couple different files.
Author
Owner

@ryanmerolle commented on GitHub (Oct 4, 2022):

We discussed via chat an approach with less impact on the schema. @arthanson is exploring and will come back at his convenience.

As always, thanks @arthanson !

@ryanmerolle commented on GitHub (Oct 4, 2022): We discussed via chat an approach with less impact on the schema. @arthanson is exploring and will come back at his convenience. As always, thanks @arthanson !
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#5882