Coverage for /home/runner/work/netbox-InterfaceNameRules-plugin/netbox-InterfaceNameRules-plugin/netbox-InterfaceNameRules-plugin/netbox_interface_name_rules/graphql/types.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-22 21:16 +0000

1# SPDX-License-Identifier: Apache-2.0 

2# Copyright (C) 2025 Marcin Zieba <marcinpsk@gmail.com> 

3 

4"""GraphQL object type for InterfaceNameRule.""" 

5 

6from typing import TYPE_CHECKING, Annotated 

7 

8import strawberry 

9import strawberry_django 

10from netbox.graphql.types import NetBoxObjectType 

11 

12from netbox_interface_name_rules.models import InterfaceNameRule 

13 

14from .filters import InterfaceNameRuleFilter 

15 

16if TYPE_CHECKING: 

17 from dcim.graphql.types import DeviceTypeType, ModuleTypeType, PlatformType 

18 

19# The filter base only exists on NetBox 4.5+; register without one where it doesn't. 

20_type_kwargs = {"fields": "__all__", "pagination": True} 

21if InterfaceNameRuleFilter is not None: # pragma: no cover — absent only on NetBox 4.3 

22 _type_kwargs["filters"] = InterfaceNameRuleFilter 

23 

24 

25@strawberry_django.type(InterfaceNameRule, **_type_kwargs) 

26class InterfaceNameRuleType(NetBoxObjectType): 

27 """An interface rename rule.""" 

28 

29 # Without these the relations resolve to a bare DjangoModelType with no queryable fields. 

30 module_type: Annotated["ModuleTypeType", strawberry.lazy("dcim.graphql.types")] | None 

31 parent_module_type: Annotated["ModuleTypeType", strawberry.lazy("dcim.graphql.types")] | None 

32 device_type: Annotated["DeviceTypeType", strawberry.lazy("dcim.graphql.types")] | None 

33 platform: Annotated["PlatformType", strawberry.lazy("dcim.graphql.types")] | None 

34 

35 

36__all__ = ("InterfaceNameRuleType",)