One option is to build a graph from Node objects (as you are doing now), and then to truncate the graph, encapsulate it using the Graph object, which stores the graph as a member, provides its own interface for performing operations on the graph and internally uses a table of nodes that should be considered deleted from the graph.
The advantage of this approach is that you do not mutate the original graph object, and you also do not need to copy it.
source share