Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop @recurse with internal filter #303

Open
aleokdev opened this issue Jun 4, 2023 · 1 comment
Open

Stop @recurse with internal filter #303

aleokdev opened this issue Jun 4, 2023 · 1 comment
Labels
A-syntax Area: query or schema syntax C-feature-request Category: request for new future functionality E-hard Call for participation: experience needed to fix: hard / a lot.

Comments

@aleokdev
Copy link

aleokdev commented Jun 4, 2023

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!

@obi1kenobi
Copy link
Owner

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.

@obi1kenobi obi1kenobi added A-syntax Area: query or schema syntax C-feature-request Category: request for new future functionality E-hard Call for participation: experience needed to fix: hard / a lot. labels Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-syntax Area: query or schema syntax C-feature-request Category: request for new future functionality E-hard Call for participation: experience needed to fix: hard / a lot.
Projects
None yet
Development

No branches or pull requests

2 participants