From 0106c84daf49b5637f8107668c8bafbd3e6a0ea8 Mon Sep 17 00:00:00 2001 From: Ruslan Bakiev <572431+veikab@users.noreply.github.com> Date: Thu, 22 Jan 2026 17:22:05 +0700 Subject: [PATCH] Add offers_count field to ProductType --- geo_app/schema.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/geo_app/schema.py b/geo_app/schema.py index d9ac744..b826f47 100644 --- a/geo_app/schema.py +++ b/geo_app/schema.py @@ -95,6 +95,23 @@ class ProductType(graphene.ObjectType): """Unique product from offers.""" uuid = graphene.String() name = graphene.String() + offers_count = graphene.Int(description="Number of offers for this product") + + def resolve_offers_count(self, info): + db = get_db() + aql = """ + FOR node IN nodes + FILTER node.node_type == 'offer' + FILTER node.product_uuid == @product_uuid + COLLECT WITH COUNT INTO length + RETURN length + """ + try: + cursor = db.aql.execute(aql, bind_vars={'product_uuid': self.uuid}) + return next(cursor, 0) + except Exception as e: + logger.error("Error counting offers for product %s: %s", self.uuid, e) + return 0 class SupplierType(graphene.ObjectType):