-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #191 from joshuajcoronado/graphqlv2
Add netbox v4 graphql support
- Loading branch information
Showing
5 changed files
with
267 additions
and
80 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from .schema import ( | ||
AssetQuery, | ||
SupplierQuery, | ||
PurchaseQuery, | ||
DeliveryQuery, | ||
InventoryItemTypeQuery, | ||
InventoryItemGroupQuery, | ||
) | ||
|
||
schema = [ | ||
AssetQuery, | ||
SupplierQuery, | ||
PurchaseQuery, | ||
DeliveryQuery, | ||
InventoryItemTypeQuery, | ||
InventoryItemGroupQuery, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import strawberry_django | ||
|
||
from netbox.graphql.filter_mixins import autotype_decorator, BaseFilterMixin | ||
|
||
from netbox_inventory import filtersets, models | ||
|
||
__all__ = ( | ||
"AssetFilter", | ||
"SupplierFilter", | ||
"PurchaseFilter", | ||
"DeliveryFilter", | ||
"InventoryItemTypeFilter", | ||
"InventoryItemGroupFilter", | ||
) | ||
|
||
|
||
@strawberry_django.filter(models.Asset, lookups=True) | ||
@autotype_decorator(filtersets.AssetFilterSet) | ||
class AssetFilter(BaseFilterMixin): | ||
pass | ||
|
||
|
||
@strawberry_django.filter(models.Supplier, lookups=True) | ||
@autotype_decorator(filtersets.SupplierFilterSet) | ||
class SupplierFilter(BaseFilterMixin): | ||
pass | ||
|
||
|
||
@strawberry_django.filter(models.Purchase, lookups=True) | ||
@autotype_decorator(filtersets.PurchaseFilterSet) | ||
class PurchaseFilter(BaseFilterMixin): | ||
pass | ||
|
||
|
||
@strawberry_django.filter(models.Delivery, lookups=True) | ||
@autotype_decorator(filtersets.DeliveryFilterSet) | ||
class DeliveryFilter(BaseFilterMixin): | ||
pass | ||
|
||
|
||
@strawberry_django.filter(models.InventoryItemType, lookups=True) | ||
@autotype_decorator(filtersets.InventoryItemTypeFilterSet) | ||
class InventoryItemTypeFilter(BaseFilterMixin): | ||
pass | ||
|
||
|
||
@strawberry_django.filter(models.InventoryItemGroup, lookups=True) | ||
@autotype_decorator(filtersets.InventoryItemGroupFilterSet) | ||
class InventoryItemGroupFilter(BaseFilterMixin): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import strawberry | ||
import strawberry_django | ||
|
||
from netbox_inventory.models import ( | ||
Asset, | ||
Supplier, | ||
Purchase, | ||
Delivery, | ||
InventoryItemType, | ||
InventoryItemGroup, | ||
) | ||
from .types import ( | ||
AssetType, | ||
SupplierType, | ||
PurchaseType, | ||
DeliveryType, | ||
InventoryItemTypeType, | ||
InventoryItemGroupType, | ||
) | ||
|
||
|
||
@strawberry.type | ||
class AssetQuery: | ||
@strawberry.field | ||
def asset(self, id: int) -> AssetType: | ||
return Asset.objects.get(pk=id) | ||
|
||
asset_list: list[AssetType] = strawberry_django.field() | ||
|
||
|
||
@strawberry.type | ||
class SupplierQuery: | ||
@strawberry.field | ||
def supplier(self, id: int) -> SupplierType: | ||
return Supplier.objects.get(pk=id) | ||
|
||
supplier_list: list[SupplierType] = strawberry_django.field() | ||
|
||
|
||
@strawberry.type | ||
class PurchaseQuery: | ||
@strawberry.field | ||
def purchase(self, id: int) -> PurchaseType: | ||
return Purchase.objects.get(pk=id) | ||
|
||
purchase_list: list[PurchaseType] = strawberry_django.field() | ||
|
||
|
||
@strawberry.type | ||
class DeliveryQuery: | ||
@strawberry.field | ||
def delivery(self, id: int) -> DeliveryType: | ||
return Delivery.objects.get(pk=id) | ||
|
||
delivery_list: list[DeliveryType] = strawberry_django.field() | ||
|
||
|
||
@strawberry.type | ||
class InventoryItemTypeQuery: | ||
@strawberry.field | ||
def inventory_item_type(self, id: int) -> InventoryItemTypeType: | ||
return InventoryItemType.objects.get(pk=id) | ||
|
||
inventory_item_type_list: list[InventoryItemTypeType] = strawberry_django.field() | ||
|
||
|
||
@strawberry.type | ||
class InventoryItemGroupQuery: | ||
@strawberry.field | ||
def inventory_item_group(self, id: int) -> InventoryItemGroupType: | ||
return InventoryItemGroup.objects.get(pk=id) | ||
|
||
inventory_item_group_list: list[InventoryItemGroupType] = strawberry_django.field() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import strawberry | ||
import strawberry_django | ||
from typing import Annotated | ||
from extras.graphql.mixins import ContactsMixin, ImageAttachmentsMixin | ||
from netbox.graphql.types import ( | ||
NetBoxObjectType, | ||
OrganizationalObjectType, | ||
) | ||
from netbox_inventory.models import ( | ||
Asset, | ||
Supplier, | ||
Purchase, | ||
Delivery, | ||
InventoryItemType, | ||
InventoryItemGroup, | ||
) | ||
from .filters import ( | ||
AssetFilter, | ||
SupplierFilter, | ||
PurchaseFilter, | ||
DeliveryFilter, | ||
InventoryItemTypeFilter, | ||
InventoryItemGroupFilter, | ||
) | ||
|
||
|
||
@strawberry_django.type(Asset, fields="__all__", filters=AssetFilter) | ||
class AssetType(ImageAttachmentsMixin, NetBoxObjectType): | ||
device_type: ( | ||
Annotated["DeviceTypeType", strawberry.lazy("dcim.graphql.types")] | None | ||
) | ||
module_type: ( | ||
Annotated["ModuleTypeType", strawberry.lazy("dcim.graphql.types")] | None | ||
) | ||
inventoryitem_type: ( | ||
Annotated[ | ||
"InventoryItemTypeType", strawberry.lazy("netbox_inventory.graphql.types") | ||
] | ||
| None | ||
) | ||
tenant: Annotated["TenantType", strawberry.lazy("tenancy.graphql.types")] | None | ||
device: Annotated["DeviceType", strawberry.lazy("dcim.graphql.types")] | None | ||
module: Annotated["ModuleType", strawberry.lazy("dcim.graphql.types")] | None | ||
contact: Annotated["ContactType", strawberry.lazy("tenancy.graphql.types")] | None | ||
inventoryitem: ( | ||
Annotated["InventoryItemType", strawberry.lazy("dcim.graphql.types")] | None | ||
) | ||
storage_location: ( | ||
Annotated["LocationType", strawberry.lazy("dcim.graphql.types")] | None | ||
) | ||
owner: Annotated["TenantType", strawberry.lazy("tenancy.graphql.types")] | None | ||
delivery: ( | ||
Annotated["DeliveryType", strawberry.lazy("netbox_inventory.graphql.types")] | ||
| None | ||
) | ||
purchase: ( | ||
Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")] | ||
| None | ||
) | ||
|
||
|
||
@strawberry_django.type(Supplier, fields="__all__", filters=SupplierFilter) | ||
class SupplierType(ContactsMixin, NetBoxObjectType): | ||
purchases: list[ | ||
Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")] | ||
] | ||
|
||
|
||
@strawberry_django.type(Purchase, fields="__all__", filters=PurchaseFilter) | ||
class PurchaseType(NetBoxObjectType): | ||
supplier: Annotated[ | ||
"SupplierType", strawberry.lazy("netbox_inventory.graphql.types") | ||
] | ||
assets: list[ | ||
Annotated["AssetType", strawberry.lazy("netbox_inventory.graphql.types")] | ||
] | ||
orders: list[ | ||
Annotated["DeliveryType", strawberry.lazy("netbox_inventory.graphql.types")] | ||
] | ||
|
||
|
||
@strawberry_django.type(Delivery, fields="__all__", filters=DeliveryFilter) | ||
class DeliveryType(NetBoxObjectType): | ||
purchase: Annotated[ | ||
"PurchaseType", strawberry.lazy("netbox_inventory.graphql.types") | ||
] | ||
receiving_contact: ( | ||
Annotated["ContactType", strawberry.lazy("tenancy.graphql.types")] | None | ||
) | ||
assets: list[ | ||
Annotated["AssetType", strawberry.lazy("netbox_inventory.graphql.types")] | ||
] | ||
|
||
|
||
@strawberry_django.type( | ||
InventoryItemType, fields="__all__", filters=InventoryItemTypeFilter | ||
) | ||
class InventoryItemTypeType(ImageAttachmentsMixin, NetBoxObjectType): | ||
manufacturer: Annotated["ManufacturerType", strawberry.lazy("dcim.graphql.types")] | ||
inventoryitem_group: ( | ||
Annotated[ | ||
"InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types") | ||
] | ||
| None | ||
) | ||
|
||
|
||
@strawberry_django.type( | ||
InventoryItemGroup, fields="__all__", filters=InventoryItemGroupFilter | ||
) | ||
class InventoryItemGroupType(OrganizationalObjectType): | ||
parent: ( | ||
Annotated[ | ||
"InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types") | ||
] | ||
| None | ||
) | ||
inventoryitem_types: list[ | ||
Annotated[ | ||
"InventoryItemTypeType", strawberry.lazy("netbox_inventory.graphql.types") | ||
] | ||
] | ||
children: list[ | ||
Annotated[ | ||
"InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types") | ||
] | ||
] |