0

Iam trying to execute a CypherQuery after forming a string and passing it on to the ExecuteCypherResults API of Neo4jClient. I have attempted this because of a need to dynamically create nodes and appropriate labels. Paramter Substituion is not applicable for labels and hence I formed a cypher query string and tried to execute.

 String qry=""; 
 qry="Create n:Person"; 
 GraphClient client=new GraphClient(new Uri("localhost:7474/db/data")); 
 client.Connect(); 
 var results = ((IRawGraphClient)client).ExecuteGetCypherResults(new CypherQuery(qry,null, Neo4jClient.Cypher.CypherResultMode.Projection)); 

When executing I get the following error : Compiler Error Message: CS0411: The type arguments for method 'Neo4jClient.IRawGraphClient.ExecuteGetCypherResults(Neo4jClient.Cypher‌​.CypherQuery)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

Any help in this regard will be great..

1 Answer 1

2

Firstly, it's my opinion that needing to dynamically assign labels is not a reason to avoid using the Neo4jClient fluent API and other helpers. If you're careful, you can dynamically build/format just the label portion of your Cypher without exposing your code to possible injection vulnerabilities.

To address your question more specifically, however, I think there are two main problems with the code above:

  1. Your Cypher syntax is wrong due to missing parentheses, and the CREATE statement doesn't return any results without a RETURN clause. You should change the Cypher syntax to something like CREATE (n:Person) RETURN n if that's what you want.
  2. The ExecuteGetCypherResults method requires a generic type parameter indicating the type of the results that you're returning. Rather than trying to guess at the properties of the node you're trying to create above, I'll simply refer you to the relevant tests in the Neo4jClient source for examples on how to use this method. Your method call will need to look something more like ExecuteGetCypherResults<Person>(...), where Person is a suitable type.

Finally, I'll just return to the original point again for emphasis - as the author of Neo4jClient says, this approach is highly discouraged. If you really insist on heading this way for some reason, I'd recommend that you'd be better off completely throwing away Neo4jClient and building your own wrapper around the Neo4j server REST API yourself, because you're going to be fighting against the way the Neo4jClient software is designed to work, while simultaneously failing to gain any benefits from it at all.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot Pat for your Advice. This was just one instance in the whole solution where this need came up. I have been using extensively Neo4jclient and fully appreciate its architecture and value prop. Exception being Exception, Neo4JClient already offered an API for handling this exception, and I tried to get help from the community to use it. Thanks again for your help and advice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.