Avoid recursive node expansion if facet/edge count is greater than

Is it possible to make a recursive query, which stops at/avoids expanding a node, if count of edges/facets is greater than x? But keep the node itself.

node (func: eq(id, "SOME_ID")) @recurse(depth: 5) {
  name
  connections @filter(lt(count(connections), 10))
}

The above query has the problem, that it exclude the node which has more than 10 connections. What I would like to achieve is to get the node it-self (with more than 10 connections), but not expand the connections.

It should be something like this

node (func: eq(id, "SOME_ID")) @recurse(depth: 5) {
  name
  connections @filter(lt(count(connections), 10)) @facets(gt(myfacet, 10))
}

@MichelDiz I don’t think it works. And what exactly does @facets(gt(myfacet, 10)) refer to? See below.

Lets assume the following data:

{
  "name": "A",
  "connections": [
    {
      "name": "B",
      "connections": [{ "name": "C" }, { "name": "D" }, { "name": "E" }]
    }
  ]
}

And the query:

node (func: eq(name, "A")) @recurse(depth: 5) {
  name
  connections @filter(lt(count(connections), 3))
}

It would give a result like:

{
  "name": "A",
  "connections": []
}

And I would like it to be

{
  "name": "A",
  "connections": [
    { "name": "B" }
  ]
}

In other words, node B should be part of the result, but the connections of B should be omitted and not expanded.

You have mentioned in your title “Avoid recursive node expansion if facet/edge count is greater than” - So I thought you knew about how facets works and wanted to use it.

Instead of using recurse, in your case, you should have a fixed query.

node (func: eq(name, "A")) @cascade {
  name
  connections { 
   name
   connections @filter(lt(count(connections), 3))
  }
}

The problem with recurse is that you can’t control it. It works as a block template and it is replicated recursively. So, what you wanna do isn’t possible via recurse query.

I do know about facets :slight_smile: - I simply reduced my example to a bare minimum, and was curios as to if the @facets would change the behaviour.

The problem with a fixed query in my case, is that I don’t know if the excessive amount of connections will happen at depth 1 or depth 5. And basically what I wanted to achieve was to make the recursive “cut” on the actual edges and not the node which is caught by the filter. But I understand it isn’t possible.