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

Reverse GraphQL is not supported #450

Open
sirtux opened this issue Oct 22, 2024 · 5 comments
Open

Reverse GraphQL is not supported #450

sirtux opened this issue Oct 22, 2024 · 5 comments
Assignees
Labels
blocked This issue is blocked by another issue enhancement New feature or request

Comments

@sirtux
Copy link

sirtux commented Oct 22, 2024

Versions
NetBox Version: 4.1.4
NetBox DNS Version: 1.1.4
Python Version: 3.12.3

Describe the bug
When using the GraphQL API, I can only do forward searches, e.g.:

query { netbox_dns_nameserver_list { tenant { name } } }

however, the reverse is not availabe:

query { tenant_list { netbox_dns_nameserver { id } } }

To Reproduce
Steps to reproduce the behavior:

  1. Go to the GraphQL Editor
  2. Try the query: query { tenant_list { netbox_dns_nameserver { id } } }
  3. See error

Expected result
I expect to get a list for nameservers for each tenant.

Actual result
"Cannot query field 'netbox_dns_nameserver' on type 'TenantType'."

Thanks!

@peteeckel peteeckel self-assigned this Oct 22, 2024
@peteeckel
Copy link
Owner

Hi @sirtux,

that's actually an interesting one, though probably nothing I can do anything about.

First, let's look at the GraphQL docs for Tenant:
Screenshot 2024-10-22 at 12 27 48

Apparently there isn't an element for netbox_dns_nameserver (nor for any other of the plugin's models) in the list. The reason becomes apparent when you look at netbox/tenancy/graphql/types.py:

@strawberry_django.type(
    models.Tenant,
    fields='__all__',
    filters=TenantFilter
)
class TenantType(NetBoxObjectType):
    group: Annotated["TenantGroupType", strawberry.lazy('tenancy.graphql.types')] | None

    asns: List[Annotated["ASNType", strawberry.lazy('ipam.graphql.types')]]
    circuits: List[Annotated["CircuitType", strawberry.lazy('circuits.graphql.types')]]
    sites: List[Annotated["SiteType", strawberry.lazy('dcim.graphql.types')]]
    vlans: List[Annotated["VLANType", strawberry.lazy('ipam.graphql.types')]]
    wireless_lans: List[Annotated["WirelessLANType", strawberry.lazy('wireless.graphql.types')]]
    route_targets: List[Annotated["RouteTargetType", strawberry.lazy('ipam.graphql.types')]]
    locations: List[Annotated["LocationType", strawberry.lazy('dcim.graphql.types')]]
    ip_ranges: List[Annotated["IPRangeType", strawberry.lazy('ipam.graphql.types')]]
    rackreservations: List[Annotated["RackReservationType", strawberry.lazy('dcim.graphql.types')]]
    racks: List[Annotated["RackType", strawberry.lazy('dcim.graphql.types')]]
    vdcs: List[Annotated["VirtualDeviceContextType", strawberry.lazy('dcim.graphql.types')]]
    prefixes: List[Annotated["PrefixType", strawberry.lazy('ipam.graphql.types')]]
    cables: List[Annotated["CableType", strawberry.lazy('dcim.graphql.types')]]
    virtual_machines: List[Annotated["VirtualMachineType", strawberry.lazy('virtualization.graphql.types')]]
    vrfs: List[Annotated["VRFType", strawberry.lazy('ipam.graphql.types')]]
    asn_ranges: List[Annotated["ASNRangeType", strawberry.lazy('ipam.graphql.types')]]
    wireless_links: List[Annotated["WirelessLinkType", strawberry.lazy('wireless.graphql.types')]]
    aggregates: List[Annotated["AggregateType", strawberry.lazy('ipam.graphql.types')]]
    power_feeds: List[Annotated["PowerFeedType", strawberry.lazy('dcim.graphql.types')]]
    devices: List[Annotated["DeviceType", strawberry.lazy('dcim.graphql.types')]]
    tunnels: List[Annotated["TunnelType", strawberry.lazy('vpn.graphql.types')]]
    ip_addresses: List[Annotated["IPAddressType", strawberry.lazy('ipam.graphql.types')]]
    clusters: List[Annotated["ClusterType", strawberry.lazy('virtualization.graphql.types')]]
    l2vpns: List[Annotated["L2VPNType", strawberry.lazy('vpn.graphql.types')]]

So the list of related objects that can be referenced is apparently hard-coded.

The only way this could be solved would be to override the TenantType class from the plugin. I'm not sure this can currently be done.

@peteeckel
Copy link
Owner

I opened a NetBox FR, let's see what happens: netbox-community/netbox#17826

@peteeckel
Copy link
Owner

Turned out there is another issue with the same scope: netbox-community/netbox#17242

@peteeckel peteeckel added the enhancement New feature or request label Oct 22, 2024
@peteeckel peteeckel added the blocked This issue is blocked by another issue label Nov 5, 2024
@peteeckel
Copy link
Owner

peteeckel commented Jan 10, 2025

@sirtux netbox-community/netbox#17242 seems go gain momentum, so it might be a good moment to show interest in getting it fixed.

@peteeckel
Copy link
Owner

Update: This is now officially a NetBox bug: netbox-community/netbox#18435

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked This issue is blocked by another issue enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants