From c8fb948a91c73586d3ebf9f5aa2b01cf54632fae Mon Sep 17 00:00:00 2001 From: Arthur Date: Wed, 24 Jan 2024 14:22:35 -0800 Subject: [PATCH] 14511 Fix connected endpoints for GraphQL --- netbox/dcim/graphql/gfk_mixins.py | 43 +++++++++++++++++++++++++++++-- netbox/dcim/graphql/mixins.py | 2 +- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/netbox/dcim/graphql/gfk_mixins.py b/netbox/dcim/graphql/gfk_mixins.py index c97aa4c2b..2f669fb87 100644 --- a/netbox/dcim/graphql/gfk_mixins.py +++ b/netbox/dcim/graphql/gfk_mixins.py @@ -1,6 +1,6 @@ import graphene -from circuits.graphql.types import CircuitTerminationType -from circuits.models import CircuitTermination +from circuits.graphql.types import CircuitTerminationType, ProviderNetworkType +from circuits.models import CircuitTermination, ProviderNetwork from dcim.graphql.types import ( ConsolePortTemplateType, ConsolePortType, @@ -167,3 +167,42 @@ class InventoryItemComponentType(graphene.Union): return PowerPortType if type(instance) is RearPort: return RearPortType + + +class ConnectedEndpointType(graphene.Union): + class Meta: + types = ( + CircuitTerminationType, + ConsolePortType, + ConsoleServerPortType, + FrontPortType, + InterfaceType, + PowerFeedType, + PowerOutletType, + PowerPortType, + ProviderNetworkType, + RearPortType, + ) + + @classmethod + def resolve_type(cls, instance, info): + if type(instance) is CircuitTermination: + return CircuitTerminationType + if type(instance) is ConsolePortType: + return ConsolePortType + if type(instance) is ConsoleServerPort: + return ConsoleServerPortType + if type(instance) is FrontPort: + return FrontPortType + if type(instance) is Interface: + return InterfaceType + if type(instance) is PowerFeed: + return PowerFeedType + if type(instance) is PowerOutlet: + return PowerOutletType + if type(instance) is PowerPort: + return PowerPortType + if type(instance) is ProviderNetwork: + return ProviderNetworkType + if type(instance) is RearPort: + return RearPortType diff --git a/netbox/dcim/graphql/mixins.py b/netbox/dcim/graphql/mixins.py index f8e626fe8..8241b7de5 100644 --- a/netbox/dcim/graphql/mixins.py +++ b/netbox/dcim/graphql/mixins.py @@ -13,7 +13,7 @@ class CabledObjectMixin: class PathEndpointMixin: - connected_endpoints = graphene.List('dcim.graphql.gfk_mixins.LinkPeerType') + connected_endpoints = graphene.List('dcim.graphql.gfk_mixins.ConnectedEndpointType') def resolve_connected_endpoints(self, info): # Handle empty values