|
1 | | -import graphene |
| 1 | +from typing import Annotated, List |
2 | 2 |
|
3 | | -from circuits import filtersets, models |
| 3 | +import strawberry |
| 4 | +import strawberry_django |
| 5 | + |
| 6 | +from circuits import models |
4 | 7 | from dcim.graphql.mixins import CabledObjectMixin |
5 | | -from extras.graphql.mixins import CustomFieldsMixin, TagsMixin, ContactsMixin |
6 | | -from netbox.graphql.types import ObjectType, OrganizationalObjectType, NetBoxObjectType |
| 8 | +from extras.graphql.mixins import ContactsMixin, CustomFieldsMixin, TagsMixin |
| 9 | +from netbox.graphql.types import NetBoxObjectType, ObjectType, OrganizationalObjectType |
| 10 | +from tenancy.graphql.types import TenantType |
| 11 | +from .filters import * |
7 | 12 |
|
8 | 13 | __all__ = ( |
9 | 14 | 'CircuitTerminationType', |
|
15 | 20 | ) |
16 | 21 |
|
17 | 22 |
|
18 | | -class CircuitTerminationType(CustomFieldsMixin, TagsMixin, CabledObjectMixin, ObjectType): |
| 23 | +@strawberry_django.type( |
| 24 | + models.Provider, |
| 25 | + fields='__all__', |
| 26 | + filters=ProviderFilter |
| 27 | +) |
| 28 | +class ProviderType(NetBoxObjectType, ContactsMixin): |
19 | 29 |
|
20 | | - class Meta: |
21 | | - model = models.CircuitTermination |
22 | | - fields = '__all__' |
23 | | - filterset_class = filtersets.CircuitTerminationFilterSet |
| 30 | + @strawberry_django.field |
| 31 | + def networks(self) -> List[Annotated["ProviderNetworkType", strawberry.lazy('circuits.graphql.types')]]: |
| 32 | + return self.networks.all() |
24 | 33 |
|
| 34 | + @strawberry_django.field |
| 35 | + def circuits(self) -> List[Annotated["CircuitType", strawberry.lazy('circuits.graphql.types')]]: |
| 36 | + return self.circuits.all() |
25 | 37 |
|
26 | | -class CircuitType(NetBoxObjectType, ContactsMixin): |
27 | | - class Meta: |
28 | | - model = models.Circuit |
29 | | - fields = '__all__' |
30 | | - filterset_class = filtersets.CircuitFilterSet |
| 38 | + @strawberry_django.field |
| 39 | + def asns(self) -> List[Annotated["ASNType", strawberry.lazy('ipam.graphql.types')]]: |
| 40 | + return self.asns.all() |
31 | 41 |
|
| 42 | + @strawberry_django.field |
| 43 | + def accounts(self) -> List[Annotated["ProviderAccountType", strawberry.lazy('circuits.graphql.types')]]: |
| 44 | + return self.accounts.all() |
32 | 45 |
|
33 | | -class CircuitTypeType(OrganizationalObjectType): |
34 | 46 |
|
35 | | - class Meta: |
36 | | - model = models.CircuitType |
37 | | - fields = '__all__' |
38 | | - filterset_class = filtersets.CircuitTypeFilterSet |
| 47 | +@strawberry_django.type( |
| 48 | + models.ProviderAccount, |
| 49 | + fields='__all__', |
| 50 | + filters=ProviderAccountFilter |
| 51 | +) |
| 52 | +class ProviderAccountType(NetBoxObjectType): |
| 53 | + provider: Annotated["ProviderType", strawberry.lazy('circuits.graphql.types')] |
39 | 54 |
|
| 55 | + @strawberry_django.field |
| 56 | + def circuits(self) -> List[Annotated["CircuitType", strawberry.lazy('circuits.graphql.types')]]: |
| 57 | + return self.circuits.all() |
40 | 58 |
|
41 | | -class ProviderType(NetBoxObjectType, ContactsMixin): |
42 | 59 |
|
43 | | - class Meta: |
44 | | - model = models.Provider |
45 | | - fields = '__all__' |
46 | | - filterset_class = filtersets.ProviderFilterSet |
| 60 | +@strawberry_django.type( |
| 61 | + models.ProviderNetwork, |
| 62 | + fields='__all__', |
| 63 | + filters=ProviderNetworkFilter |
| 64 | +) |
| 65 | +class ProviderNetworkType(NetBoxObjectType): |
| 66 | + provider: Annotated["ProviderType", strawberry.lazy('circuits.graphql.types')] |
47 | 67 |
|
| 68 | + @strawberry_django.field |
| 69 | + def circuit_terminations(self) -> List[Annotated["CircuitTerminationType", strawberry.lazy('circuits.graphql.types')]]: |
| 70 | + return self.circuit_terminations.all() |
48 | 71 |
|
49 | | -class ProviderAccountType(NetBoxObjectType): |
50 | 72 |
|
51 | | - class Meta: |
52 | | - model = models.ProviderAccount |
53 | | - fields = '__all__' |
54 | | - filterset_class = filtersets.ProviderAccountFilterSet |
| 73 | +@strawberry_django.type( |
| 74 | + models.CircuitTermination, |
| 75 | + fields='__all__', |
| 76 | + filters=CircuitTerminationFilter |
| 77 | +) |
| 78 | +class CircuitTerminationType(CustomFieldsMixin, TagsMixin, CabledObjectMixin, ObjectType): |
| 79 | + circuit: Annotated["CircuitType", strawberry.lazy('circuits.graphql.types')] |
| 80 | + provider_network: Annotated["ProviderNetworkType", strawberry.lazy('circuits.graphql.types')] | None |
| 81 | + site: Annotated["SiteType", strawberry.lazy('dcim.graphql.types')] | None |
55 | 82 |
|
56 | 83 |
|
57 | | -class ProviderNetworkType(NetBoxObjectType): |
| 84 | +@strawberry_django.type( |
| 85 | + models.CircuitType, |
| 86 | + fields='__all__', |
| 87 | + filters=CircuitTypeFilter |
| 88 | +) |
| 89 | +class CircuitTypeType(OrganizationalObjectType): |
| 90 | + color: str |
| 91 | + |
| 92 | + @strawberry_django.field |
| 93 | + def circuits(self) -> List[Annotated["CircuitType", strawberry.lazy('circuits.graphql.types')]]: |
| 94 | + return self.circuits.all() |
| 95 | + |
58 | 96 |
|
59 | | - class Meta: |
60 | | - model = models.ProviderNetwork |
61 | | - fields = '__all__' |
62 | | - filterset_class = filtersets.ProviderNetworkFilterSet |
| 97 | +@strawberry_django.type( |
| 98 | + models.Circuit, |
| 99 | + fields='__all__', |
| 100 | + filters=CircuitFilter |
| 101 | +) |
| 102 | +class CircuitType(NetBoxObjectType, ContactsMixin): |
| 103 | + provider: ProviderType |
| 104 | + provider_account: ProviderAccountType | None |
| 105 | + termination_a: CircuitTerminationType | None |
| 106 | + termination_z: CircuitTerminationType | None |
| 107 | + type: CircuitTypeType |
| 108 | + tenant: TenantType | None |
| 109 | + |
| 110 | + @strawberry_django.field |
| 111 | + def terminations(self) -> List[CircuitTerminationType]: |
| 112 | + return self.terminations.all() |
0 commit comments