简体   繁体   English

从 GitHub API 聚合特定属性

[英]Aggregate specific properties from GitHub API

Instead of getting all properties, I just need to have certain.我不需要获得所有属性,而只需要确定。

This is what I am doing right now, but this way, I am getting a bunch of the properties I don't need:这就是我现在正在做的,但是这样,我得到了一堆我不需要的属性:

await fetch(
          "https://api.github.com/search/repositories?q=calculator&per_page=100&type=all&language=&sort=stargazers",
          {
            json: true,
          }
        ).then((res) => res.json())

I need to have only these properties: html_url, name, description, updated_at, stargazers_count, forks_count, id我只需要这些属性:html_url、名称、描述、updated_at、stargazers_count、forks_count、id

The GitHub REST API does not provide options for limiting your response, but the GraphQL API does. GitHub REST API 不提供限制您回复的选项,但 GraphQL API 提供。 In your case, your query would look like this:在您的情况下,您的查询将如下所示:

{
  search(query: "calculator", type: REPOSITORY, first: 100) {
    edges {
      node {
        __typename
        ... on Repository {
          id
          name
          url
          description
          updatedAt
          stargazerCount
          forkCount
        }
      }
    }
  }
}

You can try it in the explorer: https://docs.github.com/en/graphql/overview/explorer你可以在资源管理器中试试: https://docs.github.com/en/graphql/overview/explorer

Sample output:样本 output:

{
  "data": {
    "search": {
      "edges": [
        {
          "node": {
            "__typename": "Repository",
            "id": "MDEwOlJlcG9zaXRvcnkxNjgwMDg3OTc=",
            "name": "calculator",
            "url": "https://github.com/microsoft/calculator",
            "description": "Windows Calculator: A simple yet powerful calculator that ships with Windows",
            "updatedAt": "2023-01-19T16:35:31Z",
            "stargazerCount": 26550,
            "forkCount": 4820
          }
        }
      ]
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM