Skip to content

Commit 5deb1b4

Browse files
committed
refactor(graphql): Simplify imports and format code
Refactor GraphQL module imports for clarity and consistency. Updated formatting to adhere to code standards without modifying functionality or behavior. Fixes: #249
1 parent e716efc commit 5deb1b4

File tree

4 files changed

+74
-52
lines changed

4 files changed

+74
-52
lines changed

netbox_acls/graphql/__init__.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
from .schema import *
2-
from .types import *
3-
4-
schema = [
5-
schema.NetBoxACLSQuery
6-
]
1+
from .schema import NetBoxACLSQuery
72

3+
schema = [NetBoxACLSQuery]

netbox_acls/graphql/filters.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
11
import strawberry_django
2+
from netbox.graphql.filter_mixins import BaseFilterMixin, autotype_decorator
3+
24
from .. import filtersets, models
3-
from netbox.graphql.filter_mixins import autotype_decorator, BaseFilterMixin
45

56
__all__ = (
6-
'AccessListFilter',
7-
'ACLInterfaceAssignmentFilter',
8-
'ACLExtendedRuleFilter',
9-
'ACLStandardRuleFilter',
7+
"AccessListFilter",
8+
"ACLInterfaceAssignmentFilter",
9+
"ACLExtendedRuleFilter",
10+
"ACLStandardRuleFilter",
1011
)
1112

13+
1214
@strawberry_django.filter(models.AccessList, lookups=True)
1315
@autotype_decorator(filtersets.AccessListFilterSet)
1416
class AccessListFilter(BaseFilterMixin):
1517
pass
1618

19+
1720
@strawberry_django.filter(models.ACLStandardRule, lookups=True)
1821
@autotype_decorator(filtersets.ACLStandardRuleFilterSet)
1922
class ACLStandardRuleFilter(BaseFilterMixin):
2023
pass
2124

25+
2226
@strawberry_django.filter(models.ACLExtendedRule, lookups=True)
2327
@autotype_decorator(filtersets.ACLExtendedRuleFilterSet)
2428
class ACLExtendedRuleFilter(BaseFilterMixin):
2529
pass
2630

31+
2732
@strawberry_django.filter(models.ACLInterfaceAssignment, lookups=True)
2833
@autotype_decorator(filtersets.ACLInterfaceAssignmentFilterSet)
2934
class ACLInterfaceAssignmentFilter(BaseFilterMixin):
30-
pass
35+
pass

netbox_acls/graphql/schema.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1+
from typing import List
2+
13
import strawberry
24
import strawberry_django
3-
from .types import *
4-
from ..models import *
5-
from typing import List
5+
6+
from .types import (
7+
AccessListType,
8+
ACLExtendedRuleType,
9+
ACLStandardRuleType,
10+
)
11+
612

713
@strawberry.type(name="Query")
814
class NetBoxACLSQuery:
915
"""
1016
Defines the queries available to this plugin via the graphql api.
1117
"""
18+
1219
access_list: AccessListType = strawberry_django.field()
1320
access_list_list: List[AccessListType] = strawberry_django.field()
1421

@@ -17,4 +24,3 @@ class NetBoxACLSQuery:
1724

1825
acl_standard_rule: ACLStandardRuleType = strawberry_django.field()
1926
acl_standard_rule_list: List[ACLStandardRuleType] = strawberry_django.field()
20-

netbox_acls/graphql/types.py

Lines changed: 51 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,90 @@
11
"""
2-
Define the object types and queries availble via the graphql api.
2+
Define the object types and queries available via the graphql api.
33
"""
44

5+
from typing import Annotated, List, Union
6+
57
import strawberry
68
import strawberry_django
9+
from netbox.graphql.types import OrganizationalObjectType
710

8-
9-
from typing import Annotated, List, Union
10-
from .filters import *
1111
from .. import models
12-
from netbox.graphql.types import OrganizationalObjectType
12+
from . import filters
13+
1314

1415
@strawberry_django.type(
1516
models.AccessList,
16-
fields='__all__',
17-
filters=AccessListFilter,
18-
exclude=('assigned_object_type', 'assigned_object_id')
17+
fields="__all__",
18+
exclude=["assigned_object_type", "assigned_object_id"],
19+
filters=filters.AccessListFilter,
1920
)
20-
2121
class AccessListType(OrganizationalObjectType):
2222
"""
2323
Defines the object type for the django model AccessList.
2424
"""
25-
assigned_object_type: Annotated["ContentTypeType", strawberry.lazy("netbox.graphql.types")]
26-
assigned_object: Annotated[Union[
27-
Annotated["DeviceType", strawberry.lazy('dcim.graphql.types')],
28-
Annotated["VirtualMachineType", strawberry.lazy('virtualization.graphql.types')],
29-
], strawberry.union("ACLAssignmentType")]
3025

26+
assigned_object_type: Annotated["ContentTypeType", strawberry.lazy("netbox.graphql.types")]
27+
assigned_object: Annotated[
28+
Union[
29+
Annotated["DeviceType", strawberry.lazy("dcim.graphql.types")],
30+
Annotated["VirtualMachineType", strawberry.lazy("virtualization.graphql.types")],
31+
],
32+
strawberry.union("ACLAssignmentType"),
33+
]
3134

