Coverage for netbox_data_import/graphql/schema.py: 96.00%
25 statements
« prev ^ index » next coverage.py v7.17.0, created at 2026-10-30 09:47 +0000
« prev ^ index » next coverage.py v7.17.0, created at 2026-10-30 09:47 +0000
1# SPDX-License-Identifier: Apache-2.0
2# Copyright (C) 2025 Marcin Zieba <marcinpsk@gmail.com>
4"""GraphQL queries registered with NetBox."""
6import strawberry
7import strawberry_django
8from strawberry.permission import BasePermission
10from netbox_data_import import branching
12from .types import CableClassMappingType, ImportProfileType, PortClassMappingType
15class MainOnly(BasePermission):
16 """Refuse a plugin field on the same terms as the plugin's REST and UI views."""
18 def has_permission(self, source, info, **kwargs) -> bool:
19 """Raise BranchActive, whose message becomes the GraphQL error, for a refused request."""
20 message = branching.request_refusal(info.context.request)
21 if message is not None:
22 raise branching.BranchActive(message)
23 return True
26@strawberry.type(name="Query")
27class ImportProfilesQuery:
28 """Expose import profile detail and list queries."""
30 import_profile: ImportProfileType = strawberry_django.field(permission_classes=[MainOnly])
31 import_profile_list: list[ImportProfileType] = strawberry_django.field(permission_classes=[MainOnly])
34@strawberry.type(name="Query")
35class CableClassMappingsQuery:
36 """Expose CableClass mapping detail and list queries."""
38 cable_class_mapping: CableClassMappingType = strawberry_django.field(permission_classes=[MainOnly])
39 cable_class_mapping_list: list[CableClassMappingType] = strawberry_django.field(permission_classes=[MainOnly])
42@strawberry.type(name="Query")
43class PortClassMappingsQuery:
44 """Expose PortClass mapping detail and list queries."""
46 port_class_mapping: PortClassMappingType = strawberry_django.field(permission_classes=[MainOnly])
47 port_class_mapping_list: list[PortClassMappingType] = strawberry_django.field(permission_classes=[MainOnly])
50schema = [ImportProfilesQuery, CableClassMappingsQuery, PortClassMappingsQuery]
52__all__ = ("CableClassMappingsQuery", "ImportProfilesQuery", "PortClassMappingsQuery", "schema")