How to validate an update cypher query against a schema?

35 views
Skip to first unread message

Yash Sharma

unread,
May 30, 2017, 7:56:33 PM5/30/17
to Neo4j

I have a neo4j database and I want it to conform to a predefined schema (model).

This schema has some constraints like a node with label x should  be related to a node with label y with relation type r only. No other relationship type between x and y is allowed. For example, only nodes labeled :Person can be at the two ends of a :friend_of relationship, but a node with label :Object cannot be at any end of the :friend_of relationship. Another constraint can be what type of properties are allowed on a node having a particular label or a relationship of a particular type. For example a node with label :Person can only have properties name and age. No other property is allowed.


So I want to create a method which takes input an update cypher query and checks if it updates the database as per the existing schema or not. Assume that the schema exists in JSON or XML format. Can someone guide me how can I go about solving the problem? Should I perhaps parse the query using CypherParser and then do something?

Clark Richey

unread,
May 30, 2017, 8:48:41 PM5/30/17
to ne...@googlegroups.com
This is quite challenging to implement. That being said we have implemented this in our application (http://factgem.com) and would be happy to discuss with you directly. 

Sent from my iPhone
--
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 neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Hunger

unread,
May 30, 2017, 8:48:49 PM5/30/17
to ne...@googlegroups.com
In general Neo4j is a schema free database so it's strength is in many other areas.

Best would be to use a query generator/DSL that adhere's to the schema.

You can look into the work on ontologies by my colleague Jesus: https://jesusbarrasa.wordpress.com/2016/04/06/building-a-semantic-graph-in-neo4j/

You can use existence constraints for properties, there are currently none for cardinalities.

And if you run a cypher query with explain you will get warnings about unused labels, rel-types and properties.

You can also checkout our neo4j.com/developer/graphql work, which uses graphql-schema and then generates queries and mutations from that.

Alan Robertson

unread,
May 31, 2017, 9:51:35 AM5/31/17
to Clark Richey, ne...@googlegroups.com
In general, this is very hard indeed. You have to not only know the labels of existing nodes, but the meaning of the Cypher query. Although Cypher isn't likely Turing-complete, it is nearly certain that there are legal queries that you can't  easily (or at all) prove are legal. This is equivalent to the question of "What does this program do?" - which is known to be impossible to answer for Turing-complete languages.

Michael's suggestion of a query generator which only generates updates which conform to the schema is likely your best bet.

--
  Alan Robertson

Reply all
Reply to author
Forward
0 new messages