Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github Graphql Filter issues by Milestone

I'm wrestling with Github's graphql api (while learning graphql) trying to get it to list all issues in a certain milestone. I can't figure out how to do that from the API docs.

I can query issues and see what milestone they're in (sorry, names redacted):

query {
    repository(owner:"me", name:"repo") {
        issues(last:10) {
            nodes {
                milestone {
                    id
                    title
                }
            }
         }
    }
}

I wish there was a way to say something like issues(milestoneID:"xyz"), or perhaps if Issue would define a MilestoneConnection (doesn't appear to exist).

In my reading / learning about GraphQL thus far, I haven't found a way to build arbitrary filters of fields if an explicit parameter is not defined in the schema (am I right about that?).

I guess I can query all of issues in the repository and post-process the JSON response to filter out the milestone I want, but is there a better way to do this with github + graphql?

like image 282
Eddy R. Avatar asked Sep 29 '17 23:09

Eddy R.


2 Answers

You can use a search query with milestone filter :

{
  search(first: 100, type: ISSUE, query: "user:callemall repo:material-ui milestone:v1.0.0-prerelease state:open") {
    issueCount
    pageInfo {
      hasNextPage
      endCursor
    }
    edges {
      node {
        ... on Issue {
          createdAt
          title
          url
        }
      }
    }
  }
}
like image 152
Bertrand Martel Avatar answered Sep 22 '22 19:09

Bertrand Martel


GitHub recently added the ability to see all issues that are associated with a given milestone. You should be able to fetch it with a query similar to:

query($id:ID!) {
  node(id:$id) {
    ... on Milestone {
      issues(last:10) {
        edges {
          node {
            title
            author {
              login
            }
          }
        }
      }
    }
  }
}

Or if you don't know the node ID, you could do something like:

query($owner:String!,$name:String!,$milestoneNumber:Int!) {
  repository(owner:$owner,name:$name) {
    milestone(number:$milestoneNumber) {
      issues(last:10) {
        edges {
          node {
            title
            author {
              login
            }
          }
        }
      }
    }
  }
}
like image 31
bswinnerton Avatar answered Sep 24 '22 19:09

bswinnerton