Add assigned_object models in GraphQL API similar to the REST API #6704

Closed
opened 2025-12-29 19:44:12 +01:00 by adam · 4 comments
Owner

Originally created by @ryanmerolle on GitHub (Jul 21, 2022).

Originally assigned to: @arthanson on GitHub.

NetBox version

v3.3-beta

Feature type

Change to existing functionality

Proposed functionality

As an example, currently you can only query:

{
  l2vpn_termination_list {
    assigned_object_type {
      model
    }
    assigned_object_id
  }
}

and it returns:

{
  "data": {
    "l2vpn_termination_list": [
      {
        "assigned_object_type": {
          "model": "interface"
        },
        "assigned_object_id": 1170
      }
    ]
  }
}

Where the rest api allows you to query the same model and get the assigned_object back:

{
  "count": 1,
  "next": null,
  "previous": null,
  "results": [
    {
      "id": 1,
      "url": "https://beta-demo.netbox.dev/api/ipam/l2vpn-terminations/1/",
      "display": "et-2/0/49 <> Test",
      "l2vpn": {
        "id": 1,
        "url": "https://beta-demo.netbox.dev/api/ipam/l2vpns/1/",
        "display": "Test",
        "identifier": null,
        "name": "Test",
        "slug": "test",
        "type": "vxlan-evpn"
      },
      "assigned_object_type": "dcim.interface",
      "assigned_object_id": 1170,
      "assigned_object": {
        "id": 1170,
        "url": "https://beta-demo.netbox.dev/api/dcim/interfaces/1170/",
        "display": "et-2/0/49",
        "device": {
          "id": 99,
          "url": "https://beta-demo.netbox.dev/api/dcim/devices/99/",
          "display": "r105-torsw:2 (99)",
          "name": null
        },
        "name": "et-2/0/49",
        "cable": null,
        "_occupied": false
      },
      "tags": [],
      "custom_fields": {},
      "created": "2022-07-21T09:45:29.104279Z",
      "last_updated": "2022-07-21T09:45:29.104304Z"
    }
  ]

It would be ideal that all usage of any assigned_object/assigned_object_type approach would update the graphql api to return the assigned_object.

Use case

rest and graphql feature parity.

Database changes

No response

External dependencies

No response

Originally created by @ryanmerolle on GitHub (Jul 21, 2022). Originally assigned to: @arthanson on GitHub. ### NetBox version v3.3-beta ### Feature type Change to existing functionality ### Proposed functionality As an example, currently you can only query: ``` { l2vpn_termination_list { assigned_object_type { model } assigned_object_id } } ``` and it returns: ```json { "data": { "l2vpn_termination_list": [ { "assigned_object_type": { "model": "interface" }, "assigned_object_id": 1170 } ] } } ``` Where the rest api allows you to query the same model and get the assigned_object back: ```json { "count": 1, "next": null, "previous": null, "results": [ { "id": 1, "url": "https://beta-demo.netbox.dev/api/ipam/l2vpn-terminations/1/", "display": "et-2/0/49 <> Test", "l2vpn": { "id": 1, "url": "https://beta-demo.netbox.dev/api/ipam/l2vpns/1/", "display": "Test", "identifier": null, "name": "Test", "slug": "test", "type": "vxlan-evpn" }, "assigned_object_type": "dcim.interface", "assigned_object_id": 1170, "assigned_object": { "id": 1170, "url": "https://beta-demo.netbox.dev/api/dcim/interfaces/1170/", "display": "et-2/0/49", "device": { "id": 99, "url": "https://beta-demo.netbox.dev/api/dcim/devices/99/", "display": "r105-torsw:2 (99)", "name": null }, "name": "et-2/0/49", "cable": null, "_occupied": false }, "tags": [], "custom_fields": {}, "created": "2022-07-21T09:45:29.104279Z", "last_updated": "2022-07-21T09:45:29.104304Z" } ] ``` It would be ideal that all usage of any assigned_object/assigned_object_type approach would update the graphql api to return the assigned_object. ### Use case rest and graphql feature parity. ### Database changes _No response_ ### External dependencies _No response_
adam added the status: acceptedtype: feature labels 2025-12-29 19:44:12 +01:00
adam closed this issue 2025-12-29 19:44:12 +01:00
Author
Owner

@ryanmerolle commented on GitHub (Jul 21, 2022):

Unfortunately it looks like it is not supported as is with graphen-django

This looks like a valid approach:
https://stackoverflow.com/questions/56146966/is-there-a-way-to-get-graphene-to-work-with-django-genericrelation-field/69482585#69482585

@ryanmerolle commented on GitHub (Jul 21, 2022): Unfortunately it looks like it is not supported as is with graphen-django - graphql-python/graphene-django#11 This looks like a valid approach: https://stackoverflow.com/questions/56146966/is-there-a-way-to-get-graphene-to-work-with-django-genericrelation-field/69482585#69482585
Author
Owner

@jeremystretch commented on GitHub (Jul 21, 2022):

Unfortunately it looks like it is not supported as is with graphene-django

Given that graphene-django is no longer maintained, we'll likely be moving to an alternate implementation in a future release anyway.

@jeremystretch commented on GitHub (Jul 21, 2022): > Unfortunately it looks like it is not supported as is with graphene-django Given that graphene-django is no longer maintained, we'll likely be moving to an alternate implementation in a future release anyway.
Author
Owner

@jeremystretch commented on GitHub (Aug 22, 2022):

Blocked by #9856

@jeremystretch commented on GitHub (Aug 22, 2022): Blocked by #9856
Author
Owner

@arthanson commented on GitHub (Oct 4, 2022):

Using a UnionType looks like the preferred method - The Graphene docs has it in their test cases but not very clear, this https://wagtail.org/blog/graphql-with-streamfield/ is a fairly good example. Will implement with this pattern.

@arthanson commented on GitHub (Oct 4, 2022): Using a UnionType looks like the preferred method - The Graphene docs has it in their test cases but not very clear, this https://wagtail.org/blog/graphql-with-streamfield/ is a fairly good example. Will implement with this pattern.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6704