An issue has just been raised against py2neo, saying that it fails when
returning a map literal from a Cypher query:

https://github.com/nigelsmall/py2neo/issues/240

This does not surprise me as I was unaware that map literals were even
supported. There is no mention of them in the list of valid Cypher
expressions (http://docs.neo4j.org/chunked/milestone/cypher-expressions.html)
- I assume this was added recently?

There is however something of a problem with adding support for this. When
Cypher results are returned over REST, Nodes, Relationships and Paths are
all serialised into JSON objects. Py2neo attempts to sniff the type of
object by looking for certain keys (not great but the only option
available). If I also need to now support map literals, How do I
categorically determine whether a result is a map literal or one of these
objects?

To illustrate this, the following two queries return identical output:

curl -X POST http://localhost:7474/db/data/cypher -H 'Content-Type:
application/json' -d "{\"query\":\"CREATE (a) RETURN a\"}"

curl -X POST http://localhost:7474/db/data/cypher -H 'Content-Type:
application/json' -d "{\"query\":\"CREATE (a) RETURN
{outgoing_relationships: '
http://localhost:7474/db/data/node/1/relationships/out', labels: '
http://localhost:7474/db/data/node/1/labels', data: {},
all_typed_relationships: '
http://localhost:7474/db/data/node/1/relationships/all/{-list|&|types}',
traverse: 'http://localhost:7474/db/data/node/1/traverse/{returnType}',
self: 'http://localhost:7474/db/data/node/1', property: '
http://localhost:7474/db/data/node/1/properties/{key}',
outgoing_typed_relationships: '
http://localhost:7474/db/data/node/1/relationships/out/{-list|&|types}',
properties: 'http://localhost:7474/db/data/node/1/properties',
incoming_relationships: '
http://localhost:7474/db/data/node/1/relationships/in', extensions: {},
create_relationship: 'http://localhost:7474/db/data/node/1/relationships',
paged_traverse: '
http://localhost:7474/db/data/node/1/paged/traverse/{returnType}{?pageSize,leaseTime}',
all_relationships: 'http://localhost:7474/db/data/node/1/relationships/all',
incoming_typed_relationships: '
http://localhost:7474/db/data/node/1/relationships/in/{-list|&|types}'} as
a\"}"

I realise that these examples are a bit contrived but it shows there is
nothing available to determine the type of data returned for clients
without domain knowledge.

Could I suggest as a solution an extra key in the results showing the type
of the data returned, such as:

{
  "columns" : [ "a" ],
  *"types": ["Node"],*
  "data" : [ [ {
    "outgoing_relationships" : "
http://localhost:7474/db/data/node/4/relationships/out";,
    "labels" : "http://localhost:7474/db/data/node/4/labels";,
    "data" : {
    },
    "all_typed_relationships" : "
http://localhost:7474/db/data/node/4/relationships/all/{-list|&|types}",
    "traverse" : "http://localhost:7474/db/data/node/4/traverse/{returnType}
",
    "property" : "http://localhost:7474/db/data/node/4/properties/{key}";,
    "self" : "http://localhost:7474/db/data/node/4";,
    "outgoing_typed_relationships" : "
http://localhost:7474/db/data/node/4/relationships/out/{-list|&|types}",
    "properties" : "http://localhost:7474/db/data/node/4/properties";,
    "incoming_relationships" : "
http://localhost:7474/db/data/node/4/relationships/in";,
    "extensions" : {
    },
    "create_relationship" : "
http://localhost:7474/db/data/node/4/relationships";,
    "paged_traverse" : "
http://localhost:7474/db/data/node/4/paged/traverse/{returnType}{?pageSize,leaseTime}
",
    "all_relationships" : "
http://localhost:7474/db/data/node/4/relationships/all";,
    "incoming_typed_relationships" : "
http://localhost:7474/db/data/node/4/relationships/in/{-list|&|types}"
  } ] ]
}

I can post this details onto GitHub if required but wanted to open a
discussion on the mailing list first.

Cheers
Nige

-- 
You received this message because you are subscribed to the Google Groups 
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to