Duplicate a subgraph

I already gave you all information in other topic:

CALL gds.graph.project(
    "graph",            
    "*",             
    "*"               
)
YIELD graphName AS graph, nodeProjection, nodeCount AS nodes, relationshipProjection, relationshipCount AS rels
CALL gds.wcc.write('graph', { writeProperty: 'componentId' })
YIELD nodePropertiesWritten, componentCount;
CALL gds.graph.drop('graph', false) YIELD graphName;

So after you can change the 0 by the componentId you want:

MATCH (n)
WHERE n.componentId = 0
WITH collect(n) AS nodes
CALL apoc.refactor.cloneSubgraph(nodes)
YIELD input, output, error
RETURN input, output, error;

If you know which nodes you want to duplicates, you can change the WHERE clause in the previous query to select only the nodes you want.

1 Like

Hey Cobra, thank you for your answers!
I only have the apoc library my version of neo4j is 3.5.30
so I tried to create a new graph, a simple one that looks loke this:


and I tried to duplicate query like this:

MATCH (n)
WHERE n.name = "Graph1" AND WHERE ID(type) ="CellType"
AND WHERE ID(type)="Function" AND WHERE ID(type) = "cellInstance" And WHERE ID(type) ="Connection"
AND WHERE ID(type) = "Variable"
WITH collect(n) AS nodes
CALL apoc.refactor.cloneSubgraph(nodes,[rel in relationships Where type(rel) = ‘From_Graph’ AND Where type(rel) =’FROM_TYPE’ Where type(rel) = ‘CELL_TYPE_FUNCTION’ AND Where type(rel) = ‘FROM_CELL’ AND Where type(rel) = ‘FUNCTION_INPUT_VARIABLE’ AND Where type(rel)= ‘TO_CELL’,AND Where type(rel) = ‘Functions_VARS’ ])
YIELD input, output, error
RETURN input, output, error;
still doesn't work for me :(
any suggestions?

You must use the latest version of Neo4j which is 4.4.6 then install GDS plugin on the database to use the queries I gave you.

Isn't there any other way to do it with this query you offered and use apoc only?
MATCH (n)
WHERE n.name = "Graph1"
WITH collect(n) AS nodes
CALL apoc.refactor.cloneSubgraph(nodes)
YIELD input, output, error
RETURN input, output, error;

No because you need GDS to tag nodes correctly. Moreover Neo4j 3.5 is no longer maintained so you must upgrade.

1 Like

Ok, so i'll try to upgrade it and use the queries you offered. i'll let you know if I succeeded
Cobra thank you so much for trying to help me I really
appriciate it.
have a lovely weekend!

1 Like