[PR #18618] [MERGED] Closes #7598: GraphQL Filter Redesign #15396

Closed
opened 2025-12-30 00:21:41 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/18618
Author: @jeremypng
Created: 2/11/2025
Status: Merged
Merged: 2/19/2025
Merged by: @jeremystretch

Base: 7598-graphql-custom-fieldsHead: graphql-filter-redesign


📝 Commits (5)

  • 999cae9 Closes #7598: GraphQL Filter Redesign
  • 03be7d2 Update netbox/netbox/tests/test_graphql.py
  • 489b084 cleanup enums, enable strawberry-django optimizer, extra line
  • e3e2e5d removing commented enum
  • cfa8291 moving filter_lookups.py to netbox/graphql

📊 Changes

33 files changed (+4465 additions, -633 deletions)

View changed files

netbox/circuits/graphql/enums.py (+86 -0)
netbox/circuits/graphql/filter_mixins.py (+17 -0)
📝 netbox/circuits/graphql/filters.py (+159 -34)
netbox/core/graphql/filter_mixins.py (+31 -0)
📝 netbox/core/graphql/filters.py (+74 -9)
📝 netbox/core/graphql/mixins.py (+4 -1)
📝 netbox/core/graphql/types.py (+7 -1)
netbox/dcim/graphql/enums.py (+848 -0)
netbox/dcim/graphql/filter_mixins.py (+138 -0)
📝 netbox/dcim/graphql/filters.py (+671 -129)
netbox/extras/graphql/enums.py (+188 -0)
netbox/extras/graphql/filter_mixins.py (+53 -0)
📝 netbox/extras/graphql/filters.py (+242 -41)
netbox/ipam/graphql/enums.py (+123 -0)
netbox/ipam/graphql/filter_mixins.py (+22 -0)
📝 netbox/ipam/graphql/filters.py (+282 -57)
netbox/netbox/graphql/enums.py (+112 -0)
netbox/netbox/graphql/filter_lookups.py (+218 -0)
📝 netbox/netbox/graphql/filter_mixins.py (+109 -204)
📝 netbox/netbox/settings.py (+0 -1)

...and 13 more files

📄 Description

Fixes: #7598

GraphQL rewrite with statically defined filters for each GraphQL Filter. This moves away from the DEPRECATED_FILTERS flag and gets rid of the autotype_decorator and allows strongly typed filters, enums, and custom filters like JSON and TreeNode searches. I've tried to follow idiomatic design from a GraphQL perspective. This attempts to be feature complete from a pure data model perspective, but there is plenty of room to add more business logic filters similar to the parent filters on IPRange and IPAddress that are part of this PR. It allows you to walk the data model, but does not try to replace the full functionality of the DRF API.

New query syntax for custom fields:

query GetTenants {
  tenant_list (filters: {custom_field_data: {path: "cust_id", lookup: {string_lookup: {exact:"YKY01"}}}}) {
    id
    name
    custom_field_data
  }
}

results:

{
  "data": {
    "tenant_list": [
      {
        "id": "9",
        "name": "Nakatomi Corportation",
        "custom_field_data": {
          "cust_id": "YKY01"
        }
      }
    ]
  }

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/18618 **Author:** [@jeremypng](https://github.com/jeremypng) **Created:** 2/11/2025 **Status:** ✅ Merged **Merged:** 2/19/2025 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `7598-graphql-custom-fields` ← **Head:** `graphql-filter-redesign` --- ### 📝 Commits (5) - [`999cae9`](https://github.com/netbox-community/netbox/commit/999cae939e0caabf8e8e3630c9705ac59252a6cb) Closes #7598: GraphQL Filter Redesign - [`03be7d2`](https://github.com/netbox-community/netbox/commit/03be7d2966eddc14c7240250a31857ebe228ecfd) Update netbox/netbox/tests/test_graphql.py - [`489b084`](https://github.com/netbox-community/netbox/commit/489b0841ab7478679e943512ad24f9ab5f2508df) cleanup enums, enable strawberry-django optimizer, extra line - [`e3e2e5d`](https://github.com/netbox-community/netbox/commit/e3e2e5d5992e4f521d516bcc815312ab017843ad) removing commented enum - [`cfa8291`](https://github.com/netbox-community/netbox/commit/cfa8291919c83fbde2e7aa57d68c6f9107855ac7) moving filter_lookups.py to netbox/graphql ### 📊 Changes **33 files changed** (+4465 additions, -633 deletions) <details> <summary>View changed files</summary> ➕ `netbox/circuits/graphql/enums.py` (+86 -0) ➕ `netbox/circuits/graphql/filter_mixins.py` (+17 -0) 📝 `netbox/circuits/graphql/filters.py` (+159 -34) ➕ `netbox/core/graphql/filter_mixins.py` (+31 -0) 📝 `netbox/core/graphql/filters.py` (+74 -9) 📝 `netbox/core/graphql/mixins.py` (+4 -1) 📝 `netbox/core/graphql/types.py` (+7 -1) ➕ `netbox/dcim/graphql/enums.py` (+848 -0) ➕ `netbox/dcim/graphql/filter_mixins.py` (+138 -0) 📝 `netbox/dcim/graphql/filters.py` (+671 -129) ➕ `netbox/extras/graphql/enums.py` (+188 -0) ➕ `netbox/extras/graphql/filter_mixins.py` (+53 -0) 📝 `netbox/extras/graphql/filters.py` (+242 -41) ➕ `netbox/ipam/graphql/enums.py` (+123 -0) ➕ `netbox/ipam/graphql/filter_mixins.py` (+22 -0) 📝 `netbox/ipam/graphql/filters.py` (+282 -57) ➕ `netbox/netbox/graphql/enums.py` (+112 -0) ➕ `netbox/netbox/graphql/filter_lookups.py` (+218 -0) 📝 `netbox/netbox/graphql/filter_mixins.py` (+109 -204) 📝 `netbox/netbox/settings.py` (+0 -1) _...and 13 more files_ </details> ### 📄 Description <!-- Thank you for your interest in contributing to NetBox! Please note that our contribution policy requires that a feature request or bug report be approved and assigned prior to opening a pull request. This helps avoid waste time and effort on a proposed change that we might not be able to accept. IF YOUR PULL REQUEST DOES NOT REFERENCE AN ISSUE WHICH HAS BEEN ASSIGNED TO YOU, IT WILL BE CLOSED AUTOMATICALLY. Please specify your assigned issue number on the line below. --> ### Fixes: #7598 <!-- Please include a summary of the proposed changes below. --> GraphQL rewrite with statically defined filters for each GraphQL Filter. This moves away from the DEPRECATED_FILTERS flag and gets rid of the autotype_decorator and allows strongly typed filters, enums, and custom filters like JSON and TreeNode searches. I've tried to follow idiomatic design from a GraphQL perspective. This attempts to be feature complete from a pure data model perspective, but there is plenty of room to add more business logic filters similar to the parent filters on IPRange and IPAddress that are part of this PR. It allows you to walk the data model, but does not try to replace the full functionality of the DRF API. New query syntax for custom fields: ```graphql query GetTenants { tenant_list (filters: {custom_field_data: {path: "cust_id", lookup: {string_lookup: {exact:"YKY01"}}}}) { id name custom_field_data } } ``` results: ```json { "data": { "tenant_list": [ { "id": "9", "name": "Nakatomi Corportation", "custom_field_data": { "cust_id": "YKY01" } } ] } ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-30 00:21:41 +01:00
adam closed this issue 2025-12-30 00:21:41 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#15396