GraphQL filter by multiple custom fields #11821

Closed
opened 2025-12-29 21:50:17 +01:00 by adam · 4 comments
Owner

Originally created by @llamafilm on GitHub (Nov 10, 2025).

NetBox version

4.3.2

Feature type

New functionality

Proposed functionality

Currently GraphQL can filter by only one custom field. I would like to combine more than one.

Use case

In this case, I have a boolean CF indicating whether a device should be included in an external app. And a string CF containing its encrypted credentials. I want to get a list of devices where both of those fields are set. Below are two different queries that don't work. I'm not sure which of these is preferable.

{
  device_list(
    filters:{
      custom_field_data:{
        path:"encrypted_password",lookup:{string_lookup:{regex:".+"}}
      },
      custom_field_data:{
        path:"ptzcontrol",lookup:{boolean_lookup:{exact:true}}
      }
  }) {id}
}

Error: "There can be only one input field named 'custom_field_data'."

{
  device_list(
    filters:{
      custom_field_data:{
        path:"encrypted_password",lookup:{string_lookup:{regex:".+"}},
        path:"ptzcontrol",lookup:{boolean_lookup:{exact:true}}
      },
  }) {id}
}

Error: "There can be only one input field named 'path'."

Database changes

No response

External dependencies

No response

Originally created by @llamafilm on GitHub (Nov 10, 2025). ### NetBox version 4.3.2 ### Feature type New functionality ### Proposed functionality Currently GraphQL can filter by only one custom field. I would like to combine more than one. ### Use case In this case, I have a boolean CF indicating whether a device should be included in an external app. And a string CF containing its encrypted credentials. I want to get a list of devices where both of those fields are set. Below are two different queries that don't work. I'm not sure which of these is preferable. ``` { device_list( filters:{ custom_field_data:{ path:"encrypted_password",lookup:{string_lookup:{regex:".+"}} }, custom_field_data:{ path:"ptzcontrol",lookup:{boolean_lookup:{exact:true}} } }) {id} } ``` Error: "There can be only one input field named 'custom_field_data'." ``` { device_list( filters:{ custom_field_data:{ path:"encrypted_password",lookup:{string_lookup:{regex:".+"}}, path:"ptzcontrol",lookup:{boolean_lookup:{exact:true}} }, }) {id} } ``` Error: "There can be only one input field named 'path'." ### Database changes _No response_ ### External dependencies _No response_
adam added the type: featurenetbox labels 2025-12-29 21:50:17 +01:00
adam closed this issue 2025-12-29 21:50:17 +01:00
Author
Owner

@arthanson commented on GitHub (Nov 13, 2025):

@llamafilm have you tried using "AND", see: https://strawberry.rocks/docs/django/guide/filters

@arthanson commented on GitHub (Nov 13, 2025): @llamafilm have you tried using "AND", see: https://strawberry.rocks/docs/django/guide/filters
Author
Owner

@llamafilm commented on GitHub (Nov 13, 2025):

Thank you! I forgot about that, that works.

@llamafilm commented on GitHub (Nov 13, 2025): Thank you! I forgot about that, that works.
Author
Owner

@llamafilm commented on GitHub (Nov 22, 2025):

Actually I think this is still an issue. According to strawberry docs, I should be able to do a list-based AND filter like this, but Netbox fails with "Expected value of type 'DeviceFilter".

query {
  device_list(
    filters:{
      AND:[
        {custom_field_data:{path:"ptzcontrol",lookup:{boolean_lookup:{exact:true}}}},
        {custom_field_data:{path:"encrypted_password",lookup:{string_lookup:{regex:".+"}}}},
        {custom_field_data:{path:"location_served",lookup:{string_lookup:{regex:".+"}}}},
        {primary_ip4:{address:{is_null:false}}},
        {device_type:{manufacturer:{slug:{in_list:["sony","panasonic"]}}}}
      ]
    }) {id}
}

I'm not sure why that doesn't work. I can achieve the same result with the below query that does work, but it looks ugly when you stack multiple conditions like this.

query {
  device_list(
    filters:{
      custom_field_data:{path:"ptzcontrol",lookup:{boolean_lookup:{exact:true}}},
      AND: {
        custom_field_data:{path:"encrypted_password",lookup:{string_lookup:{regex:".+"}}}
        AND:{
          custom_field_data:{path:"location_served",lookup:{string_lookup:{regex:".+"}}}
        }
      }
      primary_ip4:{address:{is_null:false}},
      device_type:{manufacturer:{slug:{in_list:["sony","panasonic"]}}}
    }) {id}
  }
@llamafilm commented on GitHub (Nov 22, 2025): Actually I think this is still an issue. According to strawberry docs, I should be able to do a list-based AND filter like this, but Netbox fails with "Expected value of type 'DeviceFilter". ``` query { device_list( filters:{ AND:[ {custom_field_data:{path:"ptzcontrol",lookup:{boolean_lookup:{exact:true}}}}, {custom_field_data:{path:"encrypted_password",lookup:{string_lookup:{regex:".+"}}}}, {custom_field_data:{path:"location_served",lookup:{string_lookup:{regex:".+"}}}}, {primary_ip4:{address:{is_null:false}}}, {device_type:{manufacturer:{slug:{in_list:["sony","panasonic"]}}}} ] }) {id} } ``` I'm not sure why that doesn't work. I can achieve the same result with the below query that does work, but it looks ugly when you stack multiple conditions like this. ``` query { device_list( filters:{ custom_field_data:{path:"ptzcontrol",lookup:{boolean_lookup:{exact:true}}}, AND: { custom_field_data:{path:"encrypted_password",lookup:{string_lookup:{regex:".+"}}} AND:{ custom_field_data:{path:"location_served",lookup:{string_lookup:{regex:".+"}}} } } primary_ip4:{address:{is_null:false}}, device_type:{manufacturer:{slug:{in_list:["sony","panasonic"]}}} }) {id} } ```
Author
Owner

@jeremystretch commented on GitHub (Nov 24, 2025):

@llamafilm please understand that the documentation for Strawberry does not govern how NetBox itself functions. Strawberry is a framework and NetBox is an application which utilizes that framework. I'm sure there are many cases where we deviate from Strawberry convention to overcome limitations in the framework or for other reasons. The NetBox documentation ultimately dictates what is and is not supported in the application.

@jeremystretch commented on GitHub (Nov 24, 2025): @llamafilm please understand that the documentation for Strawberry does not govern how NetBox itself functions. Strawberry is a framework and NetBox is an application which utilizes that framework. I'm sure there are many cases where we deviate from Strawberry convention to overcome limitations in the framework or for other reasons. The NetBox documentation ultimately dictates what is and is not supported in the application.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11821