Finding connected components in graph


(Thej Kamal Rao Menneni) #1

How do you query dgraph to get all connected sub graphs in graph?

Lets say we have 100 nodes in dgraph and there are 5 connected components, each with 20 nodes. I want to retrieve all such connected components.

At high level, I might not need to retrieve all properties of nodes or edges, just to show 5 clusters with number of nodes in each cluster.


(Michel Conrado) #2

I guess Recurse Query can help https://docs.dgraph.io/query-language/#recurse-query


(Thej Kamal Rao Menneni) #3

Thank for the response @MichelDiz. It took me some time to understand recurse query syntax.

I get following error message when I do recurse query “Failed to fetch: Could not connect to the server”

can you provide an example with recurse and pagination?


(Michel Conrado) #4

I do not believe this error is related to the recursive query. This is a technical problem. Check your settings and status of the instances.

You may have a group of Nodes with limited resources. And at the same time you’re doing the recursive query Dgraph maybe is doing other routine activities. And this can lead to some connection problem. But this is an assumption of a hypothetical situation, as I do not know the details of its context.

This is possible, but it is not controllable. You will not always have a desired result.
Ideally, paging should take place in Root in that case. If you use paging in the body of the recursive query it can get very confusing and out of control. Paging does not quite mix with recursive query.

In fact the example in https://docs.dgraph.io/query-language/#recurse-query is already using pagination - “first:”.
The idea here is to obey Root’s rule and use other combinations in https://docs.dgraph.io/query-language/#pagination

Cheers.


(system) closed #5

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.