Neo4jClient - Serializing response all attributes

This is my current query:

MATCH path=(p)<-[r:partOf*0..]-(a:NodeType)
  WHERE elementId(a) = '4:d2fb2e08-d9a8-4ace-b7b6-305175ee9551:6335'
  WITH p, elementId(p) AS uuid, [relationships(path)][0][0] AS rel
  RETURN uuid,
         p.name as name,
         rel,
         "A" as dir
UNION
MATCH path=(a:NodeType)<-[r:partOf*0..]-(p:NodeType) 
  WHERE elementId(a) = '4:d2fb2e08-d9a8-4ace-b7b6-305175ee9551:6335'
  WITH p, elementId(p) AS uuid, [relationships(path)][0][size(relationships(path))-1] AS rel
  RETURN uuid,
         p.name as name,  
         rel,
         "D" as dir

Where "A" tells me if they are ancestors / "D" descendants

rel contains:

{
  "identity": 179,
  "start": 6467,
  "end": 6359,
  "type": "partOf",
  "properties": {

  },
  "elementId": "5:d2fb2e08-d9a8-4ace-b7b6-305175ee9551:179",
  "startNodeElementId": "4:d2fb2e08-d9a8-4ace-b7b6-305175ee9551:6467",
  "endNodeElementId": "4:d2fb2e08-d9a8-4ace-b7b6-305175ee9551:6359"
}

and I extract the nodes:

Start = (null != cursor.Current["rel"]) ? cursor.Current["rel"].As<Neo4j.Driver.IRelationship>().StartNodeElementId : "",
End = (null != cursor.Current["rel"]) ? cursor.Current["rel"].As<Neo4j.Driver.IRelationship>().EndNodeElementId : ""

But all of this is 'waste' payload per row:

{
  "identity": 179,
  "start": 6467,
  "end": 6359,
  "type": "partOf",
  "properties": {

  },
  "elementId": "5:d2fb2e08-d9a8-4ace-b7b6-305175ee9551:179",

For context, I need to know all of this because the user might have no access to edit ancestors but does have access to edit descendants (the whole structure of each node is stored in a separate DB with the elementID as key).

This should give you the same thing:

MATCH path=(p)<-[r:partOf*0..]-(a:NodeType)
  WHERE elementId(a) = '4:d2fb2e08-d9a8-4ace-b7b6-305175ee9551:6335'
  WITH p, elementId(p) AS uuid, head(relationships(path)) AS rel
  RETURN uuid,
         p.name as name,
         rel,
         "A" as dir
UNION
MATCH path=(a:NodeType)<-[r:partOf*0..]-(p:NodeType) 
  WHERE elementId(a) = '4:d2fb2e08-d9a8-4ace-b7b6-305175ee9551:6335'
  WITH p, elementId(p) AS uuid, last(relationships(path)) AS rel
  RETURN uuid,
         p.name as name,  
         rel,
         "D" as dir

If you don't want to send all the 'rel' information in your payload, then you can return just the fields you want in a map.

MATCH path=(p)<-[r:partOf*0..]-(a:NodeType)
  WHERE elementId(a) = '4:d2fb2e08-d9a8-4ace-b7b6-305175ee9551:6335'
  WITH p, elementId(p) AS uuid, head(relationships(path)) AS relAll
  RETURN uuid,
         p.name as name,
         {
           startNodeElementId: elementId(startNode(relAll)),  
           endNodeElementId: elementId(endNode(relAll))
         } as rel,
         "A" as dir
UNION
MATCH path=(a:NodeType)<-[r:partOf*0..]-(p:NodeType) 
  WHERE elementId(a) = '4:d2fb2e08-d9a8-4ace-b7b6-305175ee9551:6335'
  WITH p, elementId(p) AS uuid, last(relationships(path)) AS relAll
  RETURN uuid,
        p.name as name,  
        {
           startNodeElementId: elementId(startNode(relAll)),  
           endNodeElementId: elementId(endNode(relAll))
        } as rel,
        "D" as dir
1 Like

This opens so many doors to optimising traffic ! :slight_smile:

1 Like