import ballerina/graphql; type TLift record {| readonly string id; string name; string status; int capacity; boolean night; int elevationgain; |}; type TTrail record {| readonly string id; string name; string status; string difficulty; boolean groomed; boolean trees; boolean night; |}; type Edge record {| readonly string liftId; readonly string trailId; |}; table key(id) liftTable = table [ { id: "l1", name: "Lift1", status: "OPEN", capacity: 10, night: false, elevationgain: 20} ]; table key(id) trailTabel = table [ {id: "t1", name: "tail1", status: "OPEN", difficulty: "HARD", groomed: true, trees: false, night: false} ]; table key(liftId, trailId) edgeTable = table [ {liftId: "l1", trailId: "t1"} ]; service /graphql on new graphql:Listener(9000) { resource function get allLifts(string? status) returns Lift { TLift[] tLifts = from var l in liftTable where l.status == "OPEN" select l; return new Lift(tLifts[0]); } } service class Lift { private TLift tLift; function init(TLift tLift) { self.tLift = tLift; } resource function get id () returns string { return self.tLift.id; } resource function get name () returns string { return self.tLift.name; } resource function get status () returns string { return self.tLift.status; } resource function get capacity () returns int { return self.tLift.capacity; } resource function get night () returns boolean { return self.tLift.night; } resource function get elevationgain () returns int { return self.tLift.elevationgain; } resource function get trailAccess () returns Trail { TLift[] lifts = [self.tLift]; Edge[] edges = from var edge in edgeTable join var lift in lifts on edge.liftId equals lift.id select edge; TTrail[] trails = from var trail in trailTabel join var edge in edges on trail.id equals edge.trailId select trail; return new Trail(trails[0]); } } service class Trail { private TTrail tTrail; function init(TTrail tTrail) { self.tTrail = tTrail; } resource function get id () returns string { return self.tTrail.id; } resource function get name () returns string { return self.tTrail.name; } resource function get status () returns string { return self.tTrail.status; } resource function get difficulty () returns string { return self.tTrail.difficulty; } resource function get groomed () returns boolean { return self.tTrail.groomed; } resource function get trees () returns boolean { return self.tTrail.trees; } resource function get night () returns boolean { return self.tTrail.night; } }