githubgraphqlgithub-graphql

Does GitHub's GraphQL API support filtering files/trees by basic things like name?


I'm using GitHub's GraphQL API to retrieve the directories and files within a repository, but I only need some specific subsets.

The repository I'm working with has a structure like:

 - / #root
 - /.gitignore
 - /.github/...
 - /categoryOne
 - /categoryOne/itemOne
 - /categoryOne/itemOne/config.ini
 - /categoryTwo
 - /categoryTwo/itemOne
 - /categoryTwo/itemOne/config.ini
 - /categoryTwo/itemOne/maybe_some_junk/...
 ...

I'm trying to efficiently query the (category)->(item)->(config) nodes, and have been able to do that, but so far haven't found a way to omit the "junk" items (like the .gitignore file and .github tree).

Here's my crude-but-working query.

query Repository {
    repository(name: "my-repository", owner: "example") {
        object(expression: "HEAD:") {
            ... on Tree {
                categories: entries {
                    mode
                    name
                    type
                    object {
                        ... on Tree {
                            items: entries {
                                name
                                type
                                configFile: object {
                                    ... on Blob {
                                        text
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }   
    }
}

That runs fine, but includes quite a few results I'd like to filter out. I've tried adding (where: {...}) clauses to various lines, and all have indicated that isn't syntactically correct.

Does Github's GraphQL API support filtering out some of the Blobs/Trees when querying the Repository Objects? If so, what operation/syntax is needed?


Solution

  • After learning more about GraphQL (I should have mentioned I'm very new to it) I've learned that the operations and abilities are very specific to each API's implementation--the information I'd found suggesting a where: ability doesn't apply to GitHub's API.

    Further reviewing the GitHub GraphQL schema and documenation I'm now confident it's not possible to do the filtering server-side. I'll need my client code to understand the query result is a list of "candidates", and it will need to filter accordingly.