trustfall
trustfall copied to clipboard
Stop @recurse with internal filter
Hello! I'm trying to use trustfall to query my filesystem and find directories/files with certain properties (in this case, folders whose name is "target"). To do this right now I am defining an "input directory" that defines where the tool should begin to find these files, and then the query recurses until it finds the folder it wants. However, I'd like to stop the recursion when it finds that folder, e.g. output /target/ but not /target/target/. How can I do that? Here's my query as of right now:
{
InputDirectory {
... on Directory {
entries @recurse(depth:10) {
... on Directory {
name @filter(op: "=", value: ["$target"])
path @output
}
}
}
}
}
Thanks!
Unfortunately the query language currently doesn't have a way to do this. It's a feature I'd love to add in the future though!
In the meantime, you could work around this by defining a custom edge that implements the "recurse but stop on match" behavior:
{
InputDirectory {
... on Directory {
first_matching_directory(name: "target") {
< rest of query here >
}
}
}
}
Parameterized edges currently cannot use query variables like $target
so as a workaround for that you'll need to pass a string literal for the name.
This "build it into the schema" trick is the standard workaround for all sorts of missing query functionality right now.