Skip to content

Commit 52b0555

Browse files
committed
Clean up typing for GraphQL types
1 parent 3a7edf3 commit 52b0555

File tree

10 files changed

+148
-46
lines changed

10 files changed

+148
-46
lines changed

netbox/circuits/graphql/types.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Annotated, List, Union
1+
from typing import Annotated, List, TYPE_CHECKING, Union
22

33
import strawberry
44
import strawberry_django
@@ -10,11 +10,15 @@
1010
from tenancy.graphql.types import TenantType
1111
from .filters import *
1212

13+
if TYPE_CHECKING:
14+
from dcim.graphql.types import InterfaceType, LocationType, RegionType, SiteGroupType, SiteType
15+
from ipam.graphql.types import ASNType
16+
1317
__all__ = (
14-
'CircuitTerminationType',
15-
'CircuitType',
1618
'CircuitGroupAssignmentType',
1719
'CircuitGroupType',
20+
'CircuitTerminationType',
21+
'CircuitType',
1822
'CircuitTypeType',
1923
'ProviderType',
2024
'ProviderAccountType',
@@ -62,7 +66,7 @@ class ProviderNetworkType(NetBoxObjectType):
6266

6367
@strawberry_django.type(
6468
models.CircuitTermination,
65-
exclude=('termination_type', 'termination_id', '_location', '_region', '_site', '_site_group', '_provider_network'),
69+
exclude=['termination_type', 'termination_id', '_location', '_region', '_site', '_site_group', '_provider_network'],
6670
filters=CircuitTerminationFilter
6771
)
6872
class CircuitTerminationType(CustomFieldsMixin, TagsMixin, CabledObjectMixin, ObjectType):
@@ -117,7 +121,7 @@ class CircuitGroupType(OrganizationalObjectType):
117121

118122
@strawberry_django.type(
119123
models.CircuitGroupAssignment,
120-
exclude=('member_type', 'member_id'),
124+
exclude=['member_type', 'member_id'],
121125
filters=CircuitGroupAssignmentFilter
122126
)
123127
class CircuitGroupAssignmentType(TagsMixin, BaseObjectType):

netbox/core/graphql/types.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
import strawberry
44
import strawberry_django
55
from django.contrib.contenttypes.models import ContentType as DjangoContentType
6+
67
from core import models
78
from netbox.graphql.types import BaseObjectType, NetBoxObjectType
89
from .filters import *
910

1011
__all__ = (
12+
'ContentType',
1113
'DataFileType',
1214
'DataSourceType',
1315
'ObjectChangeType',
14-
'ContentType',
1516
)
1617

1718

netbox/dcim/graphql/types.py

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,40 @@
1-
from typing import Annotated, List, Union
1+
from typing import Annotated, List, TYPE_CHECKING, Union
22

33
import strawberry
44
import strawberry_django
55

66
from core.graphql.mixins import ChangelogMixin
77
from dcim import models
88
from extras.graphql.mixins import (
9-
ConfigContextMixin, ContactsMixin, CustomFieldsMixin, ImageAttachmentsMixin, TagsMixin,
9+
ConfigContextMixin,
10+
ContactsMixin,
11+
CustomFieldsMixin,
12+
ImageAttachmentsMixin,
13+
TagsMixin,
1014
)
1115
from ipam.graphql.mixins import IPAddressesMixin, VLANGroupsMixin
1216
from netbox.graphql.scalars import BigInt
1317
from netbox.graphql.types import BaseObjectType, NetBoxObjectType, OrganizationalObjectType
1418
from .filters import *
1519
from .mixins import CabledObjectMixin, PathEndpointMixin
1620

21+
if TYPE_CHECKING:
22+
from circuits.graphql.types import CircuitTerminationType
23+
from extras.graphql.types import ConfigTemplateType
24+
from ipam.graphql.types import (
25+
ASNType,
26+
IPAddressType,
27+
PrefixType,
28+
ServiceType,
29+
VLANTranslationPolicyType,
30+
VLANType,
31+
VRFType,
32+
)
33+
from tenancy.graphql.types import TenantType
34+
from users.graphql.types import UserType
35+
from virtualization.graphql.types import ClusterType, VMInterfaceType, VirtualMachineType
36+
from wireless.graphql.types import WirelessLANType, WirelessLinkType
37+
1738
__all__ = (
1839
'CableType',
1940
'ComponentType',
@@ -111,7 +132,7 @@ class ModularComponentTemplateType(ComponentTemplateType):
111132

112133
@strawberry_django.type(
113134
models.CableTermination,
114-
exclude=('termination_type', 'termination_id', '_device', '_rack', '_location', '_site'),
135+
exclude=['termination_type', 'termination_id', '_device', '_rack', '_location', '_site'],
115136
filters=CableTerminationFilter
116137
)
117138
class CableTerminationType(NetBoxObjectType):
@@ -167,7 +188,7 @@ class CableType(NetBoxObjectType):
167188

168189
@strawberry_django.type(
169190
models.ConsolePort,
170-
exclude=('_path',),
191+
exclude=['_path'],
171192
filters=ConsolePortFilter
172193
)
173194
class ConsolePortType(ModularComponentType, CabledObjectMixin, PathEndpointMixin):
@@ -185,7 +206,7 @@ class ConsolePortTemplateType(ModularComponentTemplateType):
185206

186207
@strawberry_django.type(
187208
models.ConsoleServerPort,
188-
exclude=('_path',),
209+
exclude=['_path'],
189210
filters=ConsoleServerPortFilter
190211
)
191212
class ConsoleServerPortType(ModularComponentType, CabledObjectMixin, PathEndpointMixin):
@@ -276,7 +297,7 @@ class DeviceBayTemplateType(ComponentTemplateType):
276297

277298
@strawberry_django.type(
278299
models.InventoryItemTemplate,
279-
exclude=('component_type', 'component_id', 'parent'),
300+
exclude=['component_type', 'component_id', 'parent'],
280301
filters=InventoryItemTemplateFilter
281302
)
282303
class InventoryItemTemplateType(ComponentTemplateType):
@@ -369,7 +390,7 @@ class FrontPortTemplateType(ModularComponentTemplateType):
369390

370391
@strawberry_django.type(
371392
models.MACAddress,
372-
exclude=('assigned_object_type', 'assigned_object_id'),
393+
exclude=['assigned_object_type', 'assigned_object_id'],
373394
filters=MACAddressFilter
374395
)
375396
class MACAddressType(NetBoxObjectType):
@@ -385,7 +406,7 @@ def assigned_object(self) -> Annotated[Union[
385406

386407
@strawberry_django.type(
387408
models.Interface,
388-
exclude=('_path',),
409+
exclude=['_path'],
389410
filters=InterfaceFilter
390411
)
391412
class InterfaceType(IPAddressesMixin, ModularComponentType, CabledObjectMixin, PathEndpointMixin):
@@ -424,7 +445,7 @@ class InterfaceTemplateType(ModularComponentTemplateType):
424445

425446
@strawberry_django.type(
426447
models.InventoryItem,
427-
exclude=('component_type', 'component_id', 'parent'),
448+
exclude=['component_type', 'component_id', 'parent'],
428449
filters=InventoryItemFilter
429450
)
430451
class InventoryItemType(ComponentType):
@@ -463,7 +484,7 @@ class InventoryItemRoleType(OrganizationalObjectType):
463484
@strawberry_django.type(
464485
models.Location,
465486
# fields='__all__',
466-
exclude=('parent',), # bug - temp
487+
exclude=['parent'], # bug - temp
467488
filters=LocationFilter
468489
)
469490
class LocationType(VLANGroupsMixin, ImageAttachmentsMixin, ContactsMixin, OrganizationalObjectType):
@@ -524,7 +545,7 @@ class ModuleType(NetBoxObjectType):
524545
@strawberry_django.type(
525546
models.ModuleBay,
526547
# fields='__all__',
527-
exclude=('parent',),
548+
exclude=['parent'],
528549
filters=ModuleBayFilter
529550
)
530551
class ModuleBayType(ModularComponentType):
@@ -579,7 +600,7 @@ class PlatformType(OrganizationalObjectType):
579600

580601
@strawberry_django.type(
581602
models.PowerFeed,
582-
exclude=('_path',),
603+
exclude=['_path'],
583604
filters=PowerFeedFilter
584605
)
585606
class PowerFeedType(NetBoxObjectType, CabledObjectMixin, PathEndpointMixin):
@@ -590,7 +611,7 @@ class PowerFeedType(NetBoxObjectType, CabledObjectMixin, PathEndpointMixin):
590611

591612
@strawberry_django.type(
592613
models.PowerOutlet,
593-
exclude=('_path',),
614+
exclude=['_path'],
594615
filters=PowerOutletFilter
595616
)
596617
class PowerOutletType(ModularComponentType, CabledObjectMixin, PathEndpointMixin):
@@ -621,7 +642,7 @@ class PowerPanelType(NetBoxObjectType, ContactsMixin):
621642

622643
@strawberry_django.type(
623644
models.PowerPort,
624-
exclude=('_path',),
645+
exclude=['_path'],
625646
filters=PowerPortFilter
626647
)
627648
class PowerPortType(ModularComponentType, CabledObjectMixin, PathEndpointMixin):
@@ -712,8 +733,7 @@ class RearPortTemplateType(ModularComponentTemplateType):
712733

713734
@strawberry_django.type(
714735
models.Region,
715-
exclude=('parent',),
716-
# fields='__all__',
736+
exclude=['parent'],
717737
filters=RegionFilter
718738
)
719739
class RegionType(VLANGroupsMixin, ContactsMixin, OrganizationalObjectType):
@@ -772,8 +792,7 @@ def circuit_terminations(self) -> List[
772792

773793
@strawberry_django.type(
774794
models.SiteGroup,
775-
# fields='__all__',
776-
exclude=('parent',), # bug - temp
795+
exclude=['parent'], # bug - temp
777796
filters=SiteGroupFilter
778797
)
779798
class SiteGroupType(VLANGroupsMixin, ContactsMixin, OrganizationalObjectType):

netbox/extras/graphql/types.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Annotated, List
1+
from typing import Annotated, List, TYPE_CHECKING
22

33
import strawberry
44
import strawberry_django
@@ -8,6 +8,22 @@
88
from netbox.graphql.types import BaseObjectType, ContentTypeType, ObjectType, OrganizationalObjectType
99
from .filters import *
1010

11+
if TYPE_CHECKING:
12+
from core.graphql.types import DataFileType, DataSourceType
13+
from dcim.graphql.types import (
14+
DeviceRoleType,
15+
DeviceType,
16+
DeviceTypeType,
17+
LocationType,
18+
PlatformType,
19+
RegionType,
20+
SiteGroupType,
21+
SiteType,
22+
)
23+
from tenancy.graphql.types import TenantGroupType, TenantType
24+
from users.graphql.types import GroupType, UserType
25+
from virtualization.graphql.types import ClusterGroupType, ClusterType, ClusterTypeType, VirtualMachineType
26+
1127
__all__ = (
1228
'ConfigContextType',
1329
'ConfigTemplateType',
@@ -35,7 +51,6 @@
3551
class ConfigContextType(ObjectType):
3652
data_source: Annotated["DataSourceType", strawberry.lazy('core.graphql.types')] | None
3753
data_file: Annotated["DataFileType", strawberry.lazy('core.graphql.types')] | None
38-
3954
roles: List[Annotated["DeviceRoleType", strawberry.lazy('dcim.graphql.types')]]
4055
device_types: List[Annotated["DeviceTypeType", strawberry.lazy('dcim.graphql.types')]]
4156
tags: List[Annotated["TagType", strawberry.lazy('extras.graphql.types')]]
@@ -78,7 +93,7 @@ class CustomFieldType(ObjectType):
7893

7994
@strawberry_django.type(
8095
models.CustomFieldChoiceSet,
81-
exclude=('extra_choices', ),
96+
exclude=['extra_choices'],
8297
filters=CustomFieldChoiceSetFilter
8398
)
8499
class CustomFieldChoiceSetType(ObjectType):

netbox/ipam/graphql/types.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Annotated, List, Union
1+
from typing import Annotated, List, TYPE_CHECKING, Union
22

33
import strawberry
44
import strawberry_django
@@ -11,6 +11,21 @@
1111
from .filters import *
1212
from .mixins import IPAddressesMixin
1313

14+
if TYPE_CHECKING:
15+
from dcim.graphql.types import (
16+
DeviceType,
17+
InterfaceType,
18+
LocationType,
19+
RackType,
20+
RegionType,
21+
SiteGroupType,
22+
SiteType,
23+
)
24+
from tenancy.graphql.types import TenantType
25+
from virtualization.graphql.types import ClusterGroupType, ClusterType, VMInterfaceType, VirtualMachineType
26+
from vpn.graphql.types import L2VPNType, TunnelTerminationType
27+
from wireless.graphql.types import WirelessLANType
28+
1429
__all__ = (
1530
'ASNType',
1631
'ASNRangeType',
@@ -101,7 +116,7 @@ class FHRPGroupType(NetBoxObjectType, IPAddressesMixin):
101116

102117
@strawberry_django.type(
103118
models.FHRPGroupAssignment,
104-
exclude=('interface_type', 'interface_id'),
119+
exclude=['interface_type', 'interface_id'],
105120
filters=FHRPGroupAssignmentFilter
106121
)
107122
class FHRPGroupAssignmentType(BaseObjectType):
@@ -117,7 +132,7 @@ def interface(self) -> Annotated[Union[
117132

118133
@strawberry_django.type(
119134
models.IPAddress,
120-
exclude=('assigned_object_type', 'assigned_object_id', 'address'),
135+
exclude=['assigned_object_type', 'assigned_object_id', 'address'],
121136
filters=IPAddressFilter
122137
)
123138
class IPAddressType(NetBoxObjectType, BaseIPAddressFamilyType):
@@ -154,7 +169,7 @@ class IPRangeType(NetBoxObjectType):
154169

155170
@strawberry_django.type(
156171
models.Prefix,
157-
exclude=('scope_type', 'scope_id', '_location', '_region', '_site', '_site_group'),
172+
exclude=['scope_type', 'scope_id', '_location', '_region', '_site', '_site_group'],
158173
filters=PrefixFilter
159174
)
160175
class PrefixType(NetBoxObjectType, BaseIPAddressFamilyType):
@@ -236,7 +251,7 @@ class ServiceTemplateType(NetBoxObjectType):
236251

237252
@strawberry_django.type(
238253
models.VLAN,
239-
exclude=('qinq_svlan',),
254+
exclude=['qinq_svlan'],
240255
filters=VLANFilter
241256
)
242257
class VLANType(NetBoxObjectType):
@@ -259,7 +274,7 @@ def qinq_svlan(self) -> Annotated["VLANType", strawberry.lazy('ipam.graphql.type
259274

260275
@strawberry_django.type(
261276
models.VLANGroup,
262-
exclude=('scope_type', 'scope_id'),
277+
exclude=['scope_type', 'scope_id'],
263278
filters=VLANGroupFilter
264279
)
265280
class VLANGroupType(OrganizationalObjectType):

netbox/netbox/graphql/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
__all__ = (
1010
'BaseObjectType',
11+
'ContentTypeType',
1112
'ObjectType',
1213
'OrganizationalObjectType',
1314
'NetBoxObjectType',

0 commit comments

Comments
 (0)