6

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?

Bertrand Martel
  • 42,756
  • 16
  • 135
  • 159
Eddy R.
  • 1,089
  • 7
  • 12

2 Answers2

6

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
        }
      }
    }
  }
}
Bertrand Martel
  • 42,756
  • 16
  • 135
  • 159
  • 2
    Awesome thanks! One thing to note: if the milestone name has spaces, you need to again escape the quotes around the name. If you're using curl, and already escaping the quotes around the query string, that would be a double escape... i.e. `query: \"... milestone: \\\"a name\\\" ...\"` – Eddy R. Sep 30 '17 at 23:23
5

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
            }
          }
        }
      }
    }
  }
}
bswinnerton
  • 4,533
  • 8
  • 41
  • 56