I need to return nodes along with their IDs, and things like this are to be avoided:
RETURN n, ID(n) as n_ID
I would very much prefer to be able to return the ID as a "computed" property of the node, so that the client sees the node as if it had a property named id
.
I've been breaking my head over this for hours now. The closest I found is this comment under an unsatisfying answer to a similar question:
MATCH (n:Person) RETURN { id: ID(n), name: n.name } as user
That method is useless because it requires manually reconstructing the node as a map literal in the RETURN clause. This is impossible if you don't know all the property names, which will be the typical scenario in my application; plus, there might be lots of properties.
Next thing I tried was operator '+'. It throws a Type Mismatch; you cannot combine a Map with a Node this way. I cannot find any documented way to convert a Node to a Map either. The docs mention KEYS(), but no VALUES(), nor a way to "zip" keys and values into a map.
Another thing I thought of trying:
REDUCE(theMap = {id: ID(n)}, k in KEYS(n) | theMap + { what? : what? })
... but I know neither how to do a "variable key" in an array literal, nor how to access a node's property by a variable key.
Is what I am trying to do at all possible in cypher?