Stop recurse query when it traverses enough nodes

What I want to do

The problem I’m working on requires finding connected components in a graph. In our dataset, the components can get very big, so before we reach a size where queries become slow / eat all of our RAM, we’d like to ignore the large components (or at least limit how many total nodes our @recurse query can return).

Limiting the query by means of specifying depth or taking the first n edges in a query don’t solve my problem properly, since there’s no way to practically / meaningfully limit how large the components can be.

What I did

Tried controlling query size by changing the depth parameter and limiting on edges, but these two don’t meaningfully allow me to stop traversing the graph when I find a connected component that’s too big.

My current query looks something like this:

{
    q(func: eq(id, "555")) @recurse(loop: false, depth: 5) {
		uid
		phone_number
		~phone_number (first: 5)
		email
		~email (first: 5)
	}
}

but I’d like to be able to stop the recursion when it hits some limit (e.g. 100 nodes). Maybe something like this (which I understand isn’t currently possible):

{
    q(func: eq(id, "555")) @recurse(loop: false, first: 100) {
		uid
		phone_number
		~phone_number 
		email
		~email 
	}
}

Dgraph metadata

Dgraph version : v20.11.3 Dgraph codename : tchalla-3 Dgraph SHA-256 : c3c1474369415e74b1a59ec7053cd1e585c9d55fe71243c72c48e313728d995a Commit SHA-1 : 8d3eb766c Commit timestamp : 2021-03-31 17:28:12 +0530 Branch : HEAD Go version : go1.15.5 jemalloc enabled : true

There is a flag to the alpha servers called --limit 'query-edge=X' which applies to recursion queries, maybe that will suit your needs?

(That is the v21.03.x form of that flag but consult the docs for your version)