【问题标题】:How to fetch only public repositories from my Github account如何从我的 Github 帐户中仅获取公共存储库
【发布时间】:2020-01-21 01:20:36
【问题描述】:

所以我是 GraphQL 的新手,谁能告诉我如何将下面的代码更改为仅从我的帐户中检索公共回购?

我尝试使用“搜索”属性,但无法正常工作。

谢谢

  const {
    github: {
      repositoryOwner: {
        repositories: { edges },
      },
    },
  } = useStaticQuery(graphql`
    {
      github {
        repositoryOwner(login: "SzBor") {
          repositories(first: 6, orderBy: { field: CREATED_AT, direction: ASC }) {
            edges {
              node {
                id
                name
                url
                description
              }
            }
          }
        }
      }
    }
  `)

【问题讨论】:

  • 那么当你执行这个的时候,结果是什么?您收到什么错误(如果有)?

标签: graphql github-api


【解决方案1】:

您可以在repositories 上使用参数privacy: PUBLIC 例如:

  const {
    github: {
      repositoryOwner: {
        repositories: { edges },
      },
    },
  } = useStaticQuery(graphql`
    {
      github {
        repositoryOwner(login: "SzBor") {
          repositories(first: 6, privacy: PUBLIC, orderBy: { field: CREATED_AT, direction: ASC }) {
            edges {
              node {
                id
                name
                url
                description
              }
            }
          }
        }
      }
    }
  `)

奇怪的是 (API V4 document) 没有更新此信息,但您可以在 explorer 上进行测试:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-14
    • 2013-12-11
    • 1970-01-01
    • 2013-10-21
    • 2012-03-26
    • 2017-03-28
    • 2019-11-17
    • 2020-07-10
    相关资源
    最近更新 更多