Github Graphql Filter issues by Milestone

穿精又带淫゛_ 提交于 2020-07-18 05:11:38

问题


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?


回答1:


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
            }
          }
        }
      }
    }
  }
}



回答2:


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
        }
      }
    }
  }
}


来源:https://stackoverflow.com/questions/46498143/github-graphql-filter-issues-by-milestone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!