代码之家  ›  专栏  ›  技术社区  ›  Eddy R.

Github Graphql过滤器问题(按里程碑)

  •  6
  • Eddy R.  · 技术社区  · 7 年前

    我正在努力学习Github的graphql api(同时学习graphql),试图让它在某个里程碑中列出所有问题。我不知道如何从API文档中做到这一点。

    我可以查询问题并查看它们的里程碑(对不起,名称已编辑):

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

    我希望有一种方式可以这样说 issues(milestoneID:"xyz") ,或者如果 Issue 将定义 MilestoneConnection

    我想我可以查询存储库中的所有问题,并对JSON响应进行后期处理,以过滤出我想要的里程碑,但是有没有更好的方法用github+graphql实现这一点?

    2 回复  |  直到 7 年前
        1
  •  6
  •   Bertrand Martel    7 年前

    您可以将搜索查询用于 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
            }
          }
        }
      }
    }
    
        2
  •  5
  •   bswinnerton    7 年前

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