Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ryanmerolle opened this issue Jul 21, 2022 · 4 comments
Closed

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

ryanmerolle opened this issue Jul 21, 2022 · 4 comments
Assignees
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Milestone

Comments

@ryanmerolle
Copy link
Contributor

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

@ryanmerolle ryanmerolle added the type: feature Introduction of new functionality to the application label Jul 21, 2022
@jeremystretch jeremystretch changed the title [Feature]: Add assigned_object models in GraphQL API similar to the REST API Add assigned_object models in GraphQL API similar to the REST API Jul 21, 2022
@ryanmerolle
Copy link
Contributor Author

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

@jeremystretch
Copy link
Member

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
Copy link
Member

Blocked by #9856

@jeremystretch jeremystretch added the status: blocked Another issue or external requirement is preventing implementation label Aug 22, 2022
@jeremystretch jeremystretch added status: under review Further discussion is needed to determine this issue's scope and/or implementation and removed status: blocked Another issue or external requirement is preventing implementation labels Sep 27, 2022
@arthanson arthanson self-assigned this Oct 4, 2022
@arthanson
Copy link
Collaborator

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.

@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed status: under review Further discussion is needed to determine this issue's scope and/or implementation labels Oct 11, 2022
@jeremystretch jeremystretch added this to the v3.4 milestone Oct 11, 2022
jeremystretch added a commit that referenced this issue Oct 11, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Projects
None yet
Development

No branches or pull requests

3 participants