Delete subgraph using cypher-dsl

Hi All, Hope you are well.

We are using neo4j in our team and came across s use case where I hathe ve id of the parent node and would like to delete the entire subtree. I am using cypher-dsl and to delete the subgraphs have the following code:

static Statement deleteAllConfigNode(String cfgId) {
String userProvidedCypher =
"MATCH (p:confignode {cfgId: '"+ cfgId+"'}) " +
"CALL apoc.path.subgraphAll(p, {relationshipFilter: 'BELONGS_TO_ARRAY|IN|IN_ARRAY', minLevel: 1, maxLevel: 3}) " +
"YIELD nodes, relationships " +
"FOREACH(node in nodes |detach delete node)";

var userStatement = CypherParser.parse(userProvidedCypher); // <.>
var result = Cypher.name("nodes");
return Cypher
.call(userStatement) //<=========== Fails here
.returning(result)
.build();
}

The above code generates following query:

MATCH (p:confignode {oid: '738'})
CALL apoc.path.subgraphAll(p, {relationshipFilter: 'BELONGS_TO_ARRAY|IN|IN_ARRAY', minLevel: 1, maxLevel: 3}) yield nodes
FOREACH(node in nodes |detach delete node)

The query works fine in the neo4j browser but fails in Java code with the following error:

Statement cypherStmt;
cypherStmt = deleteAllConfigNode(oid);
dao.findAll(cypherStmt);
// logs
Error:
2023-06-13 02:05:00.877 ERROR [,699423cafde5fdb4,699423cafde5fdb4] 60047 --- [oundedElastic-2] c.p.api.handlers.ExceptionAnalyzer : Caught Exception: java.lang.IllegalArgumentException: Only a statement that returns elements, either via RETURN or YIELD, can be used in a subquery.
org.neo4j.cypherdsl.core.Subquery.call(Subquery.java:73)

what I am doing wrong or any guidance

As per exception, the statement in the Cypher.call() needs a return.
Can you try to modify your statement by adding RETURN null?

"MATCH (p:confignode {cfgId: '"+ cfgId+"'}) " +
"CALL apoc.path.subgraphAll(p, {relationshipFilter: 'BELONGS_TO_ARRAY|IN|IN_ARRAY', minLevel: 1, maxLevel: 3}) " +
"YIELD nodes, relationships " +
"FOREACH(node in nodes |detach delete node)" +
"RETURN null";