Filter relationships in GraphQL queries #7199
dvaccarosenna
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, before GraphQL was added to NetBox, a team I had been working in looked at doing something similar via a Plugin/Fork.
Something we considered/required was the need to filter relationship values an object, rather than just the top level query.
For example, when retrieving sites you can currently retrieve the Racks for each Site as part of the same query:
In our use case, we would filter the list of Racks we retrieve for each Site.
I'm not sure if this is something typically implemented in GraphQL schemas but we've found it useful.
I'm wondering if there are any future plans to support similar functionality out-of-the-box or if there is any interest in a PR for an implementation of this?
This can be achieved by overriding each relationship field on the DjangoObjectType:
It's a bit laborious to do this for every single relationship on every type but I think we could add something to the BaseObjectType to automatically replace relationship list fields with the ObjectListField (which already provides the filtering).
Beta Was this translation helpful? Give feedback.
All reactions