プログラミング

GitHub GraphQLでデータベースを検索する

GithubのGraphQL APIを使用してGithubを検索、データベースからリポジトリのリストのデータを取得します。

https://yuis.xsrv.jp/images/ss/ShareX_ScreenShot_94c60be3-e817-4106-81e9-0cb25ac287c9.png

(GitHub GraphQLの例)

{
  search(query: "beef", type: REPOSITORY, first: 10) {
    repositoryCount
    edges {
      node {
        ... on Repository {
          name
          description
          stargazerCount
          url
          createdAt
          updatedAt
          primaryLanguage {
            name
          }
        }
      }
    }
  }
}

(出力例)

クエリからjsonデータが出力されます。

{
  "data": {
    "search": {
      "repositoryCount": 1838,
      "edges": [
        {
          "node": {
            "name": "beef",
            "description": "The Browser Exploitation Framework Project",
            "stargazerCount": 5558,
            "url": "https://github.com/beefproject/beef",
            "createdAt": "2011-11-23T06:53:25Z",
            "updatedAt": "2021-03-07T16:56:54Z",
            "primaryLanguage": {
              "name": "JavaScript"
            }
          }
        },
        {
          "node": {
            "name": "BeeFramework",
            "description": "[Experimental] A semi-hybrid framework that allows you to create mobile apps using Objective-C and XML/CSS",
            "stargazerCount": 3378,
            "url": "https://github.com/gavinkwoe/BeeFramework",
            "createdAt": "2012-08-28T08:29:24Z",
            "updatedAt": "2021-03-02T02:26:59Z",
            "primaryLanguage": {
              "name": "Objective-C"
            }
          }
        },
        {
          "node": {
            "name": "Beef",
            "description": "Beef Programming Language",
            "stargazerCount": 1739,
            "url": "https://github.com/beefytech/Beef",
            "createdAt": "2019-08-20T15:43:32Z",
            "updatedAt": "2021-03-07T17:11:42Z",
            "primaryLanguage": {
              "name": "C++"
            }
          }
        }
      ]
    }
  }
}