Fix GraphQL types - add distance_km field
All checks were successful
Build Docker Image / build (push) Successful in 1m17s

- Add distance_km field to NodeType (used by nearestHubs)
- Add distance_km field to OfferNodeType (used by nearestOffers)
- Expand SupplierType with name, latitude, longitude, distance_km
- Fix nearestSuppliers to return full supplier info from nodes collection
- Fix nearestHubs and nearestOffers to pass distance_km to constructors

This fixes 8 failed integration tests for nearest* endpoints.

Resolves: Cannot query field 'distanceKm' on type 'NodeType/OfferNodeType'
This commit is contained in:
Ruslan Bakiev
2026-01-25 21:33:12 +07:00
parent 40f7f66f83
commit 64f7e4bdba

View File

@@ -33,6 +33,7 @@ class NodeType(graphene.ObjectType):
synced_at = graphene.String()
transport_types = graphene.List(graphene.String)
edges = graphene.List(EdgeType)
distance_km = graphene.Float()
class NodeConnectionsType(graphene.ObjectType):
@@ -117,6 +118,10 @@ class ProductType(graphene.ObjectType):
class SupplierType(graphene.ObjectType):
"""Unique supplier from offers."""
uuid = graphene.String()
name = graphene.String()
latitude = graphene.Float()
longitude = graphene.Float()
distance_km = graphene.Float()
class OfferNodeType(graphene.ObjectType):
@@ -133,6 +138,7 @@ class OfferNodeType(graphene.ObjectType):
currency = graphene.String()
quantity = graphene.String()
unit = graphene.String()
distance_km = graphene.Float()
class Query(graphene.ObjectType):
@@ -1444,6 +1450,7 @@ class Query(graphene.ObjectType):
synced_at=node.get('synced_at'),
transport_types=node.get('transport_types') or [],
edges=[],
distance_km=node.get('distance_km'),
))
logger.info("Found %d hubs near (%.3f, %.3f) within %d km", len(hubs), lat, lon, radius)
return hubs
@@ -1494,6 +1501,7 @@ class Query(graphene.ObjectType):
currency=node.get('currency'),
quantity=node.get('quantity'),
unit=node.get('unit'),
distance_km=node.get('distance_km'),
))
logger.info("Found %d offers near (%.3f, %.3f) within %d km", len(offers), lat, lon, radius)
return offers
@@ -1521,10 +1529,22 @@ class Query(graphene.ObjectType):
COLLECT supplier_uuid = offer.supplier_uuid INTO offers
LET first_offer = FIRST(offers).offer
LET supplier_dist = DISTANCE(first_offer.latitude, first_offer.longitude, @lat, @lon) / 1000
// Try to find supplier node for full info
LET supplier_node = FIRST(
FOR s IN nodes
FILTER s._key == supplier_uuid
FILTER s.node_type == 'supplier'
RETURN s
)
SORT supplier_dist ASC
LIMIT @limit
RETURN {
uuid: supplier_uuid,
name: supplier_node != null ? supplier_node.name : first_offer.supplier_name,
latitude: supplier_node != null ? supplier_node.latitude : first_offer.latitude,
longitude: supplier_node != null ? supplier_node.longitude : first_offer.longitude,
distance_km: supplier_dist
}
"""
@@ -1537,7 +1557,13 @@ class Query(graphene.ObjectType):
cursor = db.aql.execute(aql, bind_vars=bind_vars)
suppliers = []
for s in cursor:
suppliers.append(SupplierType(uuid=s['uuid']))
suppliers.append(SupplierType(
uuid=s['uuid'],
name=s.get('name'),
latitude=s.get('latitude'),
longitude=s.get('longitude'),
distance_km=s.get('distance_km'),
))
logger.info("Found %d suppliers near (%.3f, %.3f) within %d km", len(suppliers), lat, lon, radius)
return suppliers
except Exception as e: