Closes #16224 GraphQL Pagination (#18903)

* 16244 add pagination

* 16244 add pagination

* 16244 fix order_by pagination

* 16224 document pagination

* 16224 remove extraneous code

* 16224 missing core types

* 16224 review changes

* 16224 review changes

* 16224 review changes
This commit is contained in:
Arthur Hanson
2025-03-20 13:00:14 -07:00
committed by GitHub
parent 80440fd025
commit fe7cc8cae9
14 changed files with 277 additions and 117 deletions

View File

@@ -133,7 +133,8 @@ class ModularComponentTemplateType(ComponentTemplateType):
@strawberry_django.type(
models.CableTermination,
exclude=['termination_type', 'termination_id', '_device', '_rack', '_location', '_site'],
filters=CableTerminationFilter
filters=CableTerminationFilter,
pagination=True
)
class CableTerminationType(NetBoxObjectType):
cable: Annotated["CableType", strawberry.lazy('dcim.graphql.types')] | None
@@ -153,7 +154,8 @@ class CableTerminationType(NetBoxObjectType):
@strawberry_django.type(
models.Cable,
fields='__all__',
filters=CableFilter
filters=CableFilter,
pagination=True
)
class CableType(NetBoxObjectType):
color: str
@@ -189,7 +191,8 @@ class CableType(NetBoxObjectType):
@strawberry_django.type(
models.ConsolePort,
exclude=['_path'],
filters=ConsolePortFilter
filters=ConsolePortFilter,
pagination=True
)
class ConsolePortType(ModularComponentType, CabledObjectMixin, PathEndpointMixin):
pass
@@ -198,7 +201,8 @@ class ConsolePortType(ModularComponentType, CabledObjectMixin, PathEndpointMixin
@strawberry_django.type(
models.ConsolePortTemplate,
fields='__all__',
filters=ConsolePortTemplateFilter
filters=ConsolePortTemplateFilter,
pagination=True
)
class ConsolePortTemplateType(ModularComponentTemplateType):
pass
@@ -207,7 +211,8 @@ class ConsolePortTemplateType(ModularComponentTemplateType):
@strawberry_django.type(
models.ConsoleServerPort,
exclude=['_path'],
filters=ConsoleServerPortFilter
filters=ConsoleServerPortFilter,
pagination=True
)
class ConsoleServerPortType(ModularComponentType, CabledObjectMixin, PathEndpointMixin):
pass
@@ -216,7 +221,8 @@ class ConsoleServerPortType(ModularComponentType, CabledObjectMixin, PathEndpoin
@strawberry_django.type(
models.ConsoleServerPortTemplate,
fields='__all__',
filters=ConsoleServerPortTemplateFilter
filters=ConsoleServerPortTemplateFilter,
pagination=True
)
class ConsoleServerPortTemplateType(ModularComponentTemplateType):
pass
@@ -225,7 +231,8 @@ class ConsoleServerPortTemplateType(ModularComponentTemplateType):
@strawberry_django.type(
models.Device,
fields='__all__',
filters=DeviceFilter
filters=DeviceFilter,
pagination=True
)
class DeviceType(ConfigContextMixin, ImageAttachmentsMixin, ContactsMixin, NetBoxObjectType):
console_port_count: BigInt
@@ -280,7 +287,8 @@ class DeviceType(ConfigContextMixin, ImageAttachmentsMixin, ContactsMixin, NetBo
@strawberry_django.type(
models.DeviceBay,
fields='__all__',
filters=DeviceBayFilter
filters=DeviceBayFilter,
pagination=True
)
class DeviceBayType(ComponentType):
installed_device: Annotated["DeviceType", strawberry.lazy('dcim.graphql.types')] | None
@@ -289,7 +297,8 @@ class DeviceBayType(ComponentType):
@strawberry_django.type(
models.DeviceBayTemplate,
fields='__all__',
filters=DeviceBayTemplateFilter
filters=DeviceBayTemplateFilter,
pagination=True
)
class DeviceBayTemplateType(ComponentTemplateType):
pass
@@ -298,7 +307,8 @@ class DeviceBayTemplateType(ComponentTemplateType):
@strawberry_django.type(
models.InventoryItemTemplate,
exclude=['component_type', 'component_id', 'parent'],
filters=InventoryItemTemplateFilter
filters=InventoryItemTemplateFilter,
pagination=True
)
class InventoryItemTemplateType(ComponentTemplateType):
role: Annotated["InventoryItemRoleType", strawberry.lazy('dcim.graphql.types')] | None
@@ -324,7 +334,8 @@ class InventoryItemTemplateType(ComponentTemplateType):
@strawberry_django.type(
models.DeviceRole,
fields='__all__',
filters=DeviceRoleFilter
filters=DeviceRoleFilter,
pagination=True
)
class DeviceRoleType(OrganizationalObjectType):
color: str
@@ -337,7 +348,8 @@ class DeviceRoleType(OrganizationalObjectType):
@strawberry_django.type(
models.DeviceType,
fields='__all__',
filters=DeviceTypeFilter
filters=DeviceTypeFilter,
pagination=True
)
class DeviceTypeType(NetBoxObjectType):
console_port_template_count: BigInt
@@ -371,7 +383,8 @@ class DeviceTypeType(NetBoxObjectType):
@strawberry_django.type(
models.FrontPort,
fields='__all__',
filters=FrontPortFilter
filters=FrontPortFilter,
pagination=True
)
class FrontPortType(ModularComponentType, CabledObjectMixin):
color: str
@@ -381,7 +394,8 @@ class FrontPortType(ModularComponentType, CabledObjectMixin):
@strawberry_django.type(
models.FrontPortTemplate,
fields='__all__',
filters=FrontPortTemplateFilter
filters=FrontPortTemplateFilter,
pagination=True
)
class FrontPortTemplateType(ModularComponentTemplateType):
color: str
@@ -391,7 +405,8 @@ class FrontPortTemplateType(ModularComponentTemplateType):
@strawberry_django.type(
models.MACAddress,
exclude=['assigned_object_type', 'assigned_object_id'],
filters=MACAddressFilter
filters=MACAddressFilter,
pagination=True
)
class MACAddressType(NetBoxObjectType):
mac_address: str
@@ -407,7 +422,8 @@ class MACAddressType(NetBoxObjectType):
@strawberry_django.type(
models.Interface,
exclude=['_path'],
filters=InterfaceFilter
filters=InterfaceFilter,
pagination=True
)
class InterfaceType(IPAddressesMixin, ModularComponentType, CabledObjectMixin, PathEndpointMixin):
_name: str
@@ -434,7 +450,8 @@ class InterfaceType(IPAddressesMixin, ModularComponentType, CabledObjectMixin, P
@strawberry_django.type(
models.InterfaceTemplate,
fields='__all__',
filters=InterfaceTemplateFilter
filters=InterfaceTemplateFilter,
pagination=True
)
class InterfaceTemplateType(ModularComponentTemplateType):
_name: str
@@ -446,7 +463,8 @@ class InterfaceTemplateType(ModularComponentTemplateType):
@strawberry_django.type(
models.InventoryItem,
exclude=['component_type', 'component_id', 'parent'],
filters=InventoryItemFilter
filters=InventoryItemFilter,
pagination=True
)
class InventoryItemType(ComponentType):
role: Annotated["InventoryItemRoleType", strawberry.lazy('dcim.graphql.types')] | None
@@ -472,7 +490,8 @@ class InventoryItemType(ComponentType):
@strawberry_django.type(
models.InventoryItemRole,
fields='__all__',
filters=InventoryItemRoleFilter
filters=InventoryItemRoleFilter,
pagination=True
)
class InventoryItemRoleType(OrganizationalObjectType):
color: str
@@ -485,7 +504,8 @@ class InventoryItemRoleType(OrganizationalObjectType):
models.Location,
# fields='__all__',
exclude=['parent'], # bug - temp
filters=LocationFilter
filters=LocationFilter,
pagination=True
)
class LocationType(VLANGroupsMixin, ImageAttachmentsMixin, ContactsMixin, OrganizationalObjectType):
site: Annotated["SiteType", strawberry.lazy('dcim.graphql.types')]
@@ -512,7 +532,8 @@ class LocationType(VLANGroupsMixin, ImageAttachmentsMixin, ContactsMixin, Organi
@strawberry_django.type(
models.Manufacturer,
fields='__all__',
filters=ManufacturerFilter
filters=ManufacturerFilter,
pagination=True
)
class ManufacturerType(OrganizationalObjectType, ContactsMixin):
@@ -526,7 +547,8 @@ class ManufacturerType(OrganizationalObjectType, ContactsMixin):
@strawberry_django.type(
models.Module,
fields='__all__',
filters=ModuleFilter
filters=ModuleFilter,
pagination=True
)
class ModuleType(NetBoxObjectType):
device: Annotated["DeviceType", strawberry.lazy('dcim.graphql.types')]
@@ -546,7 +568,8 @@ class ModuleType(NetBoxObjectType):
models.ModuleBay,
# fields='__all__',
exclude=['parent'],
filters=ModuleBayFilter
filters=ModuleBayFilter,
pagination=True
)
class ModuleBayType(ModularComponentType):
@@ -561,7 +584,8 @@ class ModuleBayType(ModularComponentType):
@strawberry_django.type(
models.ModuleBayTemplate,
fields='__all__',
filters=ModuleBayTemplateFilter
filters=ModuleBayTemplateFilter,
pagination=True
)
class ModuleBayTemplateType(ModularComponentTemplateType):
pass
@@ -570,7 +594,8 @@ class ModuleBayTemplateType(ModularComponentTemplateType):
@strawberry_django.type(
models.ModuleType,
fields='__all__',
filters=ModuleTypeFilter
filters=ModuleTypeFilter,
pagination=True
)
class ModuleTypeType(NetBoxObjectType):
manufacturer: Annotated["ManufacturerType", strawberry.lazy('dcim.graphql.types')]
@@ -588,7 +613,8 @@ class ModuleTypeType(NetBoxObjectType):
@strawberry_django.type(
models.Platform,
fields='__all__',
filters=PlatformFilter
filters=PlatformFilter,
pagination=True
)
class PlatformType(OrganizationalObjectType):
manufacturer: Annotated["ManufacturerType", strawberry.lazy('dcim.graphql.types')] | None
@@ -601,7 +627,8 @@ class PlatformType(OrganizationalObjectType):
@strawberry_django.type(
models.PowerFeed,
exclude=['_path'],
filters=PowerFeedFilter
filters=PowerFeedFilter,
pagination=True
)
class PowerFeedType(NetBoxObjectType, CabledObjectMixin, PathEndpointMixin):
power_panel: Annotated["PowerPanelType", strawberry.lazy('dcim.graphql.types')]
@@ -612,7 +639,8 @@ class PowerFeedType(NetBoxObjectType, CabledObjectMixin, PathEndpointMixin):
@strawberry_django.type(
models.PowerOutlet,
exclude=['_path'],
filters=PowerOutletFilter
filters=PowerOutletFilter,
pagination=True
)
class PowerOutletType(ModularComponentType, CabledObjectMixin, PathEndpointMixin):
power_port: Annotated["PowerPortType", strawberry.lazy('dcim.graphql.types')] | None
@@ -622,7 +650,8 @@ class PowerOutletType(ModularComponentType, CabledObjectMixin, PathEndpointMixin
@strawberry_django.type(
models.PowerOutletTemplate,
fields='__all__',
filters=PowerOutletTemplateFilter
filters=PowerOutletTemplateFilter,
pagination=True
)
class PowerOutletTemplateType(ModularComponentTemplateType):
power_port: Annotated["PowerPortTemplateType", strawberry.lazy('dcim.graphql.types')] | None
@@ -631,7 +660,8 @@ class PowerOutletTemplateType(ModularComponentTemplateType):
@strawberry_django.type(
models.PowerPanel,
fields='__all__',
filters=PowerPanelFilter
filters=PowerPanelFilter,
pagination=True
)
class PowerPanelType(NetBoxObjectType, ContactsMixin):
site: Annotated["SiteType", strawberry.lazy('dcim.graphql.types')]
@@ -643,7 +673,8 @@ class PowerPanelType(NetBoxObjectType, ContactsMixin):
@strawberry_django.type(
models.PowerPort,
exclude=['_path'],
filters=PowerPortFilter
filters=PowerPortFilter,
pagination=True
)
class PowerPortType(ModularComponentType, CabledObjectMixin, PathEndpointMixin):
@@ -653,7 +684,8 @@ class PowerPortType(ModularComponentType, CabledObjectMixin, PathEndpointMixin):
@strawberry_django.type(
models.PowerPortTemplate,
fields='__all__',
filters=PowerPortTemplateFilter
filters=PowerPortTemplateFilter,
pagination=True
)
class PowerPortTemplateType(ModularComponentTemplateType):
poweroutlet_templates: List[Annotated["PowerOutletTemplateType", strawberry.lazy('dcim.graphql.types')]]
@@ -662,7 +694,8 @@ class PowerPortTemplateType(ModularComponentTemplateType):
@strawberry_django.type(
models.RackType,
fields='__all__',
filters=RackTypeFilter
filters=RackTypeFilter,
pagination=True
)
class RackTypeType(NetBoxObjectType):
manufacturer: Annotated["ManufacturerType", strawberry.lazy('dcim.graphql.types')]
@@ -671,7 +704,8 @@ class RackTypeType(NetBoxObjectType):
@strawberry_django.type(
models.Rack,
fields='__all__',
filters=RackFilter
filters=RackFilter,
pagination=True
)
class RackType(VLANGroupsMixin, ImageAttachmentsMixin, ContactsMixin, NetBoxObjectType):
site: Annotated["SiteType", strawberry.lazy('dcim.graphql.types')]
@@ -689,7 +723,8 @@ class RackType(VLANGroupsMixin, ImageAttachmentsMixin, ContactsMixin, NetBoxObje
@strawberry_django.type(
models.RackReservation,
fields='__all__',
filters=RackReservationFilter
filters=RackReservationFilter,
pagination=True
)
class RackReservationType(NetBoxObjectType):
units: List[int]
@@ -701,7 +736,8 @@ class RackReservationType(NetBoxObjectType):
@strawberry_django.type(
models.RackRole,
fields='__all__',
filters=RackRoleFilter
filters=RackRoleFilter,
pagination=True
)
class RackRoleType(OrganizationalObjectType):
color: str
@@ -712,7 +748,8 @@ class RackRoleType(OrganizationalObjectType):
@strawberry_django.type(
models.RearPort,
fields='__all__',
filters=RearPortFilter
filters=RearPortFilter,
pagination=True
)
class RearPortType(ModularComponentType, CabledObjectMixin):
color: str
@@ -723,7 +760,8 @@ class RearPortType(ModularComponentType, CabledObjectMixin):
@strawberry_django.type(
models.RearPortTemplate,
fields='__all__',
filters=RearPortTemplateFilter
filters=RearPortTemplateFilter,
pagination=True
)
class RearPortTemplateType(ModularComponentTemplateType):
color: str
@@ -734,7 +772,8 @@ class RearPortTemplateType(ModularComponentTemplateType):
@strawberry_django.type(
models.Region,
exclude=['parent'],
filters=RegionFilter
filters=RegionFilter,
pagination=True
)
class RegionType(VLANGroupsMixin, ContactsMixin, OrganizationalObjectType):
@@ -759,7 +798,8 @@ class RegionType(VLANGroupsMixin, ContactsMixin, OrganizationalObjectType):
@strawberry_django.type(
models.Site,
fields='__all__',
filters=SiteFilter
filters=SiteFilter,
pagination=True
)
class SiteType(VLANGroupsMixin, ImageAttachmentsMixin, ContactsMixin, NetBoxObjectType):
time_zone: str | None
@@ -793,7 +833,8 @@ class SiteType(VLANGroupsMixin, ImageAttachmentsMixin, ContactsMixin, NetBoxObje
@strawberry_django.type(
models.SiteGroup,
exclude=['parent'], # bug - temp
filters=SiteGroupFilter
filters=SiteGroupFilter,
pagination=True
)
class SiteGroupType(VLANGroupsMixin, ContactsMixin, OrganizationalObjectType):
@@ -818,7 +859,8 @@ class SiteGroupType(VLANGroupsMixin, ContactsMixin, OrganizationalObjectType):
@strawberry_django.type(
models.VirtualChassis,
fields='__all__',
filters=VirtualChassisFilter
filters=VirtualChassisFilter,
pagination=True
)
class VirtualChassisType(NetBoxObjectType):
member_count: BigInt
@@ -830,7 +872,8 @@ class VirtualChassisType(NetBoxObjectType):
@strawberry_django.type(
models.VirtualDeviceContext,
fields='__all__',
filters=VirtualDeviceContextFilter
filters=VirtualDeviceContextFilter,
pagination=True
)
class VirtualDeviceContextType(NetBoxObjectType):
device: Annotated["DeviceType", strawberry.lazy('dcim.graphql.types')] | None