From 6bac64227da91906bc4c7d2a81326583ce9873d1 Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Tue, 27 Aug 2024 13:45:56 -0700 Subject: [PATCH 01/41] feat: update graphql for netbox v4 --- netbox_inventory/graphql.py | 160 ++++++++++++++++++++---------------- 1 file changed, 88 insertions(+), 72 deletions(-) diff --git a/netbox_inventory/graphql.py b/netbox_inventory/graphql.py index 02649c1..51dc3e0 100644 --- a/netbox_inventory/graphql.py +++ b/netbox_inventory/graphql.py @@ -1,14 +1,7 @@ -from graphene import ObjectType -from netbox.graphql.types import NetBoxObjectType -from netbox.graphql.fields import ObjectField, ObjectListField -from .filtersets import ( - AssetFilterSet, - SupplierFilterSet, - PurchaseFilterSet, - DeliveryFilterSet, - InventoryItemTypeFilterSet, - InventoryItemGroupFilterSet, -) +import strawberry +import strawberry_django +from typing import Annotated + from .models import ( Asset, Supplier, @@ -17,64 +10,87 @@ InventoryItemType, InventoryItemGroup, ) - - -class AssetType(NetBoxObjectType): - class Meta: - model = Asset - fields = "__all__" - filterset_class = AssetFilterSet - - -class SupplierType(NetBoxObjectType): - class Meta: - model = Supplier - fields = "__all__" - filterset_class = SupplierFilterSet - - -class PurchaseType(NetBoxObjectType): - class Meta: - model = Purchase - fields = "__all__" - filterset_class = PurchaseFilterSet - - -class DeliveryType(NetBoxObjectType): - class Meta: - model = Delivery - fields = "__all__" - filterset_class = DeliveryFilterSet - - -class InventoryItemTypeType(NetBoxObjectType): - class Meta: - model = InventoryItemType - fields = "__all__" - filterset_class = InventoryItemTypeFilterSet - - -class InventoryItemGroupType(NetBoxObjectType): - class Meta: - model = InventoryItemGroup - fields = "__all__" - filterset_class = InventoryItemGroupFilterSet - - -class Query(ObjectType): - asset = ObjectField(AssetType) - supplier = ObjectField(SupplierType) - purchase = ObjectField(PurchaseType) - delivery = ObjectField(DeliveryType) - inventory_item_type = ObjectField(InventoryItemTypeType) - inventory_item_group = ObjectField(InventoryItemGroupType) - - asset_list = ObjectListField(AssetType) - supplier_list = ObjectListField(SupplierType) - purchase_list = ObjectListField(PurchaseType) - delivery_list = ObjectListField(DeliveryType) - inventory_item_type_list = ObjectListField(InventoryItemTypeType) - inventory_item_group_list = ObjectListField(InventoryItemGroupType) - - -schema = Query +from .filtersets import ( + AssetFilterSet, + SupplierFilterSet, + PurchaseFilterSet, + DeliveryFilterSet, + InventoryItemTypeFilterSet, + InventoryItemGroupFilterSet, +) +from netbox.graphql.filter_mixins import autotype_decorator, BaseFilterMixin + +# Filter definitions using existing FilterSets +@strawberry_django.filter(Asset) +@autotype_decorator(AssetFilterSet) +class AssetFilter(BaseFilterMixin): + pass + +@strawberry_django.filter(Supplier) +@autotype_decorator(SupplierFilterSet) +class SupplierFilter(BaseFilterMixin): + pass + +@strawberry_django.filter(Purchase) +@autotype_decorator(PurchaseFilterSet) +class PurchaseFilter(BaseFilterMixin): + pass + +@strawberry_django.filter(Delivery) +@autotype_decorator(DeliveryFilterSet) +class DeliveryFilter(BaseFilterMixin): + pass + +@strawberry_django.filter(InventoryItemType) +@autotype_decorator(InventoryItemTypeFilterSet) +class InventoryItemTypeFilter(BaseFilterMixin): + pass + +@strawberry_django.filter(InventoryItemGroup) +@autotype_decorator(InventoryItemGroupFilterSet) +class InventoryItemGroupFilter(BaseFilterMixin): + pass + +# Type definitions +@strawberry_django.type(Asset, fields="__all__", filters=AssetFilter) +class AssetType: + pass + +@strawberry_django.type(Supplier, fields="__all__", filters=SupplierFilter) +class SupplierType: + pass + +@strawberry_django.type(Purchase, fields="__all__", filters=PurchaseFilter) +class PurchaseType: + pass + +@strawberry_django.type(Delivery, fields="__all__", filters=DeliveryFilter) +class DeliveryType: + pass + +@strawberry_django.type(InventoryItemType, fields="__all__", filters=InventoryItemTypeFilter) +class InventoryItemTypeType: + pass + +@strawberry_django.type(InventoryItemGroup, fields="__all__", filters=InventoryItemGroupFilter) +class InventoryItemGroupType: + pass + +# Query definition +@strawberry.type +class Query: + asset: AssetType = strawberry_django.field() + supplier: SupplierType = strawberry_django.field() + purchase: PurchaseType = strawberry_django.field() + delivery: DeliveryType = strawberry_django.field() + inventory_item_type: InventoryItemTypeType = strawberry_django.field() + inventory_item_group: InventoryItemGroupType = strawberry_django.field() + + asset_list: list[AssetType] = strawberry_django.field() + supplier_list: list[SupplierType] = strawberry_django.field() + purchase_list: list[PurchaseType] = strawberry_django.field() + delivery_list: list[DeliveryType] = strawberry_django.field() + inventory_item_type_list: list[InventoryItemTypeType] = strawberry_django.field() + inventory_item_group_list: list[InventoryItemGroupType] = strawberry_django.field() + +schema = strawberry.Schema(query=Query) \ No newline at end of file From e787d507a505222eda3fe5793f81c98ed9f859ae Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Tue, 27 Aug 2024 14:00:49 -0700 Subject: [PATCH 02/41] feat: update graphql for netbox v4 --- netbox_inventory/graphql.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/netbox_inventory/graphql.py b/netbox_inventory/graphql.py index 51dc3e0..0c9c3bc 100644 --- a/netbox_inventory/graphql.py +++ b/netbox_inventory/graphql.py @@ -1,6 +1,7 @@ import strawberry import strawberry_django -from typing import Annotated +from typing import Optional +from strawberry import LazyType from .models import ( Asset, @@ -20,7 +21,7 @@ ) from netbox.graphql.filter_mixins import autotype_decorator, BaseFilterMixin -# Filter definitions using existing FilterSets +# Filter definitions @strawberry_django.filter(Asset) @autotype_decorator(AssetFilterSet) class AssetFilter(BaseFilterMixin): @@ -74,7 +75,11 @@ class InventoryItemTypeType: @strawberry_django.type(InventoryItemGroup, fields="__all__", filters=InventoryItemGroupFilter) class InventoryItemGroupType: - pass + parent: Optional['InventoryItemGroupType'] = strawberry.field(default=None) + children: list['InventoryItemGroupType'] = strawberry.field(default_factory=list) + +InventoryItemGroupType.parent = strawberry.field(LazyType["InventoryItemGroupType", __name__]) +InventoryItemGroupType.children = strawberry.field(lambda: list[InventoryItemGroupType]) # Query definition @strawberry.type From b2b132f7b2736f6f7803acac98b93c35db088c80 Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Tue, 27 Aug 2024 14:47:56 -0700 Subject: [PATCH 03/41] feat: update graphql for netbox v4 --- netbox_inventory/graphql.py | 101 --------------------------- netbox_inventory/graphql/__init__.py | 17 +++++ netbox_inventory/graphql/filters.py | 46 ++++++++++++ netbox_inventory/graphql/schema.py | 47 +++++++++++++ netbox_inventory/graphql/types.py | 39 +++++++++++ 5 files changed, 149 insertions(+), 101 deletions(-) delete mode 100644 netbox_inventory/graphql.py create mode 100644 netbox_inventory/graphql/__init__.py create mode 100644 netbox_inventory/graphql/filters.py create mode 100644 netbox_inventory/graphql/schema.py create mode 100644 netbox_inventory/graphql/types.py diff --git a/netbox_inventory/graphql.py b/netbox_inventory/graphql.py deleted file mode 100644 index 0c9c3bc..0000000 --- a/netbox_inventory/graphql.py +++ /dev/null @@ -1,101 +0,0 @@ -import strawberry -import strawberry_django -from typing import Optional -from strawberry import LazyType - -from .models import ( - Asset, - Supplier, - Purchase, - Delivery, - InventoryItemType, - InventoryItemGroup, -) -from .filtersets import ( - AssetFilterSet, - SupplierFilterSet, - PurchaseFilterSet, - DeliveryFilterSet, - InventoryItemTypeFilterSet, - InventoryItemGroupFilterSet, -) -from netbox.graphql.filter_mixins import autotype_decorator, BaseFilterMixin - -# Filter definitions -@strawberry_django.filter(Asset) -@autotype_decorator(AssetFilterSet) -class AssetFilter(BaseFilterMixin): - pass - -@strawberry_django.filter(Supplier) -@autotype_decorator(SupplierFilterSet) -class SupplierFilter(BaseFilterMixin): - pass - -@strawberry_django.filter(Purchase) -@autotype_decorator(PurchaseFilterSet) -class PurchaseFilter(BaseFilterMixin): - pass - -@strawberry_django.filter(Delivery) -@autotype_decorator(DeliveryFilterSet) -class DeliveryFilter(BaseFilterMixin): - pass - -@strawberry_django.filter(InventoryItemType) -@autotype_decorator(InventoryItemTypeFilterSet) -class InventoryItemTypeFilter(BaseFilterMixin): - pass - -@strawberry_django.filter(InventoryItemGroup) -@autotype_decorator(InventoryItemGroupFilterSet) -class InventoryItemGroupFilter(BaseFilterMixin): - pass - -# Type definitions -@strawberry_django.type(Asset, fields="__all__", filters=AssetFilter) -class AssetType: - pass - -@strawberry_django.type(Supplier, fields="__all__", filters=SupplierFilter) -class SupplierType: - pass - -@strawberry_django.type(Purchase, fields="__all__", filters=PurchaseFilter) -class PurchaseType: - pass - -@strawberry_django.type(Delivery, fields="__all__", filters=DeliveryFilter) -class DeliveryType: - pass - -@strawberry_django.type(InventoryItemType, fields="__all__", filters=InventoryItemTypeFilter) -class InventoryItemTypeType: - pass - -@strawberry_django.type(InventoryItemGroup, fields="__all__", filters=InventoryItemGroupFilter) -class InventoryItemGroupType: - parent: Optional['InventoryItemGroupType'] = strawberry.field(default=None) - children: list['InventoryItemGroupType'] = strawberry.field(default_factory=list) - -InventoryItemGroupType.parent = strawberry.field(LazyType["InventoryItemGroupType", __name__]) -InventoryItemGroupType.children = strawberry.field(lambda: list[InventoryItemGroupType]) - -# Query definition -@strawberry.type -class Query: - asset: AssetType = strawberry_django.field() - supplier: SupplierType = strawberry_django.field() - purchase: PurchaseType = strawberry_django.field() - delivery: DeliveryType = strawberry_django.field() - inventory_item_type: InventoryItemTypeType = strawberry_django.field() - inventory_item_group: InventoryItemGroupType = strawberry_django.field() - - asset_list: list[AssetType] = strawberry_django.field() - supplier_list: list[SupplierType] = strawberry_django.field() - purchase_list: list[PurchaseType] = strawberry_django.field() - delivery_list: list[DeliveryType] = strawberry_django.field() - inventory_item_type_list: list[InventoryItemTypeType] = strawberry_django.field() - inventory_item_group_list: list[InventoryItemGroupType] = strawberry_django.field() - -schema = strawberry.Schema(query=Query) \ No newline at end of file diff --git a/netbox_inventory/graphql/__init__.py b/netbox_inventory/graphql/__init__.py new file mode 100644 index 0000000..bf72cbc --- /dev/null +++ b/netbox_inventory/graphql/__init__.py @@ -0,0 +1,17 @@ +from .schema import ( + AssetQuery, + SupplierQuery, + PurchaseQuery, + DeliveryQuery, + InventoryItemTypeQuery, + InventoryItemGroupQuery +) + +schema = [ + AssetQuery, + SupplierQuery, + PurchaseQuery, + DeliveryQuery, + InventoryItemTypeQuery, + InventoryItemGroupQuery +] \ No newline at end of file diff --git a/netbox_inventory/graphql/filters.py b/netbox_inventory/graphql/filters.py new file mode 100644 index 0000000..9acd9bf --- /dev/null +++ b/netbox_inventory/graphql/filters.py @@ -0,0 +1,46 @@ +import strawberry_django + +from netbox.graphql.filter_mixins import autotype_decorator, BaseFilterMixin + +from netbox_inventory.models import Asset, Supplier, Purchase, Delivery, InventoryItemType, InventoryItemGroup +from netbox_inventory.filtersets import AssetFilterSet, SupplierFilterSet, PurchaseFilterSet, DeliveryFilterSet, InventoryItemTypeFilterSet, InventoryItemGroupFilterSet + +__all__ = ( + 'AssetFilter', + 'SupplierFilter', + 'PurchaseFilter', + 'DeliveryFilter', + 'InventoryItemTypeFilter', + 'InventoryItemGroupFilter', +) + +@strawberry_django.filter(Asset, lookups=True) +@autotype_decorator(AssetFilterSet) +class AssetFilter(BaseFilterMixin): + pass + +@strawberry_django.filter(Supplier, lookups=True) +@autotype_decorator(SupplierFilterSet) +class SupplierFilter(BaseFilterMixin): + pass + +@strawberry_django.filter(Purchase, lookups=True) +@autotype_decorator(PurchaseFilterSet) +class PurchaseFilter(BaseFilterMixin): + pass + +@strawberry_django.filter(Delivery, lookups=True) +@autotype_decorator(DeliveryFilterSet) +class DeliveryFilter(BaseFilterMixin): + pass + +@strawberry_django.filter(InventoryItemType, lookups=True) +@autotype_decorator(InventoryItemTypeFilterSet) +class InventoryItemTypeFilter(BaseFilterMixin): + pass + +@strawberry_django.filter(InventoryItemGroup, lookups=True) +@autotype_decorator(InventoryItemGroupFilterSet) +class InventoryItemGroupFilter(BaseFilterMixin): + pass + diff --git a/netbox_inventory/graphql/schema.py b/netbox_inventory/graphql/schema.py new file mode 100644 index 0000000..dfccb09 --- /dev/null +++ b/netbox_inventory/graphql/schema.py @@ -0,0 +1,47 @@ +import strawberry +import strawberry_django + +import netbox_inventory.models as models +from .types import AssetType, SupplierType, PurchaseType, DeliveryType, InventoryItemTypeType, InventoryItemGroupType + +@strawberry.type +class AssetQuery: + @strawberry.field + def asset(self, id: int) -> AssetType: + return models.Asset.get(pk=id) + asset_list: list[AssetType] = strawberry_django.field() + +@strawberry.type +class SupplierQuery: + @strawberry.field + def supplier(self, id: int) -> SupplierType: + return models.Supplier.get(pk=id) + supplier_list: list[SupplierType] = strawberry_django.field() + +@strawberry.type +class PurchaseQuery: + @strawberry.field + def purchase(self, id: int) -> PurchaseType: + return models.Purchase.get(pk=id) + purchase_list: list[PurchaseType] = strawberry_django.field() + +@strawberry.type +class DeliveryQuery: + @strawberry.field + def delivery(self, id: int) -> DeliveryType: + return models.Delivery.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 models.InventoryItemType.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 models.InventoryItemGroup.get(pk=id) + inventory_item_group_list: list[InventoryItemGroupType] = strawberry_django.field() diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py new file mode 100644 index 0000000..281597b --- /dev/null +++ b/netbox_inventory/graphql/types.py @@ -0,0 +1,39 @@ +import strawberry +import strawberry_django +from typing import Annotated + +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: + # TODO: Fill in fields + pass + +@strawberry_django.type(Supplier, fields="__all__", filters=SupplierFilter) +class SupplierType: + # TODO: Fill in fields + pass + +@strawberry_django.type(Purchase, fields="__all__", filters=PurchaseFilter) +class PurchaseType: + # TODO: Fill in fields + pass + +@strawberry_django.type(Delivery, fields="__all__", filters=DeliveryFilter) +class DeliveryType: + # Add any custom fields or methods here if needed + pass + +@strawberry_django.type(InventoryItemType, fields="__all__", filters=InventoryItemTypeFilter) +class InventoryItemTypeType: + # TODO: Fill in fields + pass + +@strawberry_django.type(InventoryItemGroup, fields="__all__", filters=InventoryItemGroupFilter) +class InventoryItemGroupType: + # TODO: Fill in fields + pass From 8bda45693c979e514ea395308d93a52b7d877152 Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Tue, 27 Aug 2024 15:00:30 -0700 Subject: [PATCH 04/41] feat: update graphql for netbox v4 --- netbox_inventory/graphql/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox_inventory/graphql/__init__.py b/netbox_inventory/graphql/__init__.py index bf72cbc..ba10e81 100644 --- a/netbox_inventory/graphql/__init__.py +++ b/netbox_inventory/graphql/__init__.py @@ -13,5 +13,5 @@ PurchaseQuery, DeliveryQuery, InventoryItemTypeQuery, - InventoryItemGroupQuery + # InventoryItemGroupQuery # Commented out to due to circular dependency ] \ No newline at end of file From d18fd7c9b6231f21f38fa406be936ed59c828bf0 Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Tue, 27 Aug 2024 15:04:13 -0700 Subject: [PATCH 05/41] feat: update graphql for netbox v4 --- netbox_inventory/graphql/__init__.py | 2 +- netbox_inventory/graphql/filters.py | 33 ++++++++++++++++++++-------- netbox_inventory/graphql/schema.py | 21 ++++++++++++------ netbox_inventory/graphql/types.py | 18 ++++++++++----- 4 files changed, 51 insertions(+), 23 deletions(-) diff --git a/netbox_inventory/graphql/__init__.py b/netbox_inventory/graphql/__init__.py index ba10e81..1321a73 100644 --- a/netbox_inventory/graphql/__init__.py +++ b/netbox_inventory/graphql/__init__.py @@ -4,7 +4,7 @@ PurchaseQuery, DeliveryQuery, InventoryItemTypeQuery, - InventoryItemGroupQuery + # InventoryItemGroupQuery ) schema = [ diff --git a/netbox_inventory/graphql/filters.py b/netbox_inventory/graphql/filters.py index 9acd9bf..8c68873 100644 --- a/netbox_inventory/graphql/filters.py +++ b/netbox_inventory/graphql/filters.py @@ -2,8 +2,23 @@ from netbox.graphql.filter_mixins import autotype_decorator, BaseFilterMixin -from netbox_inventory.models import Asset, Supplier, Purchase, Delivery, InventoryItemType, InventoryItemGroup -from netbox_inventory.filtersets import AssetFilterSet, SupplierFilterSet, PurchaseFilterSet, DeliveryFilterSet, InventoryItemTypeFilterSet, InventoryItemGroupFilterSet +from netbox_inventory.models import ( + Asset, + Supplier, + Purchase, + Delivery, + InventoryItemType, + # InventoryItemGroup +) + +from netbox_inventory.filtersets import ( + AssetFilterSet, + SupplierFilterSet, + PurchaseFilterSet, + DeliveryFilterSet, + InventoryItemTypeFilterSet, + # InventoryItemGroupFilterSet +) __all__ = ( 'AssetFilter', @@ -11,7 +26,7 @@ 'PurchaseFilter', 'DeliveryFilter', 'InventoryItemTypeFilter', - 'InventoryItemGroupFilter', + # 'InventoryItemGroupFilter', ) @strawberry_django.filter(Asset, lookups=True) @@ -38,9 +53,9 @@ class DeliveryFilter(BaseFilterMixin): @autotype_decorator(InventoryItemTypeFilterSet) class InventoryItemTypeFilter(BaseFilterMixin): pass - -@strawberry_django.filter(InventoryItemGroup, lookups=True) -@autotype_decorator(InventoryItemGroupFilterSet) -class InventoryItemGroupFilter(BaseFilterMixin): - pass - +# +# @strawberry_django.filter(InventoryItemGroup, lookups=True) +# @autotype_decorator(InventoryItemGroupFilterSet) +# class InventoryItemGroupFilter(BaseFilterMixin): +# pass +# diff --git a/netbox_inventory/graphql/schema.py b/netbox_inventory/graphql/schema.py index dfccb09..6ae4b2d 100644 --- a/netbox_inventory/graphql/schema.py +++ b/netbox_inventory/graphql/schema.py @@ -2,7 +2,14 @@ import strawberry_django import netbox_inventory.models as models -from .types import AssetType, SupplierType, PurchaseType, DeliveryType, InventoryItemTypeType, InventoryItemGroupType +from .types import ( + AssetType, + SupplierType, + PurchaseType, + DeliveryType, + InventoryItemTypeType, + # InventoryItemGroupType + ) @strawberry.type class AssetQuery: @@ -39,9 +46,9 @@ def inventory_item_type(self, id: int) -> InventoryItemTypeType: return models.InventoryItemType.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 models.InventoryItemGroup.get(pk=id) - inventory_item_group_list: list[InventoryItemGroupType] = strawberry_django.field() +# @strawberry.type +# class InventoryItemGroupQuery: +# @strawberry.field +# def inventory_item_group(self, id: int) -> InventoryItemGroupType: +# return models.InventoryItemGroup.get(pk=id) +# inventory_item_group_list: list[InventoryItemGroupType] = strawberry_django.field() diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index 281597b..80aef7e 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -4,8 +4,14 @@ from netbox_inventory.models import Asset, Supplier, Purchase, Delivery, InventoryItemType, InventoryItemGroup -from .filters import AssetFilter, SupplierFilter, PurchaseFilter, DeliveryFilter, InventoryItemTypeFilter, \ - InventoryItemGroupFilter +from .filters import ( + AssetFilter, + SupplierFilter, + PurchaseFilter, + DeliveryFilter, + InventoryItemTypeFilter, + # InventoryItemGroupFilter +) @strawberry_django.type(Asset, fields="__all__", filters=AssetFilter) @@ -33,7 +39,7 @@ class InventoryItemTypeType: # TODO: Fill in fields pass -@strawberry_django.type(InventoryItemGroup, fields="__all__", filters=InventoryItemGroupFilter) -class InventoryItemGroupType: - # TODO: Fill in fields - pass +# @strawberry_django.type(InventoryItemGroup, fields="__all__", filters=InventoryItemGroupFilter) +# class InventoryItemGroupType: +# # TODO: Fill in fields +# pass From 88ad9bdf99208211c6624d90f75f558fc64bcc3a Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Tue, 27 Aug 2024 15:19:31 -0700 Subject: [PATCH 06/41] feat: update graphql for netbox v4 --- netbox_inventory/graphql/__init__.py | 4 +- netbox_inventory/graphql/filters.py | 16 ++-- netbox_inventory/graphql/schema.py | 14 ++-- netbox_inventory/graphql/types.py | 111 +++++++++++++++++++++++---- 4 files changed, 111 insertions(+), 34 deletions(-) diff --git a/netbox_inventory/graphql/__init__.py b/netbox_inventory/graphql/__init__.py index 1321a73..6fb54ca 100644 --- a/netbox_inventory/graphql/__init__.py +++ b/netbox_inventory/graphql/__init__.py @@ -4,7 +4,7 @@ PurchaseQuery, DeliveryQuery, InventoryItemTypeQuery, - # InventoryItemGroupQuery + InventoryItemGroupQuery ) schema = [ @@ -13,5 +13,5 @@ PurchaseQuery, DeliveryQuery, InventoryItemTypeQuery, - # InventoryItemGroupQuery # Commented out to due to circular dependency + InventoryItemGroupQuery # Commented out to due to circular dependency ] \ No newline at end of file diff --git a/netbox_inventory/graphql/filters.py b/netbox_inventory/graphql/filters.py index 8c68873..33936b7 100644 --- a/netbox_inventory/graphql/filters.py +++ b/netbox_inventory/graphql/filters.py @@ -8,7 +8,7 @@ Purchase, Delivery, InventoryItemType, - # InventoryItemGroup + InventoryItemGroup ) from netbox_inventory.filtersets import ( @@ -17,7 +17,7 @@ PurchaseFilterSet, DeliveryFilterSet, InventoryItemTypeFilterSet, - # InventoryItemGroupFilterSet + InventoryItemGroupFilterSet ) __all__ = ( @@ -53,9 +53,9 @@ class DeliveryFilter(BaseFilterMixin): @autotype_decorator(InventoryItemTypeFilterSet) class InventoryItemTypeFilter(BaseFilterMixin): pass -# -# @strawberry_django.filter(InventoryItemGroup, lookups=True) -# @autotype_decorator(InventoryItemGroupFilterSet) -# class InventoryItemGroupFilter(BaseFilterMixin): -# pass -# + +@strawberry_django.filter(InventoryItemGroup, lookups=True) +@autotype_decorator(InventoryItemGroupFilterSet) +class InventoryItemGroupFilter(BaseFilterMixin): + pass + diff --git a/netbox_inventory/graphql/schema.py b/netbox_inventory/graphql/schema.py index 6ae4b2d..289058a 100644 --- a/netbox_inventory/graphql/schema.py +++ b/netbox_inventory/graphql/schema.py @@ -8,7 +8,7 @@ PurchaseType, DeliveryType, InventoryItemTypeType, - # InventoryItemGroupType + InventoryItemGroupType ) @strawberry.type @@ -46,9 +46,9 @@ def inventory_item_type(self, id: int) -> InventoryItemTypeType: return models.InventoryItemType.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 models.InventoryItemGroup.get(pk=id) -# inventory_item_group_list: list[InventoryItemGroupType] = strawberry_django.field() +@strawberry.type +class InventoryItemGroupQuery: + @strawberry.field + def inventory_item_group(self, id: int) -> InventoryItemGroupType: + return models.InventoryItemGroup.get(pk=id) + inventory_item_group_list: list[InventoryItemGroupType] = strawberry_django.field() diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index 80aef7e..6f61c90 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -1,6 +1,6 @@ import strawberry import strawberry_django -from typing import Annotated +from typing import Annotated, Optional from netbox_inventory.models import Asset, Supplier, Purchase, Delivery, InventoryItemType, InventoryItemGroup @@ -10,36 +10,113 @@ PurchaseFilter, DeliveryFilter, InventoryItemTypeFilter, - # InventoryItemGroupFilter + InventoryItemGroupFilter ) - @strawberry_django.type(Asset, fields="__all__", filters=AssetFilter) class AssetType: - # TODO: Fill in fields - pass + @strawberry_django.field + def device_type(self) -> Optional[Annotated["DeviceType", strawberry.lazy("netbox.graphql.types")]]: + return self.device_type + + @strawberry_django.field + def module_type(self) -> Optional[Annotated["ModuleType", strawberry.lazy("netbox.graphql.types")]]: + return self.module_type + + @strawberry_django.field + def inventoryitem_type(self) -> Optional[Annotated["InventoryItemTypeType", strawberry.lazy("netbox_inventory.graphql.types")]]: + return self.inventoryitem_type + + @strawberry_django.field + def device(self) -> Optional[Annotated["Device", strawberry.lazy("netbox.graphql.types")]]: + return self.device + + @strawberry_django.field + def module(self) -> Optional[Annotated["Module", strawberry.lazy("netbox.graphql.types")]]: + return self.module + + @strawberry_django.field + def inventoryitem(self) -> Optional[Annotated["InventoryItem", strawberry.lazy("netbox.graphql.types")]]: + return self.inventoryitem + + @strawberry_django.field + def tenant(self) -> Optional[Annotated["Tenant", strawberry.lazy("netbox.graphql.types")]]: + return self.tenant + + @strawberry_django.field + def contact(self) -> Optional[Annotated["Contact", strawberry.lazy("netbox.graphql.types")]]: + return self.contact + + @strawberry_django.field + def storage_location(self) -> Optional[Annotated["Location", strawberry.lazy("netbox.graphql.types")]]: + return self.storage_location + + @strawberry_django.field + def owner(self) -> Optional[Annotated["Tenant", strawberry.lazy("netbox.graphql.types")]]: + return self.owner + + @strawberry_django.field + def delivery(self) -> Optional[Annotated["DeliveryType", strawberry.lazy("netbox_inventory.graphql.types")]]: + return self.delivery + + @strawberry_django.field + def purchase(self) -> Optional[Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")]]: + return self.purchase @strawberry_django.type(Supplier, fields="__all__", filters=SupplierFilter) class SupplierType: - # TODO: Fill in fields - pass + @strawberry_django.field + def purchases(self) -> list[Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")]]: + return self.purchases.all() @strawberry_django.type(Purchase, fields="__all__", filters=PurchaseFilter) class PurchaseType: - # TODO: Fill in fields - pass + @strawberry_django.field + def supplier(self) -> Annotated["SupplierType", strawberry.lazy("netbox_inventory.graphql.types")]: + return self.supplier + + @strawberry_django.field + def orders(self) -> list[Annotated["DeliveryType", strawberry.lazy("netbox_inventory.graphql.types")]]: + return self.orders.all() + + @strawberry_django.field + def assets(self) -> list[Annotated["AssetType", strawberry.lazy("netbox_inventory.graphql.types")]]: + return self.assets.all() @strawberry_django.type(Delivery, fields="__all__", filters=DeliveryFilter) class DeliveryType: - # Add any custom fields or methods here if needed - pass + @strawberry_django.field + def purchase(self) -> Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")]: + return self.purchase + + @strawberry_django.field + def receiving_contact(self) -> Optional[Annotated["Contact", strawberry.lazy("netbox.graphql.types")]]: + return self.receiving_contact + + @strawberry_django.field + def assets(self) -> list[Annotated["AssetType", strawberry.lazy("netbox_inventory.graphql.types")]]: + return self.assets.all() @strawberry_django.type(InventoryItemType, fields="__all__", filters=InventoryItemTypeFilter) class InventoryItemTypeType: - # TODO: Fill in fields - pass + @strawberry_django.field + def manufacturer(self) -> Annotated["Manufacturer", strawberry.lazy("netbox.graphql.types")]: + return self.manufacturer + + @strawberry_django.field + def inventoryitem_group(self) -> Optional[Annotated["InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types")]]: + return self.inventoryitem_group + +@strawberry_django.type(InventoryItemGroup, fields="__all__", filters=InventoryItemGroupFilter) +class InventoryItemGroupType: + @strawberry_django.field + def parent(self) -> Optional[Annotated["InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types")]]: + return self.parent + + @strawberry_django.field + def children(self) -> list[Annotated["InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types")]]: + return self.children.all() -# @strawberry_django.type(InventoryItemGroup, fields="__all__", filters=InventoryItemGroupFilter) -# class InventoryItemGroupType: -# # TODO: Fill in fields -# pass + @strawberry_django.field + def inventoryitem_types(self) -> list[Annotated["InventoryItemTypeType", strawberry.lazy("netbox_inventory.graphql.types")]]: + return self.inventoryitem_types.all() \ No newline at end of file From 2ed9fe5c9609bab031c5f58b4569bcb17d515f77 Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Wed, 28 Aug 2024 09:49:58 -0700 Subject: [PATCH 07/41] feat: update graphql for netbox v4 --- netbox_inventory/graphql/filters.py | 2 +- netbox_inventory/graphql/schema.py | 21 ++++++++++++------- netbox_inventory/graphql/types.py | 31 +++++++++++++++++++++++------ 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/netbox_inventory/graphql/filters.py b/netbox_inventory/graphql/filters.py index 33936b7..e9d6404 100644 --- a/netbox_inventory/graphql/filters.py +++ b/netbox_inventory/graphql/filters.py @@ -26,7 +26,7 @@ 'PurchaseFilter', 'DeliveryFilter', 'InventoryItemTypeFilter', - # 'InventoryItemGroupFilter', + 'InventoryItemGroupFilter', ) @strawberry_django.filter(Asset, lookups=True) diff --git a/netbox_inventory/graphql/schema.py b/netbox_inventory/graphql/schema.py index 289058a..ed03343 100644 --- a/netbox_inventory/graphql/schema.py +++ b/netbox_inventory/graphql/schema.py @@ -1,7 +1,14 @@ import strawberry import strawberry_django -import netbox_inventory.models as models +from netbox_inventory.models import ( + Asset, + Supplier, + Purchase, + Delivery, + InventoryItemType, + InventoryItemGroup +) from .types import ( AssetType, SupplierType, @@ -15,40 +22,40 @@ class AssetQuery: @strawberry.field def asset(self, id: int) -> AssetType: - return models.Asset.get(pk=id) + 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 models.Supplier.get(pk=id) + 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 models.Purchase.get(pk=id) + 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 models.Delivery.get(pk=id) + 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 models.InventoryItemType.get(pk=id) + 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 models.InventoryItemGroup.get(pk=id) + return InventoryItemGroup.objects.get(pk=id) inventory_item_group_list: list[InventoryItemGroupType] = strawberry_django.field() diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index 6f61c90..94b31ac 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -3,7 +3,7 @@ from typing import Annotated, Optional from netbox_inventory.models import Asset, Supplier, Purchase, Delivery, InventoryItemType, InventoryItemGroup - +from netbox_inventory.choices import AssetStatusChoices from .filters import ( AssetFilter, SupplierFilter, @@ -13,8 +13,18 @@ InventoryItemGroupFilter ) + @strawberry_django.type(Asset, fields="__all__", filters=AssetFilter) class AssetType: + name: str + asset_tag: Optional[str] + serial: Optional[str] + status: AssetStatusChoices + + @strawberry_django.field + def tags(self) -> list[Annotated["TagType", strawberry.lazy("netbox.graphql.types")]]: + return self.tags.all() + @strawberry_django.field def device_type(self) -> Optional[Annotated["DeviceType", strawberry.lazy("netbox.graphql.types")]]: return self.device_type @@ -24,7 +34,8 @@ def module_type(self) -> Optional[Annotated["ModuleType", strawberry.lazy("netbo return self.module_type @strawberry_django.field - def inventoryitem_type(self) -> Optional[Annotated["InventoryItemTypeType", strawberry.lazy("netbox_inventory.graphql.types")]]: + def inventoryitem_type(self) -> Optional[ + Annotated["InventoryItemTypeType", strawberry.lazy("netbox_inventory.graphql.types")]]: return self.inventoryitem_type @strawberry_django.field @@ -63,12 +74,14 @@ def delivery(self) -> Optional[Annotated["DeliveryType", strawberry.lazy("netbox def purchase(self) -> Optional[Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")]]: return self.purchase + @strawberry_django.type(Supplier, fields="__all__", filters=SupplierFilter) class SupplierType: @strawberry_django.field def purchases(self) -> list[Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")]]: return self.purchases.all() + @strawberry_django.type(Purchase, fields="__all__", filters=PurchaseFilter) class PurchaseType: @strawberry_django.field @@ -83,6 +96,7 @@ def orders(self) -> list[Annotated["DeliveryType", strawberry.lazy("netbox_inven def assets(self) -> list[Annotated["AssetType", strawberry.lazy("netbox_inventory.graphql.types")]]: return self.assets.all() + @strawberry_django.type(Delivery, fields="__all__", filters=DeliveryFilter) class DeliveryType: @strawberry_django.field @@ -97,6 +111,7 @@ def receiving_contact(self) -> Optional[Annotated["Contact", strawberry.lazy("ne def assets(self) -> list[Annotated["AssetType", strawberry.lazy("netbox_inventory.graphql.types")]]: return self.assets.all() + @strawberry_django.type(InventoryItemType, fields="__all__", filters=InventoryItemTypeFilter) class InventoryItemTypeType: @strawberry_django.field @@ -104,13 +119,16 @@ def manufacturer(self) -> Annotated["Manufacturer", strawberry.lazy("netbox.grap return self.manufacturer @strawberry_django.field - def inventoryitem_group(self) -> Optional[Annotated["InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types")]]: + def inventoryitem_group(self) -> Optional[ + Annotated["InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types")]]: return self.inventoryitem_group + @strawberry_django.type(InventoryItemGroup, fields="__all__", filters=InventoryItemGroupFilter) class InventoryItemGroupType: @strawberry_django.field - def parent(self) -> Optional[Annotated["InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types")]]: + def parent(self) -> Optional[ + Annotated["InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types")]]: return self.parent @strawberry_django.field @@ -118,5 +136,6 @@ def children(self) -> list[Annotated["InventoryItemGroupType", strawberry.lazy(" return self.children.all() @strawberry_django.field - def inventoryitem_types(self) -> list[Annotated["InventoryItemTypeType", strawberry.lazy("netbox_inventory.graphql.types")]]: - return self.inventoryitem_types.all() \ No newline at end of file + def inventoryitem_types(self) -> list[ + Annotated["InventoryItemTypeType", strawberry.lazy("netbox_inventory.graphql.types")]]: + return self.inventoryitem_types.all() From baca66dc2171b3a9ea683fdea41cf4bc4fdc466a Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Wed, 28 Aug 2024 09:53:47 -0700 Subject: [PATCH 08/41] feat: update netbox-inventory --- netbox_inventory/graphql/types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index 94b31ac..6ccd363 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -19,7 +19,7 @@ class AssetType: name: str asset_tag: Optional[str] serial: Optional[str] - status: AssetStatusChoices + # status: AssetStatusChoices @strawberry_django.field def tags(self) -> list[Annotated["TagType", strawberry.lazy("netbox.graphql.types")]]: From 8a4edbdbb77b3a5a696521d628230d7b53b3f34e Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Wed, 28 Aug 2024 09:58:38 -0700 Subject: [PATCH 09/41] feat: update netbox-inventory --- netbox_inventory/graphql/types.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index 6ccd363..33c8c70 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -21,9 +21,9 @@ class AssetType: serial: Optional[str] # status: AssetStatusChoices - @strawberry_django.field - def tags(self) -> list[Annotated["TagType", strawberry.lazy("netbox.graphql.types")]]: - return self.tags.all() + # @strawberry_django.field + # def tags(self) -> list[Annotated["TagType", strawberry.lazy("netbox.graphql.types")]]: + # return self.tags.all() @strawberry_django.field def device_type(self) -> Optional[Annotated["DeviceType", strawberry.lazy("netbox.graphql.types")]]: From 9e7b06b3901aef521acf68965f04f2dbace4893b Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Wed, 28 Aug 2024 10:15:10 -0700 Subject: [PATCH 10/41] feat: update netbox-inventory --- netbox_inventory/graphql/__init__.py | 2 +- netbox_inventory/graphql/types.py | 15 ++------------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/netbox_inventory/graphql/__init__.py b/netbox_inventory/graphql/__init__.py index 6fb54ca..ba10e81 100644 --- a/netbox_inventory/graphql/__init__.py +++ b/netbox_inventory/graphql/__init__.py @@ -13,5 +13,5 @@ PurchaseQuery, DeliveryQuery, InventoryItemTypeQuery, - InventoryItemGroupQuery # Commented out to due to circular dependency + # InventoryItemGroupQuery # Commented out to due to circular dependency ] \ No newline at end of file diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index 33c8c70..fd32d2d 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -13,7 +13,6 @@ InventoryItemGroupFilter ) - @strawberry_django.type(Asset, fields="__all__", filters=AssetFilter) class AssetType: name: str @@ -21,10 +20,6 @@ class AssetType: serial: Optional[str] # status: AssetStatusChoices - # @strawberry_django.field - # def tags(self) -> list[Annotated["TagType", strawberry.lazy("netbox.graphql.types")]]: - # return self.tags.all() - @strawberry_django.field def device_type(self) -> Optional[Annotated["DeviceType", strawberry.lazy("netbox.graphql.types")]]: return self.device_type @@ -74,14 +69,12 @@ def delivery(self) -> Optional[Annotated["DeliveryType", strawberry.lazy("netbox def purchase(self) -> Optional[Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")]]: return self.purchase - @strawberry_django.type(Supplier, fields="__all__", filters=SupplierFilter) class SupplierType: @strawberry_django.field def purchases(self) -> list[Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")]]: return self.purchases.all() - @strawberry_django.type(Purchase, fields="__all__", filters=PurchaseFilter) class PurchaseType: @strawberry_django.field @@ -96,7 +89,6 @@ def orders(self) -> list[Annotated["DeliveryType", strawberry.lazy("netbox_inven def assets(self) -> list[Annotated["AssetType", strawberry.lazy("netbox_inventory.graphql.types")]]: return self.assets.all() - @strawberry_django.type(Delivery, fields="__all__", filters=DeliveryFilter) class DeliveryType: @strawberry_django.field @@ -111,7 +103,6 @@ def receiving_contact(self) -> Optional[Annotated["Contact", strawberry.lazy("ne def assets(self) -> list[Annotated["AssetType", strawberry.lazy("netbox_inventory.graphql.types")]]: return self.assets.all() - @strawberry_django.type(InventoryItemType, fields="__all__", filters=InventoryItemTypeFilter) class InventoryItemTypeType: @strawberry_django.field @@ -123,12 +114,10 @@ def inventoryitem_group(self) -> Optional[ Annotated["InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types")]]: return self.inventoryitem_group - @strawberry_django.type(InventoryItemGroup, fields="__all__", filters=InventoryItemGroupFilter) class InventoryItemGroupType: @strawberry_django.field - def parent(self) -> Optional[ - Annotated["InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types")]]: + def parent(self) -> Optional[Annotated["InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types")]]: return self.parent @strawberry_django.field @@ -138,4 +127,4 @@ def children(self) -> list[Annotated["InventoryItemGroupType", strawberry.lazy(" @strawberry_django.field def inventoryitem_types(self) -> list[ Annotated["InventoryItemTypeType", strawberry.lazy("netbox_inventory.graphql.types")]]: - return self.inventoryitem_types.all() + return self.inventoryitem_types.all() \ No newline at end of file From 9ac76229b4ce51d70f3d097c95700cbe29e047cb Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Wed, 28 Aug 2024 10:30:50 -0700 Subject: [PATCH 11/41] feat: update netbox-inventory --- netbox_inventory/graphql/types.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index fd32d2d..1da9be8 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -15,38 +15,38 @@ @strawberry_django.type(Asset, fields="__all__", filters=AssetFilter) class AssetType: - name: str - asset_tag: Optional[str] - serial: Optional[str] + # name: str + # asset_tag: Optional[str] + # serial: Optional[str] # status: AssetStatusChoices @strawberry_django.field - def device_type(self) -> Optional[Annotated["DeviceType", strawberry.lazy("netbox.graphql.types")]]: + def device_type(self) -> Optional[Annotated["DeviceTypeType", strawberry.lazy("netbox.dcim.graphql.types")]]: return self.device_type @strawberry_django.field - def module_type(self) -> Optional[Annotated["ModuleType", strawberry.lazy("netbox.graphql.types")]]: + def module_type(self) -> Optional[Annotated["ModuleTypeType", strawberry.lazy("netbox.dcim.graphql.types")]]: return self.module_type - @strawberry_django.field - def inventoryitem_type(self) -> Optional[ - Annotated["InventoryItemTypeType", strawberry.lazy("netbox_inventory.graphql.types")]]: - return self.inventoryitem_type + # @strawberry_django.field + # def inventoryitem_type(self) -> Optional[ + # Annotated["InventoryItemTypeType", strawberry.lazy("netbox_inventory.graphql.types")]]: + # return self.inventoryitem_type @strawberry_django.field - def device(self) -> Optional[Annotated["Device", strawberry.lazy("netbox.graphql.types")]]: + def device(self) -> Optional[Annotated["DeviceType", strawberry.lazy("netbox.dcim.graphql.types")]]: return self.device @strawberry_django.field - def module(self) -> Optional[Annotated["Module", strawberry.lazy("netbox.graphql.types")]]: + def module(self) -> Optional[Annotated["ModuleType", strawberry.lazy("netbox.dcim.graphql.types")]]: return self.module @strawberry_django.field - def inventoryitem(self) -> Optional[Annotated["InventoryItem", strawberry.lazy("netbox.graphql.types")]]: + def inventoryitem(self) -> Optional[Annotated["InventoryItemType", strawberry.lazy("netbox.dcim.graphql.types")]]: return self.inventoryitem @strawberry_django.field - def tenant(self) -> Optional[Annotated["Tenant", strawberry.lazy("netbox.graphql.types")]]: + def tenant(self) -> Optional[Annotated["Tenant", strawberry.lazy("netbox.dcim.graphql.types")]]: return self.tenant @strawberry_django.field From bfce5112c1a2a9c1d7848c0e20e5a6e6765375e1 Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Wed, 28 Aug 2024 10:41:53 -0700 Subject: [PATCH 12/41] feat: update netbox-inventory --- netbox_inventory/graphql/types.py | 87 ++++++++++++++++--------------- 1 file changed, 45 insertions(+), 42 deletions(-) diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index 1da9be8..7e4338f 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -13,61 +13,64 @@ InventoryItemGroupFilter ) + + @strawberry_django.type(Asset, fields="__all__", filters=AssetFilter) class AssetType: + device_type: Annotated["DeviceTypeType", strawberry.lazy('netbox.dcim.graphql.types')] | None # name: str # asset_tag: Optional[str] # serial: Optional[str] # status: AssetStatusChoices - @strawberry_django.field - def device_type(self) -> Optional[Annotated["DeviceTypeType", strawberry.lazy("netbox.dcim.graphql.types")]]: - return self.device_type - - @strawberry_django.field - def module_type(self) -> Optional[Annotated["ModuleTypeType", strawberry.lazy("netbox.dcim.graphql.types")]]: - return self.module_type + # @strawberry_django.field + # def device_type(self) -> Annotated["DeviceTypeType", strawberry.lazy('dcim.graphql.types')] | None + # return self.device_type + # + # @strawberry_django.field + # def module_type(self) -> Optional[Annotated["ModuleTypeType", strawberry.lazy("netbox.dcim.graphql.types")]]: + # return self.module_type # @strawberry_django.field # def inventoryitem_type(self) -> Optional[ # Annotated["InventoryItemTypeType", strawberry.lazy("netbox_inventory.graphql.types")]]: # return self.inventoryitem_type - @strawberry_django.field - def device(self) -> Optional[Annotated["DeviceType", strawberry.lazy("netbox.dcim.graphql.types")]]: - return self.device - - @strawberry_django.field - def module(self) -> Optional[Annotated["ModuleType", strawberry.lazy("netbox.dcim.graphql.types")]]: - return self.module - - @strawberry_django.field - def inventoryitem(self) -> Optional[Annotated["InventoryItemType", strawberry.lazy("netbox.dcim.graphql.types")]]: - return self.inventoryitem - - @strawberry_django.field - def tenant(self) -> Optional[Annotated["Tenant", strawberry.lazy("netbox.dcim.graphql.types")]]: - return self.tenant - - @strawberry_django.field - def contact(self) -> Optional[Annotated["Contact", strawberry.lazy("netbox.graphql.types")]]: - return self.contact - - @strawberry_django.field - def storage_location(self) -> Optional[Annotated["Location", strawberry.lazy("netbox.graphql.types")]]: - return self.storage_location - - @strawberry_django.field - def owner(self) -> Optional[Annotated["Tenant", strawberry.lazy("netbox.graphql.types")]]: - return self.owner - - @strawberry_django.field - def delivery(self) -> Optional[Annotated["DeliveryType", strawberry.lazy("netbox_inventory.graphql.types")]]: - return self.delivery - - @strawberry_django.field - def purchase(self) -> Optional[Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")]]: - return self.purchase + # @strawberry_django.field + # def device(self) -> Optional[Annotated["DeviceType", strawberry.lazy("netbox.dcim.graphql.types")]]: + # return self.device + # + # @strawberry_django.field + # def module(self) -> Optional[Annotated["ModuleType", strawberry.lazy("netbox.dcim.graphql.types")]]: + # return self.module + # + # @strawberry_django.field + # def inventoryitem(self) -> Optional[Annotated["InventoryItemType", strawberry.lazy("netbox.dcim.graphql.types")]]: + # return self.inventoryitem + # + # @strawberry_django.field + # def tenant(self) -> Optional[Annotated["Tenant", strawberry.lazy("netbox.dcim.graphql.types")]]: + # return self.tenant + # + # @strawberry_django.field + # def contact(self) -> Optional[Annotated["Contact", strawberry.lazy("netbox.graphql.types")]]: + # return self.contact + # + # @strawberry_django.field + # def storage_location(self) -> Optional[Annotated["Location", strawberry.lazy("netbox.graphql.types")]]: + # return self.storage_location + # + # @strawberry_django.field + # def owner(self) -> Optional[Annotated["Tenant", strawberry.lazy("netbox.graphql.types")]]: + # return self.owner + # + # @strawberry_django.field + # def delivery(self) -> Optional[Annotated["DeliveryType", strawberry.lazy("netbox_inventory.graphql.types")]]: + # return self.delivery + # + # @strawberry_django.field + # def purchase(self) -> Optional[Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")]]: + # return self.purchase @strawberry_django.type(Supplier, fields="__all__", filters=SupplierFilter) class SupplierType: From 0c91d415cefcf7b4834577f3d8079d24051b77cf Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Wed, 28 Aug 2024 10:56:24 -0700 Subject: [PATCH 13/41] feat: update netbox-inventory --- netbox_inventory/graphql/filters.py | 43 +++++++++-------------------- 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/netbox_inventory/graphql/filters.py b/netbox_inventory/graphql/filters.py index e9d6404..46885c8 100644 --- a/netbox_inventory/graphql/filters.py +++ b/netbox_inventory/graphql/filters.py @@ -2,24 +2,7 @@ from netbox.graphql.filter_mixins import autotype_decorator, BaseFilterMixin -from netbox_inventory.models import ( - Asset, - Supplier, - Purchase, - Delivery, - InventoryItemType, - InventoryItemGroup -) - -from netbox_inventory.filtersets import ( - AssetFilterSet, - SupplierFilterSet, - PurchaseFilterSet, - DeliveryFilterSet, - InventoryItemTypeFilterSet, - InventoryItemGroupFilterSet -) - +from netbox_inventory import filtersets, models __all__ = ( 'AssetFilter', 'SupplierFilter', @@ -29,33 +12,33 @@ 'InventoryItemGroupFilter', ) -@strawberry_django.filter(Asset, lookups=True) -@autotype_decorator(AssetFilterSet) +@strawberry_django.filter(models.Asset, lookups=True) +@autotype_decorator(filtersets.AssetFilterSet) class AssetFilter(BaseFilterMixin): pass -@strawberry_django.filter(Supplier, lookups=True) -@autotype_decorator(SupplierFilterSet) +@strawberry_django.filter(models.Supplier, lookups=True) +@autotype_decorator(filtersets.SupplierFilterSet) class SupplierFilter(BaseFilterMixin): pass -@strawberry_django.filter(Purchase, lookups=True) -@autotype_decorator(PurchaseFilterSet) +@strawberry_django.filter(models.Purchase, lookups=True) +@autotype_decorator(filtersets.PurchaseFilterSet) class PurchaseFilter(BaseFilterMixin): pass -@strawberry_django.filter(Delivery, lookups=True) -@autotype_decorator(DeliveryFilterSet) +@strawberry_django.filter(models.Delivery, lookups=True) +@autotype_decorator(filtersets.DeliveryFilterSet) class DeliveryFilter(BaseFilterMixin): pass -@strawberry_django.filter(InventoryItemType, lookups=True) -@autotype_decorator(InventoryItemTypeFilterSet) +@strawberry_django.filter(models.InventoryItemType, lookups=True) +@autotype_decorator(filtersets.InventoryItemTypeFilterSet) class InventoryItemTypeFilter(BaseFilterMixin): pass -@strawberry_django.filter(InventoryItemGroup, lookups=True) -@autotype_decorator(InventoryItemGroupFilterSet) +@strawberry_django.filter(models.InventoryItemGroup, lookups=True) +@autotype_decorator(filtersets.InventoryItemGroupFilterSet) class InventoryItemGroupFilter(BaseFilterMixin): pass From 46c2b0ea51550511edb9dfd631f8c9ffe41ab6a7 Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Wed, 28 Aug 2024 12:14:35 -0700 Subject: [PATCH 14/41] feat: update netbox-inventory --- netbox_inventory/graphql/types.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index 7e4338f..e978488 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -3,7 +3,6 @@ from typing import Annotated, Optional from netbox_inventory.models import Asset, Supplier, Purchase, Delivery, InventoryItemType, InventoryItemGroup -from netbox_inventory.choices import AssetStatusChoices from .filters import ( AssetFilter, SupplierFilter, @@ -17,7 +16,7 @@ @strawberry_django.type(Asset, fields="__all__", filters=AssetFilter) class AssetType: - device_type: Annotated["DeviceTypeType", strawberry.lazy('netbox.dcim.graphql.types')] | None + device_type: Annotated["DeviceTypeType", strawberry.lazy('netbox.graphql.types')] | None # name: str # asset_tag: Optional[str] # serial: Optional[str] From f9d8c01290ae67eaf728e8e2ab3f368fb64956c4 Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Wed, 28 Aug 2024 12:29:52 -0700 Subject: [PATCH 15/41] feat: update netbox-inventory --- netbox_inventory/graphql/types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index e978488..b0a7bf3 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -16,7 +16,7 @@ @strawberry_django.type(Asset, fields="__all__", filters=AssetFilter) class AssetType: - device_type: Annotated["DeviceTypeType", strawberry.lazy('netbox.graphql.types')] | None + device_type: Annotated["DeviceTypeType", strawberry.lazy('dcim.graphql.types')] | None # name: str # asset_tag: Optional[str] # serial: Optional[str] From 709d9dfce2e80c561ea53def2e93a938e5b79c8e Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Wed, 28 Aug 2024 12:52:25 -0700 Subject: [PATCH 16/41] feat: update netbox-inventory --- netbox_inventory/graphql/types.py | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index b0a7bf3..7616dd0 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -1,6 +1,8 @@ import strawberry import strawberry_django from typing import Annotated, Optional +from netbox.extras.graphql.mixins import ContactsMixin, CustomFieldsMixin, TagsMixin +from netbox.netbox.graphql.types import BaseObjectType, NetBoxObjectType from netbox_inventory.models import Asset, Supplier, Purchase, Delivery, InventoryItemType, InventoryItemGroup from .filters import ( @@ -15,26 +17,11 @@ @strawberry_django.type(Asset, fields="__all__", filters=AssetFilter) -class AssetType: +class AssetType(ContactsMixin, NetBoxObjectType): device_type: Annotated["DeviceTypeType", strawberry.lazy('dcim.graphql.types')] | None - # name: str - # asset_tag: Optional[str] - # serial: Optional[str] - # status: AssetStatusChoices - - # @strawberry_django.field - # def device_type(self) -> Annotated["DeviceTypeType", strawberry.lazy('dcim.graphql.types')] | None - # return self.device_type - # - # @strawberry_django.field - # def module_type(self) -> Optional[Annotated["ModuleTypeType", strawberry.lazy("netbox.dcim.graphql.types")]]: - # return self.module_type - - # @strawberry_django.field - # def inventoryitem_type(self) -> Optional[ - # Annotated["InventoryItemTypeType", strawberry.lazy("netbox_inventory.graphql.types")]]: - # return self.inventoryitem_type - + module_type: Optional[Annotated["ModuleTypeType", strawberry.lazy("dcim.graphql.types")]] | None + inventoryitem_type: Optional[Annotated["InventoryItemTypeType", strawberry.lazy("dcim.graphql.types")]] | None + tenant: Annotated["TenantType", strawberry.lazy('tenancy.graphql.types')] | None # @strawberry_django.field # def device(self) -> Optional[Annotated["DeviceType", strawberry.lazy("netbox.dcim.graphql.types")]]: # return self.device From 7e6eedf592ddfbc3e22e0b221e3ff101d08f8a8b Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Wed, 28 Aug 2024 12:57:11 -0700 Subject: [PATCH 17/41] feat: update netbox-inventory --- netbox_inventory/graphql/types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index 7616dd0..48a16c1 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -17,7 +17,7 @@ @strawberry_django.type(Asset, fields="__all__", filters=AssetFilter) -class AssetType(ContactsMixin, NetBoxObjectType): +class AssetType(ContactsMixin, BaseObjectType): device_type: Annotated["DeviceTypeType", strawberry.lazy('dcim.graphql.types')] | None module_type: Optional[Annotated["ModuleTypeType", strawberry.lazy("dcim.graphql.types")]] | None inventoryitem_type: Optional[Annotated["InventoryItemTypeType", strawberry.lazy("dcim.graphql.types")]] | None From 7c4b70e6d25ad26665f3d775291880a0744dbdbe Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Wed, 28 Aug 2024 13:01:36 -0700 Subject: [PATCH 18/41] feat: update netbox-inventory --- netbox_inventory/graphql/types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index 48a16c1..f70e04c 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -17,7 +17,7 @@ @strawberry_django.type(Asset, fields="__all__", filters=AssetFilter) -class AssetType(ContactsMixin, BaseObjectType): +class AssetType: device_type: Annotated["DeviceTypeType", strawberry.lazy('dcim.graphql.types')] | None module_type: Optional[Annotated["ModuleTypeType", strawberry.lazy("dcim.graphql.types")]] | None inventoryitem_type: Optional[Annotated["InventoryItemTypeType", strawberry.lazy("dcim.graphql.types")]] | None From 1b3cd956423c89067cd43aded7b4c010871f950d Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Wed, 28 Aug 2024 13:06:12 -0700 Subject: [PATCH 19/41] feat: update netbox-inventory --- netbox_inventory/graphql/types.py | 128 +++++++++++++++--------------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index f70e04c..d42d2fc 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -1,8 +1,8 @@ import strawberry import strawberry_django from typing import Annotated, Optional -from netbox.extras.graphql.mixins import ContactsMixin, CustomFieldsMixin, TagsMixin -from netbox.netbox.graphql.types import BaseObjectType, NetBoxObjectType +# from netbox.extras.graphql.mixins import ContactsMixin, CustomFieldsMixin, TagsMixin +# from netbox.netbox.graphql.types import BaseObjectType, NetBoxObjectType from netbox_inventory.models import Asset, Supplier, Purchase, Delivery, InventoryItemType, InventoryItemGroup from .filters import ( @@ -19,9 +19,9 @@ @strawberry_django.type(Asset, fields="__all__", filters=AssetFilter) class AssetType: device_type: Annotated["DeviceTypeType", strawberry.lazy('dcim.graphql.types')] | None - module_type: Optional[Annotated["ModuleTypeType", strawberry.lazy("dcim.graphql.types")]] | None - inventoryitem_type: Optional[Annotated["InventoryItemTypeType", strawberry.lazy("dcim.graphql.types")]] | None - tenant: Annotated["TenantType", strawberry.lazy('tenancy.graphql.types')] | None + # module_type: Optional[Annotated["ModuleTypeType", strawberry.lazy("dcim.graphql.types")]] | None + # inventoryitem_type: Optional[Annotated["InventoryItemTypeType", strawberry.lazy("dcim.graphql.types")]] | None + # tenant: Annotated["TenantType", strawberry.lazy('tenancy.graphql.types')] | None # @strawberry_django.field # def device(self) -> Optional[Annotated["DeviceType", strawberry.lazy("netbox.dcim.graphql.types")]]: # return self.device @@ -58,62 +58,62 @@ class AssetType: # def purchase(self) -> Optional[Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")]]: # return self.purchase -@strawberry_django.type(Supplier, fields="__all__", filters=SupplierFilter) -class SupplierType: - @strawberry_django.field - def purchases(self) -> list[Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")]]: - return self.purchases.all() - -@strawberry_django.type(Purchase, fields="__all__", filters=PurchaseFilter) -class PurchaseType: - @strawberry_django.field - def supplier(self) -> Annotated["SupplierType", strawberry.lazy("netbox_inventory.graphql.types")]: - return self.supplier - - @strawberry_django.field - def orders(self) -> list[Annotated["DeliveryType", strawberry.lazy("netbox_inventory.graphql.types")]]: - return self.orders.all() - - @strawberry_django.field - def assets(self) -> list[Annotated["AssetType", strawberry.lazy("netbox_inventory.graphql.types")]]: - return self.assets.all() - -@strawberry_django.type(Delivery, fields="__all__", filters=DeliveryFilter) -class DeliveryType: - @strawberry_django.field - def purchase(self) -> Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")]: - return self.purchase - - @strawberry_django.field - def receiving_contact(self) -> Optional[Annotated["Contact", strawberry.lazy("netbox.graphql.types")]]: - return self.receiving_contact - - @strawberry_django.field - def assets(self) -> list[Annotated["AssetType", strawberry.lazy("netbox_inventory.graphql.types")]]: - return self.assets.all() - -@strawberry_django.type(InventoryItemType, fields="__all__", filters=InventoryItemTypeFilter) -class InventoryItemTypeType: - @strawberry_django.field - def manufacturer(self) -> Annotated["Manufacturer", strawberry.lazy("netbox.graphql.types")]: - return self.manufacturer - - @strawberry_django.field - def inventoryitem_group(self) -> Optional[ - Annotated["InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types")]]: - return self.inventoryitem_group - -@strawberry_django.type(InventoryItemGroup, fields="__all__", filters=InventoryItemGroupFilter) -class InventoryItemGroupType: - @strawberry_django.field - def parent(self) -> Optional[Annotated["InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types")]]: - return self.parent - - @strawberry_django.field - def children(self) -> list[Annotated["InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types")]]: - return self.children.all() - - @strawberry_django.field - def inventoryitem_types(self) -> list[ - Annotated["InventoryItemTypeType", strawberry.lazy("netbox_inventory.graphql.types")]]: - return self.inventoryitem_types.all() \ No newline at end of file +# @strawberry_django.type(Supplier, fields="__all__", filters=SupplierFilter) +# class SupplierType: +# @strawberry_django.field +# def purchases(self) -> list[Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")]]: +# return self.purchases.all() +# +# @strawberry_django.type(Purchase, fields="__all__", filters=PurchaseFilter) +# class PurchaseType: +# @strawberry_django.field +# def supplier(self) -> Annotated["SupplierType", strawberry.lazy("netbox_inventory.graphql.types")]: +# return self.supplier +# +# @strawberry_django.field +# def orders(self) -> list[Annotated["DeliveryType", strawberry.lazy("netbox_inventory.graphql.types")]]: +# return self.orders.all() +# +# @strawberry_django.field +# def assets(self) -> list[Annotated["AssetType", strawberry.lazy("netbox_inventory.graphql.types")]]: +# return self.assets.all() +# +# @strawberry_django.type(Delivery, fields="__all__", filters=DeliveryFilter) +# class DeliveryType: +# @strawberry_django.field +# def purchase(self) -> Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")]: +# return self.purchase +# +# @strawberry_django.field +# def receiving_contact(self) -> Optional[Annotated["Contact", strawberry.lazy("netbox.graphql.types")]]: +# return self.receiving_contact +# +# @strawberry_django.field +# def assets(self) -> list[Annotated["AssetType", strawberry.lazy("netbox_inventory.graphql.types")]]: +# return self.assets.all() +# +# @strawberry_django.type(InventoryItemType, fields="__all__", filters=InventoryItemTypeFilter) +# class InventoryItemTypeType: +# @strawberry_django.field +# def manufacturer(self) -> Annotated["Manufacturer", strawberry.lazy("netbox.graphql.types")]: +# return self.manufacturer +# +# @strawberry_django.field +# def inventoryitem_group(self) -> Optional[ +# Annotated["InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types")]]: +# return self.inventoryitem_group +# +# @strawberry_django.type(InventoryItemGroup, fields="__all__", filters=InventoryItemGroupFilter) +# class InventoryItemGroupType: +# @strawberry_django.field +# def parent(self) -> Optional[Annotated["InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types")]]: +# return self.parent +# +# @strawberry_django.field +# def children(self) -> list[Annotated["InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types")]]: +# return self.children.all() +# +# @strawberry_django.field +# def inventoryitem_types(self) -> list[ +# Annotated["InventoryItemTypeType", strawberry.lazy("netbox_inventory.graphql.types")]]: +# return self.inventoryitem_types.all() \ No newline at end of file From 23b9f44852e1a7a22c9081aafe0b75c9ce4806a0 Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Wed, 28 Aug 2024 13:08:07 -0700 Subject: [PATCH 20/41] feat: update netbox-inventory --- netbox_inventory/graphql/__init__.py | 8 +- netbox_inventory/graphql/types.py | 124 +++++++++++++-------------- 2 files changed, 66 insertions(+), 66 deletions(-) diff --git a/netbox_inventory/graphql/__init__.py b/netbox_inventory/graphql/__init__.py index ba10e81..d2b1632 100644 --- a/netbox_inventory/graphql/__init__.py +++ b/netbox_inventory/graphql/__init__.py @@ -9,9 +9,9 @@ schema = [ AssetQuery, - SupplierQuery, - PurchaseQuery, - DeliveryQuery, - InventoryItemTypeQuery, + # SupplierQuery, + # PurchaseQuery, + # DeliveryQuery, + # InventoryItemTypeQuery, # InventoryItemGroupQuery # Commented out to due to circular dependency ] \ No newline at end of file diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index d42d2fc..205917e 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -1,8 +1,8 @@ import strawberry import strawberry_django from typing import Annotated, Optional -# from netbox.extras.graphql.mixins import ContactsMixin, CustomFieldsMixin, TagsMixin -# from netbox.netbox.graphql.types import BaseObjectType, NetBoxObjectType +from netbox.extras.graphql.mixins import ContactsMixin, CustomFieldsMixin, TagsMixin +from netbox.netbox.graphql.types import BaseObjectType, NetBoxObjectType from netbox_inventory.models import Asset, Supplier, Purchase, Delivery, InventoryItemType, InventoryItemGroup from .filters import ( @@ -19,7 +19,7 @@ @strawberry_django.type(Asset, fields="__all__", filters=AssetFilter) class AssetType: device_type: Annotated["DeviceTypeType", strawberry.lazy('dcim.graphql.types')] | None - # module_type: Optional[Annotated["ModuleTypeType", strawberry.lazy("dcim.graphql.types")]] | None + module_type: Optional[Annotated["ModuleTypeType", strawberry.lazy("dcim.graphql.types")]] | None # inventoryitem_type: Optional[Annotated["InventoryItemTypeType", strawberry.lazy("dcim.graphql.types")]] | None # tenant: Annotated["TenantType", strawberry.lazy('tenancy.graphql.types')] | None # @strawberry_django.field @@ -58,62 +58,62 @@ class AssetType: # def purchase(self) -> Optional[Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")]]: # return self.purchase -# @strawberry_django.type(Supplier, fields="__all__", filters=SupplierFilter) -# class SupplierType: -# @strawberry_django.field -# def purchases(self) -> list[Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")]]: -# return self.purchases.all() -# -# @strawberry_django.type(Purchase, fields="__all__", filters=PurchaseFilter) -# class PurchaseType: -# @strawberry_django.field -# def supplier(self) -> Annotated["SupplierType", strawberry.lazy("netbox_inventory.graphql.types")]: -# return self.supplier -# -# @strawberry_django.field -# def orders(self) -> list[Annotated["DeliveryType", strawberry.lazy("netbox_inventory.graphql.types")]]: -# return self.orders.all() -# -# @strawberry_django.field -# def assets(self) -> list[Annotated["AssetType", strawberry.lazy("netbox_inventory.graphql.types")]]: -# return self.assets.all() -# -# @strawberry_django.type(Delivery, fields="__all__", filters=DeliveryFilter) -# class DeliveryType: -# @strawberry_django.field -# def purchase(self) -> Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")]: -# return self.purchase -# -# @strawberry_django.field -# def receiving_contact(self) -> Optional[Annotated["Contact", strawberry.lazy("netbox.graphql.types")]]: -# return self.receiving_contact -# -# @strawberry_django.field -# def assets(self) -> list[Annotated["AssetType", strawberry.lazy("netbox_inventory.graphql.types")]]: -# return self.assets.all() -# -# @strawberry_django.type(InventoryItemType, fields="__all__", filters=InventoryItemTypeFilter) -# class InventoryItemTypeType: -# @strawberry_django.field -# def manufacturer(self) -> Annotated["Manufacturer", strawberry.lazy("netbox.graphql.types")]: -# return self.manufacturer -# -# @strawberry_django.field -# def inventoryitem_group(self) -> Optional[ -# Annotated["InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types")]]: -# return self.inventoryitem_group -# -# @strawberry_django.type(InventoryItemGroup, fields="__all__", filters=InventoryItemGroupFilter) -# class InventoryItemGroupType: -# @strawberry_django.field -# def parent(self) -> Optional[Annotated["InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types")]]: -# return self.parent -# -# @strawberry_django.field -# def children(self) -> list[Annotated["InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types")]]: -# return self.children.all() -# -# @strawberry_django.field -# def inventoryitem_types(self) -> list[ -# Annotated["InventoryItemTypeType", strawberry.lazy("netbox_inventory.graphql.types")]]: -# return self.inventoryitem_types.all() \ No newline at end of file +@strawberry_django.type(Supplier, fields="__all__", filters=SupplierFilter) +class SupplierType: + @strawberry_django.field + def purchases(self) -> list[Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")]]: + return self.purchases.all() + +@strawberry_django.type(Purchase, fields="__all__", filters=PurchaseFilter) +class PurchaseType: + @strawberry_django.field + def supplier(self) -> Annotated["SupplierType", strawberry.lazy("netbox_inventory.graphql.types")]: + return self.supplier + + @strawberry_django.field + def orders(self) -> list[Annotated["DeliveryType", strawberry.lazy("netbox_inventory.graphql.types")]]: + return self.orders.all() + + @strawberry_django.field + def assets(self) -> list[Annotated["AssetType", strawberry.lazy("netbox_inventory.graphql.types")]]: + return self.assets.all() + +@strawberry_django.type(Delivery, fields="__all__", filters=DeliveryFilter) +class DeliveryType: + @strawberry_django.field + def purchase(self) -> Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")]: + return self.purchase + + @strawberry_django.field + def receiving_contact(self) -> Optional[Annotated["Contact", strawberry.lazy("netbox.graphql.types")]]: + return self.receiving_contact + + @strawberry_django.field + def assets(self) -> list[Annotated["AssetType", strawberry.lazy("netbox_inventory.graphql.types")]]: + return self.assets.all() + +@strawberry_django.type(InventoryItemType, fields="__all__", filters=InventoryItemTypeFilter) +class InventoryItemTypeType: + @strawberry_django.field + def manufacturer(self) -> Annotated["Manufacturer", strawberry.lazy("netbox.graphql.types")]: + return self.manufacturer + + @strawberry_django.field + def inventoryitem_group(self) -> Optional[ + Annotated["InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types")]]: + return self.inventoryitem_group + +@strawberry_django.type(InventoryItemGroup, fields="__all__", filters=InventoryItemGroupFilter) +class InventoryItemGroupType: + @strawberry_django.field + def parent(self) -> Optional[Annotated["InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types")]]: + return self.parent + + @strawberry_django.field + def children(self) -> list[Annotated["InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types")]]: + return self.children.all() + + @strawberry_django.field + def inventoryitem_types(self) -> list[ + Annotated["InventoryItemTypeType", strawberry.lazy("netbox_inventory.graphql.types")]]: + return self.inventoryitem_types.all() \ No newline at end of file From 4c860b7dd3bb2ab836b98e42ea5c174f12451c51 Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Wed, 28 Aug 2024 13:19:18 -0700 Subject: [PATCH 21/41] feat: update netbox-inventory --- netbox_inventory/graphql/types.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index 205917e..5382f6c 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -1,8 +1,6 @@ import strawberry import strawberry_django from typing import Annotated, Optional -from netbox.extras.graphql.mixins import ContactsMixin, CustomFieldsMixin, TagsMixin -from netbox.netbox.graphql.types import BaseObjectType, NetBoxObjectType from netbox_inventory.models import Asset, Supplier, Purchase, Delivery, InventoryItemType, InventoryItemGroup from .filters import ( From 29124f351e79862a0233b80a274de999523c2cac Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Wed, 28 Aug 2024 13:24:57 -0700 Subject: [PATCH 22/41] feat: update netbox-inventory --- netbox_inventory/graphql/types.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index 5382f6c..c33f29a 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -1,6 +1,8 @@ import strawberry import strawberry_django from typing import Annotated, Optional +from netbox.extras.graphql.mixins import ContactsMixin, CustomFieldsMixin, TagsMixin +from netbox.graphql.types import NetBoxObjectType from netbox_inventory.models import Asset, Supplier, Purchase, Delivery, InventoryItemType, InventoryItemGroup from .filters import ( @@ -15,11 +17,11 @@ @strawberry_django.type(Asset, fields="__all__", filters=AssetFilter) -class AssetType: +class AssetType(ContactsMixin, NetBoxObjectType): device_type: Annotated["DeviceTypeType", strawberry.lazy('dcim.graphql.types')] | None module_type: Optional[Annotated["ModuleTypeType", strawberry.lazy("dcim.graphql.types")]] | None - # inventoryitem_type: Optional[Annotated["InventoryItemTypeType", strawberry.lazy("dcim.graphql.types")]] | None - # tenant: Annotated["TenantType", strawberry.lazy('tenancy.graphql.types')] | None + inventoryitem_type: Optional[Annotated["InventoryItemTypeType", strawberry.lazy("dcim.graphql.types")]] | None + tenant: Annotated["TenantType", strawberry.lazy('tenancy.graphql.types')] | None # @strawberry_django.field # def device(self) -> Optional[Annotated["DeviceType", strawberry.lazy("netbox.dcim.graphql.types")]]: # return self.device From de1ec10bac8d3e552157b10b001498f4aba1b34b Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Wed, 28 Aug 2024 13:29:25 -0700 Subject: [PATCH 23/41] feat: update netbox-inventory --- netbox_inventory/graphql/types.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index c33f29a..b3fbab4 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -1,8 +1,8 @@ import strawberry import strawberry_django from typing import Annotated, Optional -from netbox.extras.graphql.mixins import ContactsMixin, CustomFieldsMixin, TagsMixin -from netbox.graphql.types import NetBoxObjectType +# from netbox.extras.graphql.mixins import ContactsMixin, CustomFieldsMixin, TagsMixin +# from netbox.graphql.types import NetBoxObjectType from netbox_inventory.models import Asset, Supplier, Purchase, Delivery, InventoryItemType, InventoryItemGroup from .filters import ( @@ -17,7 +17,7 @@ @strawberry_django.type(Asset, fields="__all__", filters=AssetFilter) -class AssetType(ContactsMixin, NetBoxObjectType): +class AssetType: device_type: Annotated["DeviceTypeType", strawberry.lazy('dcim.graphql.types')] | None module_type: Optional[Annotated["ModuleTypeType", strawberry.lazy("dcim.graphql.types")]] | None inventoryitem_type: Optional[Annotated["InventoryItemTypeType", strawberry.lazy("dcim.graphql.types")]] | None From 22a492f1719e849a3dcf7b350f143ee0041f1bf9 Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Wed, 28 Aug 2024 13:40:50 -0700 Subject: [PATCH 24/41] feat: update netbox-inventory --- netbox_inventory/graphql/types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index b3fbab4..a959d2f 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -20,7 +20,7 @@ class AssetType: device_type: Annotated["DeviceTypeType", strawberry.lazy('dcim.graphql.types')] | None module_type: Optional[Annotated["ModuleTypeType", strawberry.lazy("dcim.graphql.types")]] | None - inventoryitem_type: Optional[Annotated["InventoryItemTypeType", strawberry.lazy("dcim.graphql.types")]] | None + # inventoryitem_type: Optional[Annotated["InventoryItemTypeType", strawberry.lazy("netbox.dcim.graphql.types")]] | None tenant: Annotated["TenantType", strawberry.lazy('tenancy.graphql.types')] | None # @strawberry_django.field # def device(self) -> Optional[Annotated["DeviceType", strawberry.lazy("netbox.dcim.graphql.types")]]: From 698c325439d6e8345e2af418c7eb1a197bd669e6 Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Wed, 28 Aug 2024 13:41:49 -0700 Subject: [PATCH 25/41] feat: update netbox-inventory --- netbox_inventory/graphql/types.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index a959d2f..775cb7c 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -1,8 +1,8 @@ import strawberry import strawberry_django from typing import Annotated, Optional -# from netbox.extras.graphql.mixins import ContactsMixin, CustomFieldsMixin, TagsMixin -# from netbox.graphql.types import NetBoxObjectType +from netbox.extras.graphql.mixins import ContactsMixin, CustomFieldsMixin, TagsMixin +from netbox.graphql.types import NetBoxObjectType from netbox_inventory.models import Asset, Supplier, Purchase, Delivery, InventoryItemType, InventoryItemGroup from .filters import ( @@ -17,7 +17,7 @@ @strawberry_django.type(Asset, fields="__all__", filters=AssetFilter) -class AssetType: +class AssetType(ContactsMixin, NetBoxObjectType): device_type: Annotated["DeviceTypeType", strawberry.lazy('dcim.graphql.types')] | None module_type: Optional[Annotated["ModuleTypeType", strawberry.lazy("dcim.graphql.types")]] | None # inventoryitem_type: Optional[Annotated["InventoryItemTypeType", strawberry.lazy("netbox.dcim.graphql.types")]] | None From 778e6f11b908dab9b821d0951c6d98cd48df021d Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Wed, 28 Aug 2024 13:46:34 -0700 Subject: [PATCH 26/41] feat: update netbox-inventory --- netbox_inventory/graphql/types.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index 775cb7c..a959d2f 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -1,8 +1,8 @@ import strawberry import strawberry_django from typing import Annotated, Optional -from netbox.extras.graphql.mixins import ContactsMixin, CustomFieldsMixin, TagsMixin -from netbox.graphql.types import NetBoxObjectType +# from netbox.extras.graphql.mixins import ContactsMixin, CustomFieldsMixin, TagsMixin +# from netbox.graphql.types import NetBoxObjectType from netbox_inventory.models import Asset, Supplier, Purchase, Delivery, InventoryItemType, InventoryItemGroup from .filters import ( @@ -17,7 +17,7 @@ @strawberry_django.type(Asset, fields="__all__", filters=AssetFilter) -class AssetType(ContactsMixin, NetBoxObjectType): +class AssetType: device_type: Annotated["DeviceTypeType", strawberry.lazy('dcim.graphql.types')] | None module_type: Optional[Annotated["ModuleTypeType", strawberry.lazy("dcim.graphql.types")]] | None # inventoryitem_type: Optional[Annotated["InventoryItemTypeType", strawberry.lazy("netbox.dcim.graphql.types")]] | None From 230caa22d3ecbb271717116f33aaf58705b32f25 Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Thu, 29 Aug 2024 09:33:01 -0700 Subject: [PATCH 27/41] feat: update netbox-inventory --- netbox_inventory/graphql/types.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index a959d2f..a8a8c85 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -1,8 +1,6 @@ import strawberry import strawberry_django from typing import Annotated, Optional -# from netbox.extras.graphql.mixins import ContactsMixin, CustomFieldsMixin, TagsMixin -# from netbox.graphql.types import NetBoxObjectType from netbox_inventory.models import Asset, Supplier, Purchase, Delivery, InventoryItemType, InventoryItemGroup from .filters import ( @@ -14,6 +12,11 @@ InventoryItemGroupFilter ) +# TODO: Add tags (tried with mixin) +# TODO: Change status to status choices +# TODO: InventoryItemType, i don't see an InventoryItemTypeType in the models +# TODO: DeliveryType +# TODO: PurchaseType @strawberry_django.type(Asset, fields="__all__", filters=AssetFilter) @@ -22,6 +25,12 @@ class AssetType: module_type: Optional[Annotated["ModuleTypeType", strawberry.lazy("dcim.graphql.types")]] | None # inventoryitem_type: Optional[Annotated["InventoryItemTypeType", strawberry.lazy("netbox.dcim.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 # @strawberry_django.field # def device(self) -> Optional[Annotated["DeviceType", strawberry.lazy("netbox.dcim.graphql.types")]]: # return self.device @@ -30,17 +39,8 @@ class AssetType: # def module(self) -> Optional[Annotated["ModuleType", strawberry.lazy("netbox.dcim.graphql.types")]]: # return self.module # - # @strawberry_django.field - # def inventoryitem(self) -> Optional[Annotated["InventoryItemType", strawberry.lazy("netbox.dcim.graphql.types")]]: - # return self.inventoryitem - # - # @strawberry_django.field - # def tenant(self) -> Optional[Annotated["Tenant", strawberry.lazy("netbox.dcim.graphql.types")]]: - # return self.tenant # - # @strawberry_django.field - # def contact(self) -> Optional[Annotated["Contact", strawberry.lazy("netbox.graphql.types")]]: - # return self.contact + # # @strawberry_django.field # def storage_location(self) -> Optional[Annotated["Location", strawberry.lazy("netbox.graphql.types")]]: From 350d1c122932f65a293c7fc4e70d77ce71dd7a56 Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Thu, 29 Aug 2024 09:51:44 -0700 Subject: [PATCH 28/41] feat: update netbox-inventory --- netbox_inventory/graphql/__init__.py | 10 ++-- netbox_inventory/graphql/types.py | 84 ++++------------------------ 2 files changed, 16 insertions(+), 78 deletions(-) diff --git a/netbox_inventory/graphql/__init__.py b/netbox_inventory/graphql/__init__.py index d2b1632..bf72cbc 100644 --- a/netbox_inventory/graphql/__init__.py +++ b/netbox_inventory/graphql/__init__.py @@ -9,9 +9,9 @@ schema = [ AssetQuery, - # SupplierQuery, - # PurchaseQuery, - # DeliveryQuery, - # InventoryItemTypeQuery, - # InventoryItemGroupQuery # Commented out to due to circular dependency + SupplierQuery, + PurchaseQuery, + DeliveryQuery, + InventoryItemTypeQuery, + InventoryItemGroupQuery ] \ No newline at end of file diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index a8a8c85..6eb4b05 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -22,8 +22,8 @@ @strawberry_django.type(Asset, fields="__all__", filters=AssetFilter) class AssetType: device_type: Annotated["DeviceTypeType", strawberry.lazy('dcim.graphql.types')] | None - module_type: Optional[Annotated["ModuleTypeType", strawberry.lazy("dcim.graphql.types")]] | None - # inventoryitem_type: Optional[Annotated["InventoryItemTypeType", strawberry.lazy("netbox.dcim.graphql.types")]] | None + module_type: Annotated["ModuleTypeType", strawberry.lazy("dcim.graphql.types")] | None + inventoryitem_type: Annotated["InventoryItemTypeType", strawberry.lazy("netbox.dcim.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 @@ -31,89 +31,27 @@ class AssetType: 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 - # @strawberry_django.field - # def device(self) -> Optional[Annotated["DeviceType", strawberry.lazy("netbox.dcim.graphql.types")]]: - # return self.device - # - # @strawberry_django.field - # def module(self) -> Optional[Annotated["ModuleType", strawberry.lazy("netbox.dcim.graphql.types")]]: - # return self.module - # - # - - # - # @strawberry_django.field - # def storage_location(self) -> Optional[Annotated["Location", strawberry.lazy("netbox.graphql.types")]]: - # return self.storage_location - # - # @strawberry_django.field - # def owner(self) -> Optional[Annotated["Tenant", strawberry.lazy("netbox.graphql.types")]]: - # return self.owner - # - # @strawberry_django.field - # def delivery(self) -> Optional[Annotated["DeliveryType", strawberry.lazy("netbox_inventory.graphql.types")]]: - # return self.delivery - # - # @strawberry_django.field - # def purchase(self) -> Optional[Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")]]: - # return self.purchase + 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: - @strawberry_django.field - def purchases(self) -> list[Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")]]: - return self.purchases.all() + pass @strawberry_django.type(Purchase, fields="__all__", filters=PurchaseFilter) class PurchaseType: - @strawberry_django.field - def supplier(self) -> Annotated["SupplierType", strawberry.lazy("netbox_inventory.graphql.types")]: - return self.supplier - - @strawberry_django.field - def orders(self) -> list[Annotated["DeliveryType", strawberry.lazy("netbox_inventory.graphql.types")]]: - return self.orders.all() - - @strawberry_django.field - def assets(self) -> list[Annotated["AssetType", strawberry.lazy("netbox_inventory.graphql.types")]]: - return self.assets.all() + supplier: Annotated["SupplierType", strawberry.lazy("netbox_inventory.graphql.types")] @strawberry_django.type(Delivery, fields="__all__", filters=DeliveryFilter) class DeliveryType: - @strawberry_django.field - def purchase(self) -> Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")]: - return self.purchase - - @strawberry_django.field - def receiving_contact(self) -> Optional[Annotated["Contact", strawberry.lazy("netbox.graphql.types")]]: - return self.receiving_contact - - @strawberry_django.field - def assets(self) -> list[Annotated["AssetType", strawberry.lazy("netbox_inventory.graphql.types")]]: - return self.assets.all() + purchase: Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")] + receiving_contact: Annotated["ContactType", strawberry.lazy("tenancy.graphql.types")] | None @strawberry_django.type(InventoryItemType, fields="__all__", filters=InventoryItemTypeFilter) class InventoryItemTypeType: - @strawberry_django.field - def manufacturer(self) -> Annotated["Manufacturer", strawberry.lazy("netbox.graphql.types")]: - return self.manufacturer - - @strawberry_django.field - def inventoryitem_group(self) -> Optional[ - Annotated["InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types")]]: - return self.inventoryitem_group + 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: - @strawberry_django.field - def parent(self) -> Optional[Annotated["InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types")]]: - return self.parent - - @strawberry_django.field - def children(self) -> list[Annotated["InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types")]]: - return self.children.all() - - @strawberry_django.field - def inventoryitem_types(self) -> list[ - Annotated["InventoryItemTypeType", strawberry.lazy("netbox_inventory.graphql.types")]]: - return self.inventoryitem_types.all() \ No newline at end of file + pass \ No newline at end of file From 1e867036b78a0542bf33d5e87303940816ce5f42 Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Thu, 29 Aug 2024 09:54:56 -0700 Subject: [PATCH 29/41] feat: update netbox-inventory --- netbox_inventory/graphql/types.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index 6eb4b05..11c888b 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -14,16 +14,12 @@ # TODO: Add tags (tried with mixin) # TODO: Change status to status choices -# TODO: InventoryItemType, i don't see an InventoryItemTypeType in the models -# TODO: DeliveryType -# TODO: PurchaseType - @strawberry_django.type(Asset, fields="__all__", filters=AssetFilter) class AssetType: 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.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 From 2d097d202e6f2bb198f2bba38445e2ad9db3a882 Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Thu, 29 Aug 2024 09:59:43 -0700 Subject: [PATCH 30/41] feat: update netbox-inventory --- netbox_inventory/graphql/types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index 11c888b..e85c36e 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -50,4 +50,4 @@ class InventoryItemTypeType: @strawberry_django.type(InventoryItemGroup, fields="__all__", filters=InventoryItemGroupFilter) class InventoryItemGroupType: - pass \ No newline at end of file + parent: Annotated["InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types")] | None \ No newline at end of file From 15e7b02821a7e8631785b29f677659ef53c62dee Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Thu, 29 Aug 2024 10:16:14 -0700 Subject: [PATCH 31/41] feat: update netbox-inventory --- netbox_inventory/graphql/types.py | 1 + 1 file changed, 1 insertion(+) diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index e85c36e..d390f3f 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -42,6 +42,7 @@ class PurchaseType: class DeliveryType: 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: From 11114ffc66de6b0c807f77d327a8a69b9d3b95b3 Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Thu, 29 Aug 2024 10:25:01 -0700 Subject: [PATCH 32/41] feat: update netbox-inventory --- netbox_inventory/graphql/types.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index d390f3f..3e1ca11 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -32,11 +32,13 @@ class AssetType: @strawberry_django.type(Supplier, fields="__all__", filters=SupplierFilter) class SupplierType: - pass + purchases: list[Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")]] @strawberry_django.type(Purchase, fields="__all__", filters=PurchaseFilter) class PurchaseType: 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: @@ -51,4 +53,6 @@ class InventoryItemTypeType: @strawberry_django.type(InventoryItemGroup, fields="__all__", filters=InventoryItemGroupFilter) class InventoryItemGroupType: - parent: Annotated["InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types")] | None \ No newline at end of file + 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")]] \ No newline at end of file From e7d3d2bbd2214417259194dbd63af3cda407ea4c Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Thu, 29 Aug 2024 10:32:20 -0700 Subject: [PATCH 33/41] feat: update netbox-inventory --- netbox_inventory/graphql/types.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index 3e1ca11..2a4626d 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -12,9 +12,6 @@ InventoryItemGroupFilter ) -# TODO: Add tags (tried with mixin) -# TODO: Change status to status choices - @strawberry_django.type(Asset, fields="__all__", filters=AssetFilter) class AssetType: device_type: Annotated["DeviceTypeType", strawberry.lazy('dcim.graphql.types')] | None From b2235ef88576a293f0958c3f0a4e967fb282bc18 Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Thu, 29 Aug 2024 11:23:47 -0700 Subject: [PATCH 34/41] feat: update netbox-inventory --- netbox_inventory/graphql/types.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index 2a4626d..4fb41ed 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -1,7 +1,8 @@ import strawberry import strawberry_django -from typing import Annotated, Optional - +from typing import Annotated +from netbox.graphql.types import NetBoxObjectType +from extras.graphql.mixins import ContactsMixin from netbox_inventory.models import Asset, Supplier, Purchase, Delivery, InventoryItemType, InventoryItemGroup from .filters import ( AssetFilter, @@ -13,7 +14,7 @@ ) @strawberry_django.type(Asset, fields="__all__", filters=AssetFilter) -class AssetType: +class AssetType(ContactsMixin, 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 @@ -28,28 +29,28 @@ class AssetType: purchase: Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")] | None @strawberry_django.type(Supplier, fields="__all__", filters=SupplierFilter) -class SupplierType: +class SupplierType(NetBoxObjectType): purchases: list[Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")]] @strawberry_django.type(Purchase, fields="__all__", filters=PurchaseFilter) -class PurchaseType: +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: +class DeliveryType(ContactsMixin, 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: +class InventoryItemTypeType(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: +class InventoryItemGroupType(NetBoxObjectType): 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")]] \ No newline at end of file From 487cd27d40c45c31a9aa3d8dafddbf910036c31d Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Thu, 29 Aug 2024 11:31:37 -0700 Subject: [PATCH 35/41] feat: update netbox-inventory --- netbox_inventory/graphql/__init__.py | 6 +- netbox_inventory/graphql/filters.py | 20 +++-- netbox_inventory/graphql/schema.py | 20 ++++- netbox_inventory/graphql/types.py | 122 +++++++++++++++++++++------ 4 files changed, 127 insertions(+), 41 deletions(-) diff --git a/netbox_inventory/graphql/__init__.py b/netbox_inventory/graphql/__init__.py index bf72cbc..ddadae9 100644 --- a/netbox_inventory/graphql/__init__.py +++ b/netbox_inventory/graphql/__init__.py @@ -4,7 +4,7 @@ PurchaseQuery, DeliveryQuery, InventoryItemTypeQuery, - InventoryItemGroupQuery + InventoryItemGroupQuery, ) schema = [ @@ -13,5 +13,5 @@ PurchaseQuery, DeliveryQuery, InventoryItemTypeQuery, - InventoryItemGroupQuery -] \ No newline at end of file + InventoryItemGroupQuery, +] diff --git a/netbox_inventory/graphql/filters.py b/netbox_inventory/graphql/filters.py index 46885c8..99b5b56 100644 --- a/netbox_inventory/graphql/filters.py +++ b/netbox_inventory/graphql/filters.py @@ -3,42 +3,48 @@ from netbox.graphql.filter_mixins import autotype_decorator, BaseFilterMixin from netbox_inventory import filtersets, models + __all__ = ( - 'AssetFilter', - 'SupplierFilter', - 'PurchaseFilter', - 'DeliveryFilter', - 'InventoryItemTypeFilter', - 'InventoryItemGroupFilter', + "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 - diff --git a/netbox_inventory/graphql/schema.py b/netbox_inventory/graphql/schema.py index ed03343..c7415c6 100644 --- a/netbox_inventory/graphql/schema.py +++ b/netbox_inventory/graphql/schema.py @@ -1,13 +1,13 @@ import strawberry import strawberry_django -from netbox_inventory.models import ( +from netbox_inventory.models import ( Asset, Supplier, Purchase, Delivery, InventoryItemType, - InventoryItemGroup + InventoryItemGroup, ) from .types import ( AssetType, @@ -15,47 +15,59 @@ PurchaseType, DeliveryType, InventoryItemTypeType, - InventoryItemGroupType - ) + 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() diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index 4fb41ed..9c49e5c 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -3,54 +3,122 @@ from typing import Annotated from netbox.graphql.types import NetBoxObjectType from extras.graphql.mixins import ContactsMixin -from netbox_inventory.models import Asset, Supplier, Purchase, Delivery, InventoryItemType, InventoryItemGroup +from netbox_inventory.models import ( + Asset, + Supplier, + Purchase, + Delivery, + InventoryItemType, + InventoryItemGroup, +) from .filters import ( AssetFilter, SupplierFilter, PurchaseFilter, DeliveryFilter, InventoryItemTypeFilter, - InventoryItemGroupFilter + InventoryItemGroupFilter, ) + @strawberry_django.type(Asset, fields="__all__", filters=AssetFilter) class AssetType(ContactsMixin, 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 + 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(NetBoxObjectType): - purchases: list[Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")]] + 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")]] + 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(ContactsMixin, 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")]] + 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) + +@strawberry_django.type( + InventoryItemType, fields="__all__", filters=InventoryItemTypeFilter +) class InventoryItemTypeType(NetBoxObjectType): manufacturer: Annotated["ManufacturerType", strawberry.lazy("dcim.graphql.types")] - inventoryitem_group: Annotated["InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types")] | None + inventoryitem_group: ( + Annotated[ + "InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types") + ] + | None + ) -@strawberry_django.type(InventoryItemGroup, fields="__all__", filters=InventoryItemGroupFilter) + +@strawberry_django.type( + InventoryItemGroup, fields="__all__", filters=InventoryItemGroupFilter +) class InventoryItemGroupType(NetBoxObjectType): - 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")]] \ No newline at end of file + 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") + ] + ] From a52c75946052463cc2b51582b757a567d126aef1 Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Thu, 29 Aug 2024 12:02:37 -0700 Subject: [PATCH 36/41] feat: update netbox-inventory --- netbox_inventory/graphql/types.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index 9c49e5c..dfae894 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -2,7 +2,6 @@ import strawberry_django from typing import Annotated from netbox.graphql.types import NetBoxObjectType -from extras.graphql.mixins import ContactsMixin from netbox_inventory.models import ( Asset, Supplier, @@ -22,7 +21,7 @@ @strawberry_django.type(Asset, fields="__all__", filters=AssetFilter) -class AssetType(ContactsMixin, NetBoxObjectType): +class AssetType(NetBoxObjectType): device_type: ( Annotated["DeviceTypeType", strawberry.lazy("dcim.graphql.types")] | None ) @@ -77,7 +76,7 @@ class PurchaseType(NetBoxObjectType): @strawberry_django.type(Delivery, fields="__all__", filters=DeliveryFilter) -class DeliveryType(ContactsMixin, NetBoxObjectType): +class DeliveryType(NetBoxObjectType): purchase: Annotated[ "PurchaseType", strawberry.lazy("netbox_inventory.graphql.types") ] From 7daaa0cc50ede7ce232c9ae8803c5d9d6dcaeae8 Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Thu, 29 Aug 2024 13:27:36 -0700 Subject: [PATCH 37/41] feat: update netbox-inventory --- netbox_inventory/graphql/types.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index dfae894..1b6c707 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -1,7 +1,8 @@ import strawberry import strawberry_django from typing import Annotated -from netbox.graphql.types import NetBoxObjectType +from extras.graphql.mixins import ContactsMixin +from netbox.graphql.types import NetBoxObjectType, OrganizationalObjectType from netbox_inventory.models import ( Asset, Supplier, @@ -56,14 +57,14 @@ class AssetType(NetBoxObjectType): @strawberry_django.type(Supplier, fields="__all__", filters=SupplierFilter) -class SupplierType(NetBoxObjectType): +class SupplierType(OrganizationalObjectType, ContactsMixin): purchases: list[ Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")] ] @strawberry_django.type(Purchase, fields="__all__", filters=PurchaseFilter) -class PurchaseType(NetBoxObjectType): +class PurchaseType(NetBoxObjectType, ContactsMixin): supplier: Annotated[ "SupplierType", strawberry.lazy("netbox_inventory.graphql.types") ] @@ -76,7 +77,7 @@ class PurchaseType(NetBoxObjectType): @strawberry_django.type(Delivery, fields="__all__", filters=DeliveryFilter) -class DeliveryType(NetBoxObjectType): +class DeliveryType(NetBoxObjectType, ContactsMixin): purchase: Annotated[ "PurchaseType", strawberry.lazy("netbox_inventory.graphql.types") ] @@ -104,7 +105,7 @@ class InventoryItemTypeType(NetBoxObjectType): @strawberry_django.type( InventoryItemGroup, fields="__all__", filters=InventoryItemGroupFilter ) -class InventoryItemGroupType(NetBoxObjectType): +class InventoryItemGroupType(OrganizationalObjectType): parent: ( Annotated[ "InventoryItemGroupType", strawberry.lazy("netbox_inventory.graphql.types") From bbe2d88aac538c9fdc8b8604567f537478a65df4 Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Thu, 29 Aug 2024 13:44:55 -0700 Subject: [PATCH 38/41] feat: update netbox-inventory --- netbox_inventory/graphql/types.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index 1b6c707..e9f0abf 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -2,7 +2,7 @@ import strawberry_django from typing import Annotated from extras.graphql.mixins import ContactsMixin -from netbox.graphql.types import NetBoxObjectType, OrganizationalObjectType +from netbox.graphql.types import BaseObjectType, NetBoxObjectType, OrganizationalObjectType from netbox_inventory.models import ( Asset, Supplier, @@ -57,14 +57,14 @@ class AssetType(NetBoxObjectType): @strawberry_django.type(Supplier, fields="__all__", filters=SupplierFilter) -class SupplierType(OrganizationalObjectType, ContactsMixin): +class SupplierType(NetBoxObjectType, ContactsMixin): purchases: list[ Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")] ] @strawberry_django.type(Purchase, fields="__all__", filters=PurchaseFilter) -class PurchaseType(NetBoxObjectType, ContactsMixin): +class PurchaseType(NetBoxObjectType): supplier: Annotated[ "SupplierType", strawberry.lazy("netbox_inventory.graphql.types") ] @@ -77,7 +77,7 @@ class PurchaseType(NetBoxObjectType, ContactsMixin): @strawberry_django.type(Delivery, fields="__all__", filters=DeliveryFilter) -class DeliveryType(NetBoxObjectType, ContactsMixin): +class DeliveryType(NetBoxObjectType): purchase: Annotated[ "PurchaseType", strawberry.lazy("netbox_inventory.graphql.types") ] @@ -92,7 +92,7 @@ class DeliveryType(NetBoxObjectType, ContactsMixin): @strawberry_django.type( InventoryItemType, fields="__all__", filters=InventoryItemTypeFilter ) -class InventoryItemTypeType(NetBoxObjectType): +class InventoryItemTypeType(BaseObjectType): manufacturer: Annotated["ManufacturerType", strawberry.lazy("dcim.graphql.types")] inventoryitem_group: ( Annotated[ From c96069c7c2d13cdf91a27c19a2369148b66a6a40 Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Thu, 29 Aug 2024 13:51:29 -0700 Subject: [PATCH 39/41] feat: update netbox-inventory --- netbox_inventory/graphql/types.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index e9f0abf..f570838 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -1,7 +1,7 @@ import strawberry import strawberry_django from typing import Annotated -from extras.graphql.mixins import ContactsMixin +from extras.graphql.mixins import ContactsMixin, ImageAttachmentsMixin from netbox.graphql.types import BaseObjectType, NetBoxObjectType, OrganizationalObjectType from netbox_inventory.models import ( Asset, @@ -22,7 +22,7 @@ @strawberry_django.type(Asset, fields="__all__", filters=AssetFilter) -class AssetType(NetBoxObjectType): +class AssetType(ImageAttachmentsMixin, NetBoxObjectType): device_type: ( Annotated["DeviceTypeType", strawberry.lazy("dcim.graphql.types")] | None ) @@ -57,7 +57,7 @@ class AssetType(NetBoxObjectType): @strawberry_django.type(Supplier, fields="__all__", filters=SupplierFilter) -class SupplierType(NetBoxObjectType, ContactsMixin): +class SupplierType(ContactsMixin, NetBoxObjectType): purchases: list[ Annotated["PurchaseType", strawberry.lazy("netbox_inventory.graphql.types")] ] @@ -92,7 +92,7 @@ class DeliveryType(NetBoxObjectType): @strawberry_django.type( InventoryItemType, fields="__all__", filters=InventoryItemTypeFilter ) -class InventoryItemTypeType(BaseObjectType): +class InventoryItemTypeType(ImageAttachmentsMixin, BaseObjectType): manufacturer: Annotated["ManufacturerType", strawberry.lazy("dcim.graphql.types")] inventoryitem_group: ( Annotated[ From 8960493cc69bfdf5da20e19d6b5109bad06e10e6 Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Thu, 29 Aug 2024 13:51:50 -0700 Subject: [PATCH 40/41] feat: update netbox-inventory --- netbox_inventory/graphql/types.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index f570838..fcd67c3 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -2,7 +2,11 @@ import strawberry_django from typing import Annotated from extras.graphql.mixins import ContactsMixin, ImageAttachmentsMixin -from netbox.graphql.types import BaseObjectType, NetBoxObjectType, OrganizationalObjectType +from netbox.graphql.types import ( + BaseObjectType, + NetBoxObjectType, + OrganizationalObjectType, +) from netbox_inventory.models import ( Asset, Supplier, From 7b088295aa4e7a2cbe08d1f76c5a7fcf2d2ff4fb Mon Sep 17 00:00:00 2001 From: Joshua Coronado Date: Thu, 29 Aug 2024 13:53:09 -0700 Subject: [PATCH 41/41] feat: update netbox-inventory --- netbox_inventory/graphql/types.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/netbox_inventory/graphql/types.py b/netbox_inventory/graphql/types.py index fcd67c3..4ace601 100644 --- a/netbox_inventory/graphql/types.py +++ b/netbox_inventory/graphql/types.py @@ -3,7 +3,6 @@ from typing import Annotated from extras.graphql.mixins import ContactsMixin, ImageAttachmentsMixin from netbox.graphql.types import ( - BaseObjectType, NetBoxObjectType, OrganizationalObjectType, ) @@ -96,7 +95,7 @@ class DeliveryType(NetBoxObjectType): @strawberry_django.type( InventoryItemType, fields="__all__", filters=InventoryItemTypeFilter ) -class InventoryItemTypeType(ImageAttachmentsMixin, BaseObjectType): +class InventoryItemTypeType(ImageAttachmentsMixin, NetBoxObjectType): manufacturer: Annotated["ManufacturerType", strawberry.lazy("dcim.graphql.types")] inventoryitem_group: ( Annotated[