Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Optimize stock warehouse resolver performance

Tomasz Szymanski955489bff02a
diff --git a/saleor/graphql/warehouse/types.py b/saleor/graphql/warehouse/types.py
index 9ce16b31bd..97511e7acf 100644
--- a/saleor/graphql/warehouse/types.py
+++ b/saleor/graphql/warehouse/types.py
@@ -14,6 +14,7 @@ from ..core.fields import ConnectionField
from ..core.types import ModelObjectType, NonNullList
from ..decorators import one_of_permissions_required
from ..meta.types import ObjectWithMetadata
+from .dataloaders import WarehouseByIdLoader
from .enums import WarehouseClickAndCollectOptionEnum
@@ -181,6 +182,12 @@ class Stock(ModelObjectType):
)
)["quantity_reserved"]
+ @staticmethod
+ def resolve_warehouse(root, info, *_args, **kwargs):
+ if root.warehouse_id:
+ return WarehouseByIdLoader(info.context).load(root.warehouse_id)
+ return None
+
@staticmethod
def resolve_product_variant(root, *_args):
return ChannelContext(node=root.product_variant, channel_slug=None)