build loadGraph function