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.

Graph formatted results from HTTP API contain multiple graph objects instead of one

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:

3X_2_a_2a70db8585540f840140d11e4bd28b0ba6e22fdc.png

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:

3X_1_e_1eba744e49b0f822b19d56428033b4e310e9707b.png

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": []
                    }
                }
            ]
        }
    ]
1 REPLY 1

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.