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):