graph: throw error on creation if graph is invalid