types.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. from typing import TYPE_CHECKING, Annotated
  2. import strawberry
  3. import strawberry_django
  4. from netbox.graphql.types import NestedGroupObjectType, PrimaryObjectType
  5. from wireless import models
  6. from .filters import *
  7. if TYPE_CHECKING:
  8. from dcim.graphql.types import DeviceType, InterfaceType, LocationType, RegionType, SiteGroupType, SiteType
  9. from ipam.graphql.types import VLANType
  10. from tenancy.graphql.types import TenantType
  11. __all__ = (
  12. 'WirelessLANType',
  13. 'WirelessLANGroupType',
  14. 'WirelessLinkType',
  15. )
  16. @strawberry_django.type(
  17. models.WirelessLANGroup,
  18. fields='__all__',
  19. filters=WirelessLANGroupFilter,
  20. pagination=True
  21. )
  22. class WirelessLANGroupType(NestedGroupObjectType):
  23. parent: Annotated["WirelessLANGroupType", strawberry.lazy('wireless.graphql.types')] | None
  24. wireless_lans: list[Annotated["WirelessLANType", strawberry.lazy('wireless.graphql.types')]]
  25. children: list[Annotated["WirelessLANGroupType", strawberry.lazy('wireless.graphql.types')]]
  26. @strawberry_django.type(
  27. models.WirelessLAN,
  28. exclude=['scope_type', 'scope_id', '_location', '_region', '_site', '_site_group'],
  29. filters=WirelessLANFilter,
  30. pagination=True
  31. )
  32. class WirelessLANType(PrimaryObjectType):
  33. group: Annotated["WirelessLANGroupType", strawberry.lazy('wireless.graphql.types')] | None
  34. vlan: Annotated["VLANType", strawberry.lazy('ipam.graphql.types')] | None
  35. tenant: Annotated["TenantType", strawberry.lazy('tenancy.graphql.types')] | None
  36. interfaces: list[Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')]]
  37. @strawberry_django.field
  38. def scope(self) -> Annotated[
  39. Annotated['LocationType', strawberry.lazy('dcim.graphql.types')]
  40. | Annotated['RegionType', strawberry.lazy('dcim.graphql.types')]
  41. | Annotated['SiteGroupType', strawberry.lazy('dcim.graphql.types')]
  42. | Annotated['SiteType', strawberry.lazy('dcim.graphql.types')],
  43. strawberry.union('WirelessLANScopeType'),
  44. ] | None:
  45. return self.scope
  46. @strawberry_django.type(
  47. models.WirelessLink,
  48. fields='__all__',
  49. filters=WirelessLinkFilter,
  50. pagination=True
  51. )
  52. class WirelessLinkType(PrimaryObjectType):
  53. interface_a: Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')]
  54. interface_b: Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')]
  55. tenant: Annotated["TenantType", strawberry.lazy('tenancy.graphql.types')] | None
  56. _interface_a_device: Annotated["DeviceType", strawberry.lazy('dcim.graphql.types')] | None
  57. _interface_b_device: Annotated["DeviceType", strawberry.lazy('dcim.graphql.types')] | None