Filter repositories on child field


#1

I want all my repos that have forks. Is that a thing? I don’t mean repos that ARE forks (there’s an isFork condition for that), but repos that HAVE forks.

Is there a way to filter a parent (repo) on a child field (edges.node.forks.totalCount)?

Something like:

query {
  viewer {
    repositories(first: 20, edges.node.forks.totalCount > 0) {
      totalCount
      edges {
        node {
          name
        }
      }
    }
  }
}

Is there even a way to condition with gt and lt ?

I can’t find any advanced GraphQL syntax on graphql.org or dev.github.


#3

I want all my repos that have forks. Is that a thing? I don’t mean repos that ARE forks (there’s an isFork condition for that), but repos that HAVE forks.

Yup, we have a forks connection on the Repository type! You can get a list of a repo’s forks using something like this:

query {
  node(id: "MDEwOlJlcG9zaXRvcnk4NDM5MTQ3") {
    ... on Repository {
      forks {
        totalCount
        edges {
          node {
            owner {
              login
            }
          }
        }
      }
    }
  }
}

Is there even a way to condition with gt and lt ?

I can’t find any advanced GraphQL syntax on graphql.org or dev.github.

Unfortunately, there’s no such syntax supported by GraphQL. It’s the sort of thing we could get around in, say, a String used as a query/search. This may be something we look into for the search functionality of the GraphQL API.


List repositories filtered by owner and repo name