3235
class Meta:
3336
"""
3437
Associates the filterset, fields, and model for the django model AccessList.
3538
"""
39+
3640
@strawberry_django.field
37-
def accesslists(self) -> List[Annotated["AccessList", strawberry.lazy('accesslists.graphql.types')]]:
41+
def accesslists(self) -> List[Annotated["AccessList", strawberry.lazy("accesslists.graphql.types")]]:
3842
return self.accesslists.all()
39-
43+
44+
4045
@strawberry_django.type(
4146
models.ACLInterfaceAssignment,
42-
fields='__all__',
43-
exclude=('assigned_object_type', 'assigned_object_id'),
44-
filters=ACLInterfaceAssignmentFilter
47+
fields="__all__",
48+
exclude=["assigned_object_type", "assigned_object_id"],
49+
filters=filters.ACLInterfaceAssignmentFilter,
4550
)
4651
class ACLInterfaceAssignmentType(OrganizationalObjectType):
4752
"""
4853
Defines the object type for the django model AccessList.
4954
"""
55+
5056
access_list: Annotated["AccessListType", strawberry.lazy("netbox_acls.graphql.types")]
5157
assigned_object_type: Annotated["ContentTypeType", strawberry.lazy("netbox.graphql.types")]
52-
assigned_object: Annotated[Union[
53-
Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')],
54-
Annotated["VMInterfaceType", strawberry.lazy('virtualization.graphql.types')],
55-
], strawberry.union("ACLInterfaceAssignmentType")]
56-
57-
58-
58+
assigned_object: Annotated[
59+
Union[
60+
Annotated["InterfaceType", strawberry.lazy("dcim.graphql.types")],
61+
Annotated["VMInterfaceType", strawberry.lazy("virtualization.graphql.types")],
62+
],
63+
strawberry.union("ACLInterfaceAssignmentType"),
64+
]
5965

6066
class Meta:
6167
"""
6268
Associates the filterset, fields, and model for the django model ACLInterfaceAssignment.
6369
"""
70+
6471
@strawberry_django.field
65-
def aclinterfaceassignments(self) -> List[Annotated["ACLInterfaceAssignment", strawberry.lazy('aclinterfaceassignments.graphql.types')]]:
72+
def aclinterfaceassignments(
73+
self,
74+
) -> List[Annotated["ACLInterfaceAssignment", strawberry.lazy("aclinterfaceassignments.graphql.types")]]:
6675
return self.aclinterfaceassignments.all()
6776

77+
6878
@strawberry_django.type(
6979
models.ACLExtendedRule,
70-
fields='__all__',
71-
filters=ACLExtendedRuleFilter
80+
fields="__all__",
81+
filters=filters.ACLExtendedRuleFilter,
7282
)
73-
7483
class ACLExtendedRuleType(OrganizationalObjectType):
7584
"""
7685
Defines the object type for the django model ACLExtendedRule.
7786
"""
87+
7888
source_ports: List[int]
7989
destination_ports: List[int]
8090
access_list: Annotated["AccessListType", strawberry.lazy("netbox_acls.graphql.types")]
@@ -85,29 +95,34 @@ class Meta:
8595
"""
8696
Associates the filterset, fields, and model for the django model ACLExtendedRule.
8797
"""
98+
8899
@strawberry_django.field
89-
def aclextendedrules(self) -> List[Annotated["ACLExtendedRule", strawberry.lazy('aclextendedrule.graphql.types')]]:
100+
def aclextendedrules(
101+
self,
102+
) -> List[Annotated["ACLExtendedRule", strawberry.lazy("aclextendedrule.graphql.types")]]:
90103
return self.aclextendedrules.all()
91104

92105

93106
@strawberry_django.type(
94107
models.ACLStandardRule,
95-
fields='__all__',
96-
filters=ACLStandardRuleFilter
108+
fields="__all__",
109+
filters=filters.ACLStandardRuleFilter,
97110
)
98-
99111
class ACLStandardRuleType(OrganizationalObjectType):
100112
"""
101113
Defines the object type for the django model ACLStandardRule.
102114
"""
115+
103116
access_list: Annotated["AccessListType", strawberry.lazy("netbox_acls.graphql.types")]
104117
source_prefix: Annotated["PrefixType", strawberry.lazy("ipam.graphql.types")]
105118

106119
class Meta:
107120
"""
108121
Associates the filterset, fields, and model for the django model ACLExtendedRule.
109122
"""
123+
110124
@strawberry_django.field
111-
def aclstandardrules(self) -> List[Annotated["ACLStandardRule", strawberry.lazy('aclstandardrule.graphql.types')]]:
125+
def aclstandardrules(
126+
self,
127+
) -> List[Annotated["ACLStandardRule", strawberry.lazy("aclstandardrule.graphql.types")]]:
112128
return self.aclstandardrules.all()
113-

0 commit comments

Comments
 (0)