Skip to content

Sub filters on GraphQL broken for some queries #15553

Closed
@arthanson

Description

@arthanson

Deployment Type

Self-hosted

NetBox Version

v4.0.0

Python Version

3.8

Steps to Reproduce

Found while updating the GraphQL docs for Strawberry. When the sub-field is defined as a function the filtering logic is not applied to it and therefore filtering logic won't work. For example the following query with sub-filter doesn't work:

{
  device_list {
    id
    name
    interfaces(filters: {enabled: {exact: true}}) {
      name
    }
  }
}

This is because it is defined as a function:

    @strawberry_django.field
    def interfaces(self) -> List[Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')]]:
        return self.interfaces.all()

If it is defined as a line type the filtering does work, but this will not work for fields that have to be defined as functions because the accessor is different:

    interfaces: List[Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')]]

Adding the filters directly to the decorator does not work either:

    @strawberry_django.field(filters=InterfaceFilter)

Expected Behavior

Filtering should work on all sub-objects

Observed Behavior

Filtering does not work on sub sub-objects.

Metadata

Metadata

Assignees

Labels

severity: mediumResults in substantial degraded or broken functionality for specfic workflowsstatus: acceptedThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the application

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions