Просмотр исходного кода

14511 Fix connected endpoints for GraphQL

Arthur 2 лет назад
Родитель
Сommit
c8fb948a91
2 измененных файлов с 42 добавлено и 3 удалено
  1. 41 2
      netbox/dcim/graphql/gfk_mixins.py
  2. 1 1
      netbox/dcim/graphql/mixins.py

+ 41 - 2
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

+ 1 - 1
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