Create buildGraph function