Search code examples
pythonneo4jbulbs

How to enter a neo4j Cypher query using Bulbs?


I know the greatest utility of Bulbs is that it lets you use an object graph mapper, but if I wanted to also include an already-written cypher query, how can I enter that directly through this API? Looking through the documentation of the project, I found this section:

http://bulbflow.com/docs/api/bulbs/neo4jserver/cypher/

...but the syntax of how to enter the query or what the return values were seemed a little unclear to me.


Solution

  • Here's an example:

    inrels = graph.cypher.query('START strt=node({mynode}) \
                                MATCH strt<-[r:follows]-neighbor \
                                WHERE neighbor.attr = {myattr} \
                                RETURN r', {'mynode': self.eid, 'myattr': someattr})
    
    firstrel = inrel.next()
    

    If you return a single column with nodes or rels, those would automatically be inflated to bulb objects. There used to be a graph.cypher.table() for generic return values in multi-column layout, based on your link I'm not sure this still exists.