Get Active Branches w/ v4

I’m using the v4 GraphQL API and I’m looking for a way to fetch all active branches in a repo (pretty much the same list as “Active branches” when you visit the “Branches” page of a repo).

I have something like this so far (barely nothing):

{
  repository(owner: "...", name: "...") {
    refs(last: 10, refPrefix: "refs/heads/") {
      nodes {
        name
        target {
          ... on Commit {
            committedDate
            authoredDate
            pushedDate
            author {
              user {
                login
              }
            }
          }
        }
      }
    }
  }
}

I’m not even sure if I’m heading in the right direction, but the specific questions I have are:

  • How can I filter this down to only show branches that have a committedDate within the last month?

  • How can I sort the refs list by a child/nested property? Specifically the committedDate

Thank you

GraphQL doesn’t provide any sorting or filtering within the query language itself. If the API you’re interacting with via GraphQL doesn’t provide those features, then you have to use GraphQL to query the data and then sort and filter it yourself locally.

I hope that helps!