That is brilliant and simple and shows that when Graph Databases were a big thing they probably should have used Prolog as a front end.