You don't actually say programmatically, but you have tagged this 'perl'... The graph_local table in the Cacti SQL database has a list of all graphs and which host they are related to.
select host_id,count(*) from graph_local group by host_id;
Will give you a list broken down by host_id. Pull in the host description from the host table if you need it:
select host.description, host.id, count(*) from graph_local,host where graph_local.host_id=host.id group by host_id;
However you should also look at the Autom8 plugin, if what you are trying to achieve is something like: "Find all 'up' ethernet interfaces, and create a traffic graph for one's that don't already have one", or "Find all devices with Host Template XX, and add a graph for CPU usage if they don't have one". Autom8 will do this for you.