GraphQL Ordering Support #11517

Open
opened 2025-12-29 21:46:18 +01:00 by adam · 2 comments
Owner

Originally created by @sleepinggenius2 on GitHub (Aug 21, 2025).

NetBox version

v4.3.6

Feature type

New functionality

Proposed functionality

With the implementation of pagination in #16224, I thought that might have also introduced ordering, but that does not seem to be the case. Therefore, I propose ordering as an additional argument alongside filters and pagination when accessing non-scalar types. It would work the same as the ordering argument in the REST API, but should probably be turned into an array of strings instead of a single comma-separated string.

Use case

I need to pull nested data from NetBox and using the REST API does not allow that without N+1 queries. Initially, I wrote an export template to solve this problem, but as the output format needs to be JSON, that started becoming tedious, so I decided to explore the possibility of using GraphQL instead. It ended up being fairly straightforward to get the shape of the data I needed, but I was disappointed to find that ordering was not possible. In my case, I am grabbing the members of a virtual chassis and I need them in order of vc_position, not name, as they seem to be by default. My hope was that I could unmarshal the JSON response directly without additional processing.

Database changes

None

External dependencies

None

Originally created by @sleepinggenius2 on GitHub (Aug 21, 2025). ### NetBox version v4.3.6 ### Feature type New functionality ### Proposed functionality With the implementation of pagination in #16224, I thought that might have also introduced ordering, but that does not seem to be the case. Therefore, I propose `ordering` as an additional argument alongside `filters` and `pagination` when accessing non-scalar types. It would work the same as the `ordering` argument in the REST API, but should probably be turned into an array of strings instead of a single comma-separated string. ### Use case I need to pull nested data from NetBox and using the REST API does not allow that without N+1 queries. Initially, I wrote an export template to solve this problem, but as the output format needs to be JSON, that started becoming tedious, so I decided to explore the possibility of using GraphQL instead. It ended up being fairly straightforward to get the shape of the data I needed, but I was disappointed to find that ordering was not possible. In my case, I am grabbing the members of a virtual chassis and I need them in order of `vc_position`, not `name`, as they seem to be by default. My hope was that I could unmarshal the JSON response directly without additional processing. ### Database changes None ### External dependencies None
Author
Owner

@arthanson commented on GitHub (Aug 22, 2025):

Strawberry does have ordering support https://strawberry.rocks/docs/django/guide/ordering this would be a fairly substantial change as ordering enum and input would need to be be defined for all model types.

@arthanson commented on GitHub (Aug 22, 2025): Strawberry does have ordering support https://strawberry.rocks/docs/django/guide/ordering this would be a fairly substantial change as ordering enum and input would need to be be defined for all model types.
Author
Owner

@jeremystretch commented on GitHub (Aug 28, 2025):

I think we have a fairly good understanding of what this entails, however it's still to be determined whether this could effect a breaking change.

@jeremystretch commented on GitHub (Aug 28, 2025): I think we have a fairly good understanding of what this entails, however it's still to be determined whether this could effect a breaking change.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11517