cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Procedure return type

Hello everyone, I am having some problems with the Cypher procedures.
I want to return the graph that I get from executing a cypher query but I can't wrap my head around what type I need to return from my procedure method and what GraphDatabaseService method I need to execute to get that object. I am pretty sure it is a stream with a custom type containing the data I want to return but what is that precisely?
As my first try I am trying to return the base Hello World query that is included in the Basic Query scripts.

Here is an extract of my procedure method:

@Procedure("ktk.mytest")
@Description("A test procedure that therurns HELLO WORLD!")
public Stream<MyTestResult> test(){
String query;
query = "CREATE (database:Database {name:"Neo4j"})-[r:SAYS]->(message:Message {name:"Hello World!"}) RETURN database, message, r";

Stream<MyTestResult> rStream = db.execute(query).stream().map(MyTestResult::new);

return rStream;
}

Thank you very much and sorry for the very simple question, I am quite a noob at this.

Thanks,
Gustavo.

4 REPLIES 4

Benoit
Graph Buddy

Hi Gustavo,

What error do you have with this code ?
Can you give the code of the MyTestResult class ?

Cheers

Sure, here is the code of the MyResult class:

public class MyTestResult {

public long nodeId;
public MyTestResult(Node node) {

this.nodeId = node.getId();
}
}

The error is that it cannot convert to type R.

Your cypher query returns a iterable of <Map<String, Object>. MyTestResult will need a constructor like,

public MyTestResult(Map<String, Object> onerow) {
...
}

That should resolve your syntax error

Cheers

Thank you Aldrin, I missed that detail!