0

我正在尝试在 Githubs GraphQL api 上运行以下查询:

{
  user(login: "davekaj") {
    id
    repositories(first: 10, orderBy: {field: NAME, direction: ASC}) {
      nodes {
        ref(qualifiedName: "master") {
          target {
            ... on Commit {
              history(first: 15, author: "WHAT DO I PUT HERE") {
                totalCount
                nodes {
                  additions
                  author {
                    name
                    user {
                      id
                    }
                  }
                  committedDate
                  deletions
                }
              }
            }
          }
        }
      }
    }
  }
}

它要我过滤一个CommitAuthorfor history(author: )。我尝试传递我的用户名或我的唯一用户 ID,但它不起作用。我本质上是在传递一个字符串,但它需要 type CommitAuthor。我如何传递一个CommitAuthor值?

我不清楚,我搜索了文档和架构,但找不到任何东西。

请帮忙!

4

1 回答 1

1

啊,所以一旦我查看了 graphql 文档(而不仅仅是 github 文档),答案实际上非常简单。CommitAuthor是一种输入类型,此处描述为https://graphql.org/graphql-js/mutations-and-input-types/

结果是你传递了一个CommitAuthor. 在这种情况下,我只需要传递 id,如下所示:author: {id: "MDQ6VXNlcjIyNDE3Mzgy"}

请参阅下面的完整代码。

{
  user(login: "davekaj") {
    id
    repositories(first: 10, orderBy: {field: NAME, direction: ASC}) {
      nodes {
        ref(qualifiedName: "master") {
          target {
            ... on Commit {
              history(first: 15, author: {id: "MDQ6VXNlcjIyNDE3Mzgy"}) {
                totalCount
                nodes {
                  additions
                  author {
                    name
                    user {
                      id
                    }
                  }
                  committedDate
                  deletions
                }
              }
            }
          }
        }
      }
    }
  }
}
于 2020-01-15T14:03:09.733 回答