How to efficiently find shortest and longest paths between node types in Dgraph (similar to APOC in Neo4j)?

As you’re acutely aware, the shortest function only operates on uids…

Since you’re using Python, you may want to check out the extract_dict function in pydgraph. It was built specifically for converting DQL query results to a dict representing nodes and a list representing edges. Function: link. Test: link

Once you have those two artifacts, you can use them in networkx or any other graph algo package you like to accomplish your objectives.

Here’s a notebook that uses a locally defined extract_dict (it was later moved to pydgraph) and moves the results into networkx and then performs a number of graph analyses on the data.