1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

14511 Fix connected endpoints for GraphQL

This commit is contained in:
Arthur
2024-01-24 14:22:35 -08:00
committed by Jeremy Stretch
parent a141f7f771
commit c8fb948a91
2 changed files with 42 additions and 3 deletions

View File

@ -1,6 +1,6 @@
import graphene import graphene
from circuits.graphql.types import CircuitTerminationType from circuits.graphql.types import CircuitTerminationType, ProviderNetworkType
from circuits.models import CircuitTermination from circuits.models import CircuitTermination, ProviderNetwork
from dcim.graphql.types import ( from dcim.graphql.types import (
ConsolePortTemplateType, ConsolePortTemplateType,
ConsolePortType, ConsolePortType,
@ -167,3 +167,42 @@ class InventoryItemComponentType(graphene.Union):
return PowerPortType return PowerPortType
if type(instance) is RearPort: if type(instance) is RearPort:
return RearPortType 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

View File

@ -13,7 +13,7 @@ class CabledObjectMixin:
class PathEndpointMixin: 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): def resolve_connected_endpoints(self, info):
# Handle empty values # Handle empty values