{"id":15130231,"url":"https://github.com/huakunshen/github-graphql","last_synced_at":"2026-02-26T05:26:53.550Z","repository":{"id":253417835,"uuid":"843444317","full_name":"HuakunShen/github-graphql","owner":"HuakunShen","description":"GitHub GraphQL API TypeScript wrapper/sdk. Common queries and functions provided, e.g. star history, contribution.","archived":false,"fork":false,"pushed_at":"2025-04-02T20:51:42.000Z","size":325,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-02T21:28:06.239Z","etag":null,"topics":["api","github","graphql"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HuakunShen.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["HuakunShen"],"buy_me_a_coffee":"huakun"}},"created_at":"2024-08-16T14:26:43.000Z","updated_at":"2025-04-02T20:51:45.000Z","dependencies_parsed_at":"2025-03-08T19:26:31.461Z","dependency_job_id":"38507631-0d5c-4c10-b8bc-887f3632e181","html_url":"https://github.com/HuakunShen/github-graphql","commit_stats":null,"previous_names":["huakunshen/github-graphql"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HuakunShen%2Fgithub-graphql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HuakunShen%2Fgithub-graphql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HuakunShen%2Fgithub-graphql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HuakunShen%2Fgithub-graphql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HuakunShen","download_url":"https://codeload.github.com/HuakunShen/github-graphql/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247393540,"owners_count":20931809,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","github","graphql"],"created_at":"2024-09-26T02:42:36.113Z","updated_at":"2026-02-26T05:26:53.498Z","avatar_url":"https://github.com/HuakunShen.png","language":"TypeScript","funding_links":["https://github.com/sponsors/HuakunShen","https://buymeacoffee.com/huakun"],"categories":[],"sub_categories":[],"readme":"# github-graphql\n\n[![wakatime](https://wakatime.com/badge/user/94be0fbf-cb9d-411d-8526-d0c4a4e82e1a/project/4c1152fd-6dae-4734-8ee7-5b2a2a98ec71.svg)](https://wakatime.com/badge/user/94be0fbf-cb9d-411d-8526-d0c4a4e82e1a/project/4c1152fd-6dae-4734-8ee7-5b2a2a98ec71)\n[![JSR](https://jsr.io/badges/@hk/github-graphql)](https://jsr.io/@hk/github-graphql)\n[![NPM Version](https://img.shields.io/npm/v/github-graphql)](https://www.npmjs.com/package/github-graphql)\n[![CI Build \u0026 Test](https://github.com/HuakunShen/github-graphql/actions/workflows/ci.yml/badge.svg)](https://github.com/HuakunShen/github-graphql/actions/workflows/ci.yml)\n[![Generate and Deploy Docs](https://github.com/HuakunShen/github-graphql/actions/workflows/docs.yml/badge.svg)](https://github.com/HuakunShen/github-graphql/actions/workflows/docs.yml)\n\n## Documentation:\n\n- https://huakunshen.github.io/github-graphql/\n- https://jsr.io/@hk/github-graphql/doc\n\nThis project is a codegen wrapper around GitHub's GraphQL API, with some queries I needed for my own projects.\n\nAs rest API doesn't provide types, I prefer to use GraphQL for type safety and intellisense.\nI found myself duplicating this codegen setup in multiple projects, so I decided to extract it into a standalone package.\n\nIf you managed to find this project and think it's useful, feel free to use it in your own projects.\nIf you want to add some common queries you find yourself using, feel free to open a PR. Add the query files to `./src/operations` folder.\n\nIf the queries you need is very specific to your project, you can fork this project and modify it to your needs.\n\n## Installation\n\nSince the main purpose of this project is to get the benefits of types, I recommend using it with TypeScript and the package doesn't provide bundled JS files.\n\nThis package is published to both npm and jsr. The package name is slightly different on jsr as it requires a scoped package name.\n\n```bash\n# npm\nnpm install github-graphql\npnpm install github-graphql\n\n\n# check https://jsr.io/@hk/github-graphql for more info\n# JSR\npnpm dlx jsr add @hk/github-graphql\nnpx jsr add @hk/github-graphql\n```\n\n## Usage\n\nSample code is the best way to learn. Look at tests in [`__tests__`](./__tests__/) folder for examples. It's quite simple.\n\nNote that to use GitHub's GraphQL API, you need to provide a token.\n\nIf you install from jsr, make sure `@hk/github-graphql` is used as the package name.\n\nA star history example is provided at [`./examples/star-history`](./examples/star-history/README.md).\n\n```ts\n// If you install from npm\nimport { getSdk } from \"github-graphql/req\"\n\n// If you install from jsr\nimport { getSdk } from \"@hk/github-graphql/req\"\n```\n\nSee [operations](./src/operations/) folder for available queries.\n\n## Flavors\n\nThere are two flavors of this API. `graphql-request` and `@apollo/client`.\n\nYou can find sample code for both in the tests.\n\n### `graphql-request`\n\nExported under `/req` subpackage.\n\n```ts\nimport { GraphQLClient } from \"graphql-request\"\nimport { getSdk } from \"@hk/github-graphql/req\"\n\nconst client = new GraphQLClient(\"https://api.github.com/graphql\", {\n\theaders: {\n\t\tauthorization: `Bearer ${Bun.env.GITHUB_TOKEN}`,\n\t\t\"User-Agent\": \"github-graphql package\"\n\t}\n})\nconst sdk = getSdk(client)\n\nconst data = await sdk.Repository({\n\towner: \"tauri-apps\",\n\tname: \"tauri\"\n})\n\nexpect(data.data.repository?.stargazerCount).toBeGreaterThan(100)\n```\n\n### `@apollo/client`\n\n```ts\nimport { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"\nimport { DefaultGitHubContributionDocument } from \"@hk/github-graphql\"\n\nconst client = new ApolloClient({\n\tcache: new InMemoryCache(),\n\tlink: new HttpLink({\n\t\turi: \"https://api.github.com/graphql\",\n\t\theaders: {\n\t\t\tauthorization: `Bearer ${Bun.env.GITHUB_TOKEN}`,\n\t\t\t\"User-Agent\": \"github-graphql package\"\n\t\t}\n\t})\n})\n\nconst result = await client.query({\n\tquery: RepositoryDocument,\n\tvariables: {\n\t\towner: \"tauri-apps\",\n\t\tname: \"tauri\"\n\t}\n})\nconst stargazerCount = result.data.repository?.stargazerCount\n```\n\n## Development\n\nThis project is built with [Bun](https://bun.sh).\nNo Node or npm or pnpm is required to develop/build this project.\n\nTo build this project\n\nAdd GitHub Token to `.env` file\n\n```\nGITHUB_TOKEN=github_pat_xxx\n```\n\n```bash\nbun install\nbun run build\nbun run test\n```\n\nThis is a pure TypeScript project, no JS code will be generated.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuakunshen%2Fgithub-graphql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhuakunshen%2Fgithub-graphql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuakunshen%2Fgithub-graphql/lists"}