Clean up typing for GraphQL types

This commit is contained in:
Jeremy Stretch 2025-03-07 11:24:11 -05:00
parent 3a7edf3c0a
commit 52b0555940
10 changed files with 148 additions and 46 deletions

View File

@ -1,4 +1,4 @@
from typing import Annotated, List, Union from typing import Annotated, List, TYPE_CHECKING, Union
import strawberry import strawberry
import strawberry_django import strawberry_django
@ -10,11 +10,15 @@ from netbox.graphql.types import BaseObjectType, NetBoxObjectType, ObjectType, O
from tenancy.graphql.types import TenantType from tenancy.graphql.types import TenantType
from .filters import * from .filters import *
if TYPE_CHECKING:
from dcim.graphql.types import InterfaceType, LocationType, RegionType, SiteGroupType, SiteType
from ipam.graphql.types import ASNType
__all__ = ( __all__ = (
'CircuitTerminationType',
'CircuitType',
'CircuitGroupAssignmentType', 'CircuitGroupAssignmentType',
'CircuitGroupType', 'CircuitGroupType',
'CircuitTerminationType',
'CircuitType',
'CircuitTypeType', 'CircuitTypeType',
'ProviderType', 'ProviderType',
'ProviderAccountType', 'ProviderAccountType',
@ -62,7 +66,7 @@ class ProviderNetworkType(NetBoxObjectType):
@strawberry_django.type( @strawberry_django.type(
models.CircuitTermination, models.CircuitTermination,
exclude=('termination_type', 'termination_id', '_location', '_region', '_site', '_site_group', '_provider_network'), exclude=['termination_type', 'termination_id', '_location', '_region', '_site', '_site_group', '_provider_network'],
filters=CircuitTerminationFilter filters=CircuitTerminationFilter
) )
class CircuitTerminationType(CustomFieldsMixin, TagsMixin, CabledObjectMixin, ObjectType): class CircuitTerminationType(CustomFieldsMixin, TagsMixin, CabledObjectMixin, ObjectType):
@ -117,7 +121,7 @@ class CircuitGroupType(OrganizationalObjectType):
@strawberry_django.type( @strawberry_django.type(
models.CircuitGroupAssignment, models.CircuitGroupAssignment,
exclude=('member_type', 'member_id'), exclude=['member_type', 'member_id'],
filters=CircuitGroupAssignmentFilter filters=CircuitGroupAssignmentFilter
) )
class CircuitGroupAssignmentType(TagsMixin, BaseObjectType): class CircuitGroupAssignmentType(TagsMixin, BaseObjectType):

View File

@ -3,15 +3,16 @@ from typing import Annotated, List
import strawberry import strawberry
import strawberry_django import strawberry_django
from django.contrib.contenttypes.models import ContentType as DjangoContentType from django.contrib.contenttypes.models import ContentType as DjangoContentType
from core import models from core import models
from netbox.graphql.types import BaseObjectType, NetBoxObjectType from netbox.graphql.types import BaseObjectType, NetBoxObjectType
from .filters import * from .filters import *
__all__ = ( __all__ = (
'ContentType',
'DataFileType', 'DataFileType',
'DataSourceType', 'DataSourceType',
'ObjectChangeType', 'ObjectChangeType',
'ContentType',
) )

View File

@ -1,4 +1,4 @@
from typing import Annotated, List, Union from typing import Annotated, List, TYPE_CHECKING, Union
import strawberry import strawberry
import strawberry_django import strawberry_django
@ -6,7 +6,11 @@ import strawberry_django
from core.graphql.mixins import ChangelogMixin from core.graphql.mixins import ChangelogMixin
from dcim import models from dcim import models
from extras.graphql.mixins import ( from extras.graphql.mixins import (
ConfigContextMixin, ContactsMixin, CustomFieldsMixin, ImageAttachmentsMixin, TagsMixin, ConfigContextMixin,
ContactsMixin,
CustomFieldsMixin,
ImageAttachmentsMixin,
TagsMixin,
) )
from ipam.graphql.mixins import IPAddressesMixin, VLANGroupsMixin from ipam.graphql.mixins import IPAddressesMixin, VLANGroupsMixin
from netbox.graphql.scalars import BigInt from netbox.graphql.scalars import BigInt
@ -14,6 +18,23 @@ from netbox.graphql.types import BaseObjectType, NetBoxObjectType, Organizationa
from .filters import * from .filters import *
from .mixins import CabledObjectMixin, PathEndpointMixin from .mixins import CabledObjectMixin, PathEndpointMixin
if TYPE_CHECKING:
from circuits.graphql.types import CircuitTerminationType
from extras.graphql.types import ConfigTemplateType
from ipam.graphql.types import (
ASNType,
IPAddressType,
PrefixType,
ServiceType,
VLANTranslationPolicyType,
VLANType,
VRFType,
)
from tenancy.graphql.types import TenantType
from users.graphql.types import UserType
from virtualization.graphql.types import ClusterType, VMInterfaceType, VirtualMachineType
from wireless.graphql.types import WirelessLANType, WirelessLinkType
__all__ = ( __all__ = (
'CableType', 'CableType',
'ComponentType', 'ComponentType',
@ -111,7 +132,7 @@ class ModularComponentTemplateType(ComponentTemplateType):
@strawberry_django.type( @strawberry_django.type(
models.CableTermination, models.CableTermination,
exclude=('termination_type', 'termination_id', '_device', '_rack', '_location', '_site'), exclude=['termination_type', 'termination_id', '_device', '_rack', '_location', '_site'],
filters=CableTerminationFilter filters=CableTerminationFilter
) )
class CableTerminationType(NetBoxObjectType): class CableTerminationType(NetBoxObjectType):
@ -167,7 +188,7 @@ class CableType(NetBoxObjectType):
@strawberry_django.type( @strawberry_django.type(
models.ConsolePort, models.ConsolePort,
exclude=('_path',), exclude=['_path'],
filters=ConsolePortFilter filters=ConsolePortFilter
) )
class ConsolePortType(ModularComponentType, CabledObjectMixin, PathEndpointMixin): class ConsolePortType(ModularComponentType, CabledObjectMixin, PathEndpointMixin):
@ -185,7 +206,7 @@ class ConsolePortTemplateType(ModularComponentTemplateType):
@strawberry_django.type( @strawberry_django.type(
models.ConsoleServerPort, models.ConsoleServerPort,
exclude=('_path',), exclude=['_path'],
filters=ConsoleServerPortFilter filters=ConsoleServerPortFilter
) )
class ConsoleServerPortType(ModularComponentType, CabledObjectMixin, PathEndpointMixin): class ConsoleServerPortType(ModularComponentType, CabledObjectMixin, PathEndpointMixin):
@ -276,7 +297,7 @@ class DeviceBayTemplateType(ComponentTemplateType):
@strawberry_django.type( @strawberry_django.type(
models.InventoryItemTemplate, models.InventoryItemTemplate,
exclude=('component_type', 'component_id', 'parent'), exclude=['component_type', 'component_id', 'parent'],
filters=InventoryItemTemplateFilter filters=InventoryItemTemplateFilter
) )
class InventoryItemTemplateType(ComponentTemplateType): class InventoryItemTemplateType(ComponentTemplateType):
@ -369,7 +390,7 @@ class FrontPortTemplateType(ModularComponentTemplateType):
@strawberry_django.type( @strawberry_django.type(
models.MACAddress, models.MACAddress,
exclude=('assigned_object_type', 'assigned_object_id'), exclude=['assigned_object_type', 'assigned_object_id'],
filters=MACAddressFilter filters=MACAddressFilter
) )
class MACAddressType(NetBoxObjectType): class MACAddressType(NetBoxObjectType):
@ -385,7 +406,7 @@ class MACAddressType(NetBoxObjectType):
@strawberry_django.type( @strawberry_django.type(
models.Interface, models.Interface,
exclude=('_path',), exclude=['_path'],
filters=InterfaceFilter filters=InterfaceFilter
) )
class InterfaceType(IPAddressesMixin, ModularComponentType, CabledObjectMixin, PathEndpointMixin): class InterfaceType(IPAddressesMixin, ModularComponentType, CabledObjectMixin, PathEndpointMixin):
@ -424,7 +445,7 @@ class InterfaceTemplateType(ModularComponentTemplateType):
@strawberry_django.type( @strawberry_django.type(
models.InventoryItem, models.InventoryItem,
exclude=('component_type', 'component_id', 'parent'), exclude=['component_type', 'component_id', 'parent'],
filters=InventoryItemFilter filters=InventoryItemFilter
) )
class InventoryItemType(ComponentType): class InventoryItemType(ComponentType):
@ -463,7 +484,7 @@ class InventoryItemRoleType(OrganizationalObjectType):
@strawberry_django.type( @strawberry_django.type(
models.Location, models.Location,
# fields='__all__', # fields='__all__',
exclude=('parent',), # bug - temp exclude=['parent'], # bug - temp
filters=LocationFilter filters=LocationFilter
) )
class LocationType(VLANGroupsMixin, ImageAttachmentsMixin, ContactsMixin, OrganizationalObjectType): class LocationType(VLANGroupsMixin, ImageAttachmentsMixin, ContactsMixin, OrganizationalObjectType):
@ -524,7 +545,7 @@ class ModuleType(NetBoxObjectType):
@strawberry_django.type( @strawberry_django.type(
models.ModuleBay, models.ModuleBay,
# fields='__all__', # fields='__all__',
exclude=('parent',), exclude=['parent'],
filters=ModuleBayFilter filters=ModuleBayFilter
) )
class ModuleBayType(ModularComponentType): class ModuleBayType(ModularComponentType):
@ -579,7 +600,7 @@ class PlatformType(OrganizationalObjectType):
@strawberry_django.type( @strawberry_django.type(
models.PowerFeed, models.PowerFeed,
exclude=('_path',), exclude=['_path'],
filters=PowerFeedFilter filters=PowerFeedFilter
) )
class PowerFeedType(NetBoxObjectType, CabledObjectMixin, PathEndpointMixin): class PowerFeedType(NetBoxObjectType, CabledObjectMixin, PathEndpointMixin):
@ -590,7 +611,7 @@ class PowerFeedType(NetBoxObjectType, CabledObjectMixin, PathEndpointMixin):
@strawberry_django.type( @strawberry_django.type(
models.PowerOutlet, models.PowerOutlet,
exclude=('_path',), exclude=['_path'],
filters=PowerOutletFilter filters=PowerOutletFilter
) )
class PowerOutletType(ModularComponentType, CabledObjectMixin, PathEndpointMixin): class PowerOutletType(ModularComponentType, CabledObjectMixin, PathEndpointMixin):
@ -621,7 +642,7 @@ class PowerPanelType(NetBoxObjectType, ContactsMixin):
@strawberry_django.type( @strawberry_django.type(
models.PowerPort, models.PowerPort,
exclude=('_path',), exclude=['_path'],
filters=PowerPortFilter filters=PowerPortFilter
) )
class PowerPortType(ModularComponentType, CabledObjectMixin, PathEndpointMixin): class PowerPortType(ModularComponentType, CabledObjectMixin, PathEndpointMixin):
@ -712,8 +733,7 @@ class RearPortTemplateType(ModularComponentTemplateType):
@strawberry_django.type( @strawberry_django.type(
models.Region, models.Region,
exclude=('parent',), exclude=['parent'],
# fields='__all__',
filters=RegionFilter filters=RegionFilter
) )
class RegionType(VLANGroupsMixin, ContactsMixin, OrganizationalObjectType): class RegionType(VLANGroupsMixin, ContactsMixin, OrganizationalObjectType):
@ -772,8 +792,7 @@ class SiteType(VLANGroupsMixin, ImageAttachmentsMixin, ContactsMixin, NetBoxObje
@strawberry_django.type( @strawberry_django.type(
models.SiteGroup, models.SiteGroup,
# fields='__all__', exclude=['parent'], # bug - temp
exclude=('parent',), # bug - temp
filters=SiteGroupFilter filters=SiteGroupFilter
) )
class SiteGroupType(VLANGroupsMixin, ContactsMixin, OrganizationalObjectType): class SiteGroupType(VLANGroupsMixin, ContactsMixin, OrganizationalObjectType):

View File

@ -1,4 +1,4 @@
from typing import Annotated, List from typing import Annotated, List, TYPE_CHECKING
import strawberry import strawberry
import strawberry_django import strawberry_django
@ -8,6 +8,22 @@ from extras.graphql.mixins import CustomFieldsMixin, TagsMixin
from netbox.graphql.types import BaseObjectType, ContentTypeType, ObjectType, OrganizationalObjectType from netbox.graphql.types import BaseObjectType, ContentTypeType, ObjectType, OrganizationalObjectType
from .filters import * from .filters import *
if TYPE_CHECKING:
from core.graphql.types import DataFileType, DataSourceType
from dcim.graphql.types import (
DeviceRoleType,
DeviceType,
DeviceTypeType,
LocationType,
PlatformType,
RegionType,
SiteGroupType,
SiteType,
)
from tenancy.graphql.types import TenantGroupType, TenantType
from users.graphql.types import GroupType, UserType
from virtualization.graphql.types import ClusterGroupType, ClusterType, ClusterTypeType, VirtualMachineType
__all__ = ( __all__ = (
'ConfigContextType', 'ConfigContextType',
'ConfigTemplateType', 'ConfigTemplateType',
@ -35,7 +51,6 @@ __all__ = (
class ConfigContextType(ObjectType): class ConfigContextType(ObjectType):
data_source: Annotated["DataSourceType", strawberry.lazy('core.graphql.types')] | None data_source: Annotated["DataSourceType", strawberry.lazy('core.graphql.types')] | None
data_file: Annotated["DataFileType", strawberry.lazy('core.graphql.types')] | None data_file: Annotated["DataFileType", strawberry.lazy('core.graphql.types')] | None
roles: List[Annotated["DeviceRoleType", strawberry.lazy('dcim.graphql.types')]] roles: List[Annotated["DeviceRoleType", strawberry.lazy('dcim.graphql.types')]]
device_types: List[Annotated["DeviceTypeType", strawberry.lazy('dcim.graphql.types')]] device_types: List[Annotated["DeviceTypeType", strawberry.lazy('dcim.graphql.types')]]
tags: List[Annotated["TagType", strawberry.lazy('extras.graphql.types')]] tags: List[Annotated["TagType", strawberry.lazy('extras.graphql.types')]]
@ -78,7 +93,7 @@ class CustomFieldType(ObjectType):
@strawberry_django.type( @strawberry_django.type(
models.CustomFieldChoiceSet, models.CustomFieldChoiceSet,
exclude=('extra_choices', ), exclude=['extra_choices'],
filters=CustomFieldChoiceSetFilter filters=CustomFieldChoiceSetFilter
) )
class CustomFieldChoiceSetType(ObjectType): class CustomFieldChoiceSetType(ObjectType):

View File

@ -1,4 +1,4 @@
from typing import Annotated, List, Union from typing import Annotated, List, TYPE_CHECKING, Union
import strawberry import strawberry
import strawberry_django import strawberry_django
@ -11,6 +11,21 @@ from netbox.graphql.types import BaseObjectType, NetBoxObjectType, Organizationa
from .filters import * from .filters import *
from .mixins import IPAddressesMixin from .mixins import IPAddressesMixin
if TYPE_CHECKING:
from dcim.graphql.types import (
DeviceType,
InterfaceType,
LocationType,
RackType,
RegionType,
SiteGroupType,
SiteType,
)
from tenancy.graphql.types import TenantType
from virtualization.graphql.types import ClusterGroupType, ClusterType, VMInterfaceType, VirtualMachineType
from vpn.graphql.types import L2VPNType, TunnelTerminationType
from wireless.graphql.types import WirelessLANType
__all__ = ( __all__ = (
'ASNType', 'ASNType',
'ASNRangeType', 'ASNRangeType',
@ -101,7 +116,7 @@ class FHRPGroupType(NetBoxObjectType, IPAddressesMixin):
@strawberry_django.type( @strawberry_django.type(
models.FHRPGroupAssignment, models.FHRPGroupAssignment,
exclude=('interface_type', 'interface_id'), exclude=['interface_type', 'interface_id'],
filters=FHRPGroupAssignmentFilter filters=FHRPGroupAssignmentFilter
) )
class FHRPGroupAssignmentType(BaseObjectType): class FHRPGroupAssignmentType(BaseObjectType):
@ -117,7 +132,7 @@ class FHRPGroupAssignmentType(BaseObjectType):
@strawberry_django.type( @strawberry_django.type(
models.IPAddress, models.IPAddress,
exclude=('assigned_object_type', 'assigned_object_id', 'address'), exclude=['assigned_object_type', 'assigned_object_id', 'address'],
filters=IPAddressFilter filters=IPAddressFilter
) )
class IPAddressType(NetBoxObjectType, BaseIPAddressFamilyType): class IPAddressType(NetBoxObjectType, BaseIPAddressFamilyType):
@ -154,7 +169,7 @@ class IPRangeType(NetBoxObjectType):
@strawberry_django.type( @strawberry_django.type(
models.Prefix, models.Prefix,
exclude=('scope_type', 'scope_id', '_location', '_region', '_site', '_site_group'), exclude=['scope_type', 'scope_id', '_location', '_region', '_site', '_site_group'],
filters=PrefixFilter filters=PrefixFilter
) )
class PrefixType(NetBoxObjectType, BaseIPAddressFamilyType): class PrefixType(NetBoxObjectType, BaseIPAddressFamilyType):
@ -236,7 +251,7 @@ class ServiceTemplateType(NetBoxObjectType):
@strawberry_django.type( @strawberry_django.type(
models.VLAN, models.VLAN,
exclude=('qinq_svlan',), exclude=['qinq_svlan'],
filters=VLANFilter filters=VLANFilter
) )
class VLANType(NetBoxObjectType): class VLANType(NetBoxObjectType):
@ -259,7 +274,7 @@ class VLANType(NetBoxObjectType):
@strawberry_django.type( @strawberry_django.type(
models.VLANGroup, models.VLANGroup,
exclude=('scope_type', 'scope_id'), exclude=['scope_type', 'scope_id'],
filters=VLANGroupFilter filters=VLANGroupFilter
) )
class VLANGroupType(OrganizationalObjectType): class VLANGroupType(OrganizationalObjectType):

View File

@ -8,6 +8,7 @@ from extras.graphql.mixins import CustomFieldsMixin, JournalEntriesMixin, TagsMi
__all__ = ( __all__ = (
'BaseObjectType', 'BaseObjectType',
'ContentTypeType',
'ObjectType', 'ObjectType',
'OrganizationalObjectType', 'OrganizationalObjectType',
'NetBoxObjectType', 'NetBoxObjectType',

View File

@ -6,16 +6,36 @@ import strawberry_django
from extras.graphql.mixins import CustomFieldsMixin, TagsMixin from extras.graphql.mixins import CustomFieldsMixin, TagsMixin
from netbox.graphql.types import BaseObjectType, OrganizationalObjectType, NetBoxObjectType from netbox.graphql.types import BaseObjectType, OrganizationalObjectType, NetBoxObjectType
from tenancy import models from tenancy import models
from .mixins import ContactAssignmentsMixin
from .filters import * from .filters import *
from .mixins import ContactAssignmentsMixin
if TYPE_CHECKING: if TYPE_CHECKING:
from circuits.graphql.types import * from circuits.graphql.types import CircuitType
from dcim.graphql.types import * from dcim.graphql.types import (
from ipam.graphql.types import * CableType,
from wireless.graphql.types import * DeviceType,
from virtualization.graphql.types import * LocationType,
from vpn.graphql.types import * PowerFeedType,
RackType,
RackReservationType,
SiteType,
VirtualDeviceContextType,
)
from ipam.graphql.types import (
AggregateType,
ASNType,
ASNRangeType,
IPAddressType,
IPRangeType,
PrefixType,
RouteTargetType,
VLANType,
VRFType,
)
from netbox.graphql.types import ContentTypeType
from wireless.graphql.types import WirelessLANType, WirelessLinkType
from virtualization.graphql.types import ClusterType, VirtualMachineType
from vpn.graphql.types import L2VPNType, TunnelType
__all__ = ( __all__ = (
'ContactAssignmentType', 'ContactAssignmentType',

View File

@ -1,4 +1,4 @@
from typing import Annotated, List, Union from typing import Annotated, List, TYPE_CHECKING, Union
import strawberry import strawberry
import strawberry_django import strawberry_django
@ -10,6 +10,21 @@ from netbox.graphql.types import OrganizationalObjectType, NetBoxObjectType
from virtualization import models from virtualization import models
from .filters import * from .filters import *
if TYPE_CHECKING:
from dcim.graphql.types import (
DeviceRoleType,
DeviceType,
LocationType,
MACAddressType,
PlatformType,
RegionType,
SiteGroupType,
SiteType,
)
from extras.graphql.types import ConfigTemplateType
from ipam.graphql.types import IPAddressType, ServiceType, VLANTranslationPolicyType, VLANType, VRFType
from tenancy.graphql.types import TenantType
__all__ = ( __all__ = (
'ClusterType', 'ClusterType',
'ClusterGroupType', 'ClusterGroupType',
@ -30,7 +45,7 @@ class ComponentType(NetBoxObjectType):
@strawberry_django.type( @strawberry_django.type(
models.Cluster, models.Cluster,
exclude=('scope_type', 'scope_id', '_location', '_region', '_site', '_site_group'), exclude=['scope_type', 'scope_id', '_location', '_region', '_site', '_site_group'],
filters=ClusterFilter filters=ClusterFilter
) )
class ClusterType(VLANGroupsMixin, NetBoxObjectType): class ClusterType(VLANGroupsMixin, NetBoxObjectType):

View File

@ -1,4 +1,4 @@
from typing import Annotated, List, Union from typing import Annotated, List, TYPE_CHECKING, Union
import strawberry import strawberry
import strawberry_django import strawberry_django
@ -8,6 +8,13 @@ from netbox.graphql.types import ObjectType, OrganizationalObjectType, NetBoxObj
from vpn import models from vpn import models
from .filters import * from .filters import *
if TYPE_CHECKING:
from dcim.graphql.types import InterfaceType
from ipam.graphql.types import IPAddressType, RouteTargetType, VLANType
from netbox.graphql.types import ContentTypeType
from tenancy.graphql.types import TenantType
from virtualization.graphql.types import VMInterfaceType
__all__ = ( __all__ = (
'IKEPolicyType', 'IKEPolicyType',
'IKEProposalType', 'IKEProposalType',
@ -125,7 +132,7 @@ class L2VPNType(ContactsMixin, NetBoxObjectType):
@strawberry_django.type( @strawberry_django.type(
models.L2VPNTermination, models.L2VPNTermination,
exclude=('assigned_object_type', 'assigned_object_id'), exclude=['assigned_object_type', 'assigned_object_id'],
filters=L2VPNTerminationFilter filters=L2VPNTerminationFilter
) )
class L2VPNTerminationType(NetBoxObjectType): class L2VPNTerminationType(NetBoxObjectType):

View File

@ -1,4 +1,4 @@
from typing import Annotated, List, Union from typing import Annotated, List, TYPE_CHECKING, Union
import strawberry import strawberry
import strawberry_django import strawberry_django
@ -7,6 +7,11 @@ from netbox.graphql.types import OrganizationalObjectType, NetBoxObjectType
from wireless import models from wireless import models
from .filters import * from .filters import *
if TYPE_CHECKING:
from dcim.graphql.types import DeviceType, InterfaceType, LocationType, RegionType, SiteGroupType, SiteType
from ipam.graphql.types import VLANType
from tenancy.graphql.types import TenantType
__all__ = ( __all__ = (
'WirelessLANType', 'WirelessLANType',
'WirelessLANGroupType', 'WirelessLANGroupType',
@ -28,7 +33,7 @@ class WirelessLANGroupType(OrganizationalObjectType):
@strawberry_django.type( @strawberry_django.type(
models.WirelessLAN, models.WirelessLAN,
exclude=('scope_type', 'scope_id', '_location', '_region', '_site', '_site_group'), exclude=['scope_type', 'scope_id', '_location', '_region', '_site', '_site_group'],
filters=WirelessLANFilter filters=WirelessLANFilter
) )
class WirelessLANType(NetBoxObjectType): class WirelessLANType(NetBoxObjectType):