Last time we found that writing the query that told us which items to gather from the world to build any given item was between tricky and impossible to express in one Cypher query without some application code.
We outlined an algorithm that used a simulated shopping list to keep track of what we needed to run for each Recipe in the tree.
Let’s try it out then – our previous Cypher query told us that we needed 1x Wood to build a Wood Axe but that was wrong, so how does the new algorithm work out?
That’s looking tidier, we need 2x Wood.
How about producing a Carrot on a Stick?
We can see from the indentation in both shots how each Recipe ends up running other Recipes recursively until we finally hit resources that have no Recipe – raw materials.
We’re not going to go any further with this application – we’ve tried a few things out, explored how far we can push Cypher for our use case and pulled together a quick Node app to talk to the database to do the heavy-lifting when we couldn’t manage in Cypher.
Next time we’ll do a quick retrospective on the project to wrap things up.