Hi all
Hoping for some help with a query, and a possible feature request.
I have a set of C# AST data stored in Dgraph. I haven’t been able to figure out a way to “find all methods that don’t have a for loop.”
I can “find all methods with a for loop” by finding all for loops, and recursing back to the method declaration like so:
{
recurse (func: eq(kind, "csharp.for_statement")){
method as ~child
}
method(func: uid(method)) {
@filter(eq(kind, "csharp.method_declaration"))
kind
identifier_token
}
}
I can also “find all for loops inside methods” by reversing reversing the variable assignment:
{
recurse (func: eq(kind, "csharp.method_declaration")){
for as child
}
for(func: uid(for)) {
@filter(eq(kind, "csharp.for_statement"))
kind
identifier_token
}
}
But I can’t get “methods without for loops”, or “for loops that aren’t in methods” with this method. What do you think is the best way to do it?
Just spitballing: might it be possible to express the whole query as a single block with a root of func: eq(kind, "csharp.method_declaration")
, put the recurse inside the block, and just use NOT
on the filter?
Something vaguely like this:
me(func: eq(kind, "csharp.method_declaration")) @cascade {
recurse () {
@filter(NOT eq(kind, "csharp.for_statement")
kind
child
}
}