Search code examples
memgraphdb

How to use BSF within GQLAlchemy?


I know how to use BSF in Cypher but I can't find anything on using BSF within GQLAlchemy. I've found BreadthFirstSearch Objects but I'm lacking some example. If you've used it, can you share part of the code with me?


Solution

  • Take a look at code from test example. I think that it should be a good starting point.

    def test_bfs():
        bfs_alg = BreadthFirstSearch()
    
        query_builder = (
            QueryBuilder()
            .match()
            .node(labels="City", name="Zagreb")
            .to(relationship_type="Road", algorithm=bfs_alg)
            .node(labels="City", name="Paris")
            .return_()
        )
        expected_query = " MATCH (:City {name: 'Zagreb'})-[:Road *BFS]->(:City {name: 'Paris'}) RETURN * "
    
        with patch.object(Memgraph, "execute_and_fetch", return_value=None) as mock:
            query_builder.execute()
    
        mock.assert_called_with(expected_query)