1

To make yet another d3 viewer, I'd like to get a graph out from a rest query.

In my understanding, stating 'resultDataContent':['graph'] would return a graph. Instead, it return a list of subgraphs and I need therefore to collect and distinct the nodes. Is there a way to get the full sub graph simply?

For example, I put these 4 nodes

CREATE (a:Person {name:'a'}) CREATE (b:Person {name:'b'}) CREATE (c:Person {name:'c'}) CREATE (d:Person {name:'d'}) CREATE (a)-[:KNOWS]->(b) CREATE (a)-[:KNOWS]->(c) CREATE (b)-[:KNOWS]->(c) CREATE (c)-[:KNOWS]->(d) 

But calling a POST query with the following query will return 2 results.data, each of them with a "graph", consisting of 2 nodes and a links?

{"statements":[ { "statement":"MATCH (p:Person {name:{pName}})-[l:KNOWS]-(q:Person) RETURN p,l,q", "parameters":{"pName":"a"}, "resultDataContents":["graph"] } ]} 

Is there a way to return the one subgraph, without the need to reassemble the results?

Thanks for the help, Alex

2 Answers 2

1

I think the issue is that the same person will be returned twice by your query. Change the return statement to:

RETURN collect(distinct(p)),collect(l),collect(distinct(q)) 

That will give you the following response:

{ "results": [ { "columns": [ "collect(distinct(p))", "collect(l)", "collect(distinct(q))" ], "data": [ { "graph": { "nodes": [ { "id": "1849644", "labels": [ "Person" ], "properties": { "name": "b" } }, { "id": "1849645", "labels": [ "Person" ], "properties": { "name": "c" } }, { "id": "1849643", "labels": [ "Person" ], "properties": { "name": "a" } } ], "relationships": [ { "id": "4052753", "type": "KNOWS", "startNode": "1849643", "endNode": "1849644", "properties": {} }, { "id": "4052754", "type": "KNOWS", "startNode": "1849643", "endNode": "1849645", "properties": {} } ] } } ] } ], "errors": [] } 
Sign up to request clarification or add additional context in comments.

Comments

0

Whilst working on something similar (https://stackoverflow.com/questions/26067792/neo4j-cypher-gui) I've run into the same problem. The documentation: http://docs.neo4j.org/chunked/stable/rest-api-transactional.html is very light on the subject

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.