Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
06-28-2021 09:06 AM
I'm running into an issue where I am querying my database and asking Neo4j to return the results in graph format so that I can use D3 or some derivative of it to render my graph result in a web application.
First, I'll add the data:
CREATE ( bike:Bike { weight: 10 } ) CREATE ( frontWheel:Wheel { spokes: 3 } ) CREATE ( backWheel:Wheel { spokes: 32 } ) CREATE p1 = (bike)-[:HAS { position: 1 } ]->(frontWheel) CREATE p2 = (bike)-[:HAS { position: 2 } ]->(backWheel) RETURN bike, p1, p2
Then, in Neo4j Browser (via Neo4j Desktop), if I run this Cypher statement:
MATCH (a) RETURN a;
The graph view of the result contains multiple nodes connected to one another via multiple relationships. Like this:
However, when performing the same query using the HTTP API, instead of receiving a single graph object with the same nodes and relationships that I saw in the Neo4j Browser, I instead get multiple, separate graph objects, each with only one node in it, and therefore, over the entire HTTP response, there are no relationships returned. If I rendered this, I would not have the necessary relationship information to render the result like Neo4j Browser does, and I'd be left with this:
It seems as though the Neo4j Browser is adding in relationships that exist for rendering the graph which are relationships that are not returned by the HTTP API. How can I recreate the graph result rendering done by Neo4j Browser in my web app?
What I expect:
{
"results": [
{
"columns": [
"a"
],
"data": [
{
"graph": {
"nodes": [
{...
},
{...
},
{...
}
],
"relationships": [
{...
},
{...
}
]
}
}
]
}
]
What I get:
{
"results": [
{
"columns": [
"a"
],
"data": [
{
"graph": {
"nodes": [
{...
}
],
"relationships": []
}
},
{
"graph": {
"nodes": [
{...
}
],
"relationships": []
}
},
{
"graph": {
"nodes": [
{...
}
],
"relationships": []
}
}
]
}
]
07-02-2021 04:00 PM
Yes neo4j browser runs an additional query that is enabled/disabled with the "connect result nodes" setting, which is basically
MATCH (a)-[r]->(b) WHERRE id(a) in $ids and id(b) IN $ids RETURN r
To fetch the relationships after the fact.
All the sessions of the conference are now available online