neoxygen / neo4j-neoclient

Simple PHP HttpClient for the Neo4j ReST API with Multi DB Support
MIT License
121 stars 138 forks source link

Best way to check create query response #30

Closed mehmetbilgin closed 9 years ago

mehmetbilgin commented 9 years ago

Hi Christophe, thanks for this library and keeping it up-to date with recent Neo4j updates.

I have one question regarding create queries. What is the best method to check whether query is successful or not. For example if there is an user with username=mehmet, first query will be successful but the second one will fail.

MATCH (user:User {username:'mehmet' }) CREATE (book:Book { title:'hobbit' }) CREATE (user)-[:READ]->(book)

MATCH (user:User {username:'invalid' }) CREATE (book:Book { title:'hobbit' }) CREATE (user)-[:READ]->(book)

When I check the sendCypherQuery() response I can't see any difference for these queries.

Of course I can add a return clause like "RETURN book.title" to the query and check its existence in the response to check result but I wanted to check whether is there a better method.

ikwattro commented 9 years ago

Hello @mehmetbilgin ,

Thanks for using the library.

The second query will not fail, simply because Neo4j will not return you an error and the transaction will be ok.

If you try the same query in the neo4j browser you can see just that the query will return a 200 result and just return you no data (in fact there are no schema violations, syntax errors or anything else that can make fail the query) It is how Cypher behaves, if he matches nothing he will just not execute the creates.

So yes, sendCypherQuery will behave the same in the two cases.

If you need to be sure that the query has executed changes to the graph, you may in this case like you said return the username or one of the book titles.

mehmetbilgin commented 9 years ago

Got it thanks.