[PR #15141] [MERGED] 9856 Replace graphene with Strawberry #14531

Closed
opened 2025-12-29 23:25:02 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/15141
Author: @arthanson
Created: 2/13/2024
Status: Merged
Merged: 3/22/2024
Merged by: @jeremystretch

Base: featureHead: 9856-strawberry-2


📝 Commits (10+)

📊 Changes

70 files changed (+97902 additions, -2410 deletions)

View changed files

📝 base_requirements.txt (+9 -10)
📝 docs/plugins/development/graphql-api.md (+22 -25)
netbox/circuits/graphql/filters.py (+50 -0)
📝 netbox/circuits/graphql/schema.py (+35 -36)
📝 netbox/circuits/graphql/types.py (+84 -34)
netbox/core/graphql/filters.py (+21 -0)
📝 netbox/core/graphql/schema.py (+14 -14)
📝 netbox/core/graphql/types.py (+22 -9)
netbox/dcim/graphql/filters.py (+294 -0)
📝 netbox/dcim/graphql/gfk_mixins.py (+3 -76)
📝 netbox/dcim/graphql/mixins.py (+37 -10)
📝 netbox/dcim/graphql/schema.py (+206 -245)
📝 netbox/dcim/graphql/types.py (+815 -306)
netbox/extras/graphql/filters.py (+98 -0)
📝 netbox/extras/graphql/mixins.py (+32 -19)
📝 netbox/extras/graphql/schema.py (+65 -75)
📝 netbox/extras/graphql/types.py (+167 -63)
netbox/ipam/graphql/filters.py (+119 -0)
netbox/ipam/graphql/gfk_mixins.py (+0 -95)
📝 netbox/ipam/graphql/mixins.py (+12 -9)

...and 50 more files

📄 Description

Fixes: #9856

Replaces django-graphene with strawberry-django a new engine for handling GraphQL queries. Notable changes:

  • Converts all GraphQL types to Strawberry Types
  • Includes much more updated GraphiQL browser
  • Decorator to auto-generate Strawberry required data-classes for filters as Strawberry doesn't support django-filter currently.

Example Queries:

{
  circuit_termination_list(filters: {cabled: false}) {
    id
    display
    cable {
      id
    }
  }
}

and

{
  location_list {
    image_attachments {
      id
    }
    contacts {
      id
    }
    changelog {
      id
    }
    display
    class_type
    tags {
      id
    }
    custom_fields
    id
    created
    last_updated
    custom_field_data
    name
    slug
    description
    site {
      id
    }
    status
    tenant {
      id
    }
    lft
    rght
    tree_id
    level
    children {
      id
    }
    powerpanel_set {
      id
    }
    cabletermination_set {
      id
    }
    racks {
      id
    }
    vlan_groups {
      id
    }
    parent {
      id
    }
    devices {
      id
    }
  }
}

Filtering lookups are different between the two libraries:

Graphene

user_list(is_superuser: true) {
    id
}

Strawberry

user_list(filters: {is_superuser: true}) {
   id
}

The filtering lookup syntax (greater than, less than, case-insensitive compare) is also different:
Graphene

{
  user_list(username__ic: "bob") {
    username
  }
}

Strawberry

{
  user_list(filters: {username: {i_contains: "bob"}}) {
    username
  }
}

For stawberry, allowing lookups on fields forces the lookup to be present, so it forces this somewhat awkward syntax:
Graphene

{
  user_list(id: "3") {
    id
  }
}

Strawberry

{
  user_list(filters: {id: {exact: 3}}) {
    id
  }
}

Performance optimizer

Below is a ridiculous nested query that can be used to show optimization

old graphene: 55 queries
strawberry: 24 queries

{
  location_list {
    image_attachments {
      id
    }
    contacts {
      id
    }
    changelog {
      id
    }
    display
    class_type
    tags {
      id
    }
    custom_fields
    id
    created
    last_updated
    custom_field_data
    name
    slug
    description
    site {
      id
      name
      locations {
        id
        name
      }
    }
    status
    tenant {
      id
      sites {
        id
        name
      }
    }
    lft
    rght
    tree_id
    level
    children {
      id
    }
    powerpanel_set {
      id
    }
    cabletermination_set {
      id
    }
    racks {
      id
      site {
        id
        name
      }
    }
    vlan_groups {
      id
    }
    parent {
      id
    }
    devices {
      id
    }
  }
}

🔄 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/15141 **Author:** [@arthanson](https://github.com/arthanson) **Created:** 2/13/2024 **Status:** ✅ Merged **Merged:** 3/22/2024 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `feature` ← **Head:** `9856-strawberry-2` --- ### 📝 Commits (10+) - [`3f2c21f`](https://github.com/netbox-community/netbox/commit/3f2c21f0059cdfe279cb294d662cc5e757e88f71) 9856 base strawberry integration - [`eceac90`](https://github.com/netbox-community/netbox/commit/eceac90b1c1acdf82263321ef736197ee4d02d88) 9856 user and group - [`700f015`](https://github.com/netbox-community/netbox/commit/700f01594219f82c0baf589b708002b4c46f3a2c) 9856 user and circuits base - [`46b0df4`](https://github.com/netbox-community/netbox/commit/46b0df43f9f893e7a6f2c3260c3c902be08a1c10) 9856 extras and mixins - [`36f57f8`](https://github.com/netbox-community/netbox/commit/36f57f8f08c5546f1d1d905065fc03b91edcef6e) 9856 fk - [`34d9b78`](https://github.com/netbox-community/netbox/commit/34d9b78d1969c307f5814f2998f27b4396e5e72c) 9856 merge feature - [`dbe4097`](https://github.com/netbox-community/netbox/commit/dbe4097a789b070ba0cd2073e83e9a766b2d1201) Merge branch 'feature' into 9856-strawberry-2 - [`de2d9ed`](https://github.com/netbox-community/netbox/commit/de2d9edbd4ab70ec2850c6627fe4adfc25267bd8) 9856 update strawberry version - [`7a222a6`](https://github.com/netbox-community/netbox/commit/7a222a650110139e12b2f41024417b003cae1da5) 9856 update imports - [`28c48b3`](https://github.com/netbox-community/netbox/commit/28c48b3d6c00912d8bfc39443cba277147a1aa98) 9856 compatability fixes ### 📊 Changes **70 files changed** (+97902 additions, -2410 deletions) <details> <summary>View changed files</summary> 📝 `base_requirements.txt` (+9 -10) 📝 `docs/plugins/development/graphql-api.md` (+22 -25) ➕ `netbox/circuits/graphql/filters.py` (+50 -0) 📝 `netbox/circuits/graphql/schema.py` (+35 -36) 📝 `netbox/circuits/graphql/types.py` (+84 -34) ➕ `netbox/core/graphql/filters.py` (+21 -0) 📝 `netbox/core/graphql/schema.py` (+14 -14) 📝 `netbox/core/graphql/types.py` (+22 -9) ➕ `netbox/dcim/graphql/filters.py` (+294 -0) 📝 `netbox/dcim/graphql/gfk_mixins.py` (+3 -76) 📝 `netbox/dcim/graphql/mixins.py` (+37 -10) 📝 `netbox/dcim/graphql/schema.py` (+206 -245) 📝 `netbox/dcim/graphql/types.py` (+815 -306) ➕ `netbox/extras/graphql/filters.py` (+98 -0) 📝 `netbox/extras/graphql/mixins.py` (+32 -19) 📝 `netbox/extras/graphql/schema.py` (+65 -75) 📝 `netbox/extras/graphql/types.py` (+167 -63) ➕ `netbox/ipam/graphql/filters.py` (+119 -0) ➖ `netbox/ipam/graphql/gfk_mixins.py` (+0 -95) 📝 `netbox/ipam/graphql/mixins.py` (+12 -9) _...and 50 more files_ </details> ### 📄 Description ### Fixes: #9856 Replaces django-graphene with strawberry-django a new engine for handling GraphQL queries. Notable changes: * Converts all GraphQL types to Strawberry Types * Includes much more updated GraphiQL browser * Decorator to auto-generate Strawberry required data-classes for filters as Strawberry doesn't support django-filter currently. Example Queries: ``` { circuit_termination_list(filters: {cabled: false}) { id display cable { id } } } ``` and ``` { location_list { image_attachments { id } contacts { id } changelog { id } display class_type tags { id } custom_fields id created last_updated custom_field_data name slug description site { id } status tenant { id } lft rght tree_id level children { id } powerpanel_set { id } cabletermination_set { id } racks { id } vlan_groups { id } parent { id } devices { id } } } ``` ### Filtering lookups are different between the two libraries: **Graphene** ``` user_list(is_superuser: true) { id } ``` **Strawberry** ``` user_list(filters: {is_superuser: true}) { id } ``` The filtering lookup syntax (greater than, less than, case-insensitive compare) is also different: **Graphene** ``` { user_list(username__ic: "bob") { username } } ``` **Strawberry** ``` { user_list(filters: {username: {i_contains: "bob"}}) { username } } ``` For stawberry, allowing lookups on fields forces the lookup to be present, so it forces this somewhat awkward syntax: **Graphene** ``` { user_list(id: "3") { id } } ``` **Strawberry** ``` { user_list(filters: {id: {exact: 3}}) { id } } ``` ## Performance optimizer Below is a ridiculous nested query that can be used to show optimization **old graphene:** 55 queries **strawberry:** 24 queries ``` { location_list { image_attachments { id } contacts { id } changelog { id } display class_type tags { id } custom_fields id created last_updated custom_field_data name slug description site { id name locations { id name } } status tenant { id sites { id name } } lft rght tree_id level children { id } powerpanel_set { id } cabletermination_set { id } racks { id site { id name } } vlan_groups { id } parent { id } devices { id } } } ``` --- <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-29 23:25:02 +01:00
adam closed this issue 2025-12-29 23:25:02 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#14531