Search code examples
neo4jneo4jclient

Neo4j Create Unique using params to create nodes using WithParams


I've originally posted here http://hg.readify.net/neo4jclient/issue/122/createunique-withparam-object


I'm running neo4j 1.9.1 with neo4jclient 1.0.0.590

Following on from this issue http://hg.readify.net/neo4jclient/issue/66/support-custom-parameters-in-cypher-fluent

I'm trying to reuse that syntax to createunique a relationship and a node with properties

var docoType = new DocumentationType() {DocumentationTypeId = message.DocumentationTypeId, Description = message.DocumentationTypeDescription};

_connectedClient.Cypher
    .Start(new {docType = docTypeCategory})
    .CreateUnique("docType-[r:{ISDOCTYPERELAT]}->(newDocType {possiblyNewDocoType})")
    .WithParam("ISDOCTYPERELAT", IsDocumentationType.TypeKey)
    .WithParam("possiblyNewDocoType", docoType)
    .Return<Node<DocumentationType>>("newDocType");

_log.Info(JsonConvert.SerializeObject(createDocType.Query));

here are some results from fiddler when i ask for the results

POST

{
"query" : "START docType=node({p0})\r\nCREATE UNIQUE (docType) - [r:{ISDOCTYPERELAT}]-> (newDocType {possiblyNewDocoType})\r\nRETURN newDocType",
"params" : {
    "p0" : 538,
    "ISDOCTYPERELAT" : "DOCTYPES",
    "possiblyNewDocoType" : {
        "DocumentationTypeId" : "USERADMINISTRATION",
        "Description" : "User Administration"
    }
}

}

RESPONSE

{
"message" : "string matching regex ``(``|[^`])*`' expected but `{' found\n\nThink we should have better error message here? Help us by sending this query to cypher@neo4j.org.\n\nThank you, the Neo4j Team.\n\n\"CREATE UNIQUE (docType) - [r:{ISDOCTYPERELAT}]-> (newDocType {possiblyNewDocoType})\r\"\n                              ^",
"exception" : "SyntaxException",
"fullname" : "org.neo4j.cypher.SyntaxException",
"stacktrace" : ["org.neo4j.cypher.internal.parser.v1_9.CypherParserImpl.parse(CypherParserImpl.scala:47)", "org.neo4j.cypher.CypherParser.parse(CypherParser.scala:44)", "org.neo4j.cypher.ExecutionEngine$$anonfun$prepare$1.apply(ExecutionEngine.scala:80)", "org.neo4j.cypher.ExecutionEngine$$anonfun$prepare$1.apply(ExecutionEngine.scala:80)", "org.neo4j.cypher.internal.LRUCache$LazyValue.value$lzycompute(LRUCache.scala:27)", "org.neo4j.cypher.internal.LRUCache$LazyValue.value(LRUCache.scala:27)", "org.neo4j.cypher.internal.LRUCache.getOrElseUpdate(LRUCache.scala:39)", "org.neo4j.cypher.ExecutionEngine.prepare(ExecutionEngine.scala:80)", "org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:72)", "org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:76)", "org.neo4j.cypher.javacompat.ExecutionEngine.execute(ExecutionEngine.java:79)", "org.neo4j.server.rest.web.CypherService.cypher(CypherService.java:94)", "java.lang.reflect.Method.invoke(Method.java:606)", "org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112)"]

}

I've manually taken the querytext and removed the key quotes and had it run succesfully

//THIS WORKS
START docType=node(538)
CREATE UNIQUE docType-[r:DOCTYPES]->(newDocType {
DocumentationTypeId : "USERADMINISTRATION",
Description : "User Administration"
})
RETURN newDocType

Am I doing something wrong here?

Thanks!


Solution

  • Solved my problem!

    i was parameterising the relationship, which is supposedly a big no no.

    this c# query worked

    var createDocType = _connectedClient.Cypher
    .Start(new {docType = docTypeCategory})
    .CreateUnique("(docType) - [r:"+ IsDocumentationType.TypeKey+ "]-> (newDocType {possiblyNewDocoType})")                                                
    .WithParam("possiblyNewDocoType", docoType)
    .Return<Node<DocumentationType>>("newDocType");
    

    ```