Github Graphql过滤Milestone的问题

问题描述 投票:5回答:2

我正在与Github的graphql api(同时学习graphql)进行摔跤,试图让它列出某个里程碑中的所有问题。我无法弄清楚如何从API文档中做到这一点。

我可以查询问题并查看他们所处的里程碑(抱歉,名称已编辑):

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

我希望有一种方法可以说像issues(milestoneID:"xyz"),或者如果Issue定义一个MilestoneConnection(似乎不存在)。

到目前为止,在我阅读/学习GraphQL时,如果未在模式中定义显式参数,我还没有找到构建任意字段过滤器的方法(我是否正确?)。

我想我可以查询存储库中的所有问题并对JSON响应进行后处理以过滤掉我想要的里程碑,但有没有更好的方法来使用github + graphql?

github graphql github-api github-graphql
2个回答
5
投票

GitHub最近添加了查看与给定里程碑相关的所有问题的功能。您应该可以使用类似于以下的查询来获取它:

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

或者,如果您不知道节点ID,您可以执行以下操作:

query($owner:String!,$name:String!,$milestoneNumber:Int!) {
  repository(owner:$owner,name:$name) {
    milestone(number:$milestoneNumber) {
      issues(last:10) {
        edges {
          node {
            title
            author {
              login
            }
          }
        }
      }
    }
  }
}

5
投票

您可以使用milestone过滤器的搜索查询:

{
  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
        }
      }
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.