Finding connected components in graph

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.

1 Like

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

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?

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 Get started with Dgraph is already using pagination - “first:”.
The idea here is to obey Root’s rule and use other combinations in Get started with Dgraph

Cheers.

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