├── .github ├── ISSUE_TEMPLATE │ ├── bug.yml │ ├── documentation.yml │ ├── feature.yml │ └── maintenance.yml ├── pull_request_template.md ├── renovate.json └── workflows │ ├── add_to_octokit_project.yml │ ├── codeql-analysis.yml │ ├── immediate-response.yml │ ├── release.yml │ ├── test.yml │ ├── update-graphql-codegen.yml │ ├── update-prettier.yml │ └── update.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── SECURITY.md ├── bin └── download.js ├── index.d.ts ├── index.js ├── lib └── validate.js ├── package-lock.json ├── package.json ├── schema.d.ts ├── schema.graphql ├── schema.json └── test ├── index.js ├── smoke.js ├── typescript-validate.ts └── validate.js /.github/ISSUE_TEMPLATE/bug.yml: -------------------------------------------------------------------------------- 1 | name: Bug 2 | description: File a bug report 3 | title: "[BUG]: " 4 | labels: ["Type: Bug", "Status: Triage"] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | Thanks for taking the time to fill out this bug report! 10 | - type: textarea 11 | id: what-happened 12 | attributes: 13 | label: What happened? 14 | description: What did you do? What happened? What did you expect to happen? 15 | placeholder: Put your description of the bug here. 16 | validations: 17 | required: true 18 | - type: textarea 19 | id: versions 20 | attributes: 21 | label: Versions 22 | description: What versions of the relevant software are you running? 23 | placeholder: Octokit.js v2.0.10, Node v16.18.0 24 | validations: 25 | required: true 26 | - type: textarea 27 | id: logs 28 | attributes: 29 | label: Relevant log output 30 | description: | 31 | Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks. 32 | Please check your logs before submission to ensure sensitive information is redacted. 33 | render: shell 34 | - type: checkboxes 35 | id: terms 36 | attributes: 37 | label: Code of Conduct 38 | description: By submitting this issue, you agree to follow our [Code of Conduct](CODE_OF_CONDUCT.md) 39 | options: 40 | - label: I agree to follow this project's Code of Conduct 41 | required: true 42 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/documentation.yml: -------------------------------------------------------------------------------- 1 | name: Documentation 2 | description: Update or add documentation 3 | title: "[DOCS]: " 4 | labels: ["Type: Documentation", "Status: Triage"] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | Thanks for taking the time to fill this out! 10 | - type: textarea 11 | id: describe-need 12 | attributes: 13 | label: Describe the need 14 | description: What do you wish was different about our docs? 15 | placeholder: Describe the need for documentation updates here. 16 | validations: 17 | required: true 18 | - type: input 19 | id: sdk_version 20 | attributes: 21 | label: SDK Version 22 | description: Do these docs apply to a specific SDK version? 23 | placeholder: Octokit.NET v4.0.1 24 | validations: 25 | required: false 26 | - type: input 27 | id: api_version 28 | attributes: 29 | label: API Version 30 | description: Do these docs apply to a specific version of the GitHub REST API or GraphQL API? 31 | placeholder: ex. v1.1.1 32 | validations: 33 | required: false 34 | - type: textarea 35 | id: logs 36 | attributes: 37 | label: Relevant log output 38 | description: | 39 | Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks. 40 | Please check your logs before submission to ensure sensitive information is redacted. 41 | render: shell 42 | - type: checkboxes 43 | id: terms 44 | attributes: 45 | label: Code of Conduct 46 | description: By submitting this issue, you agree to follow our [Code of Conduct](CODE_OF_CONDUCT.md) 47 | options: 48 | - label: I agree to follow this project's Code of Conduct 49 | required: true 50 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature.yml: -------------------------------------------------------------------------------- 1 | name: Feature 2 | description: Suggest an idea for a new feature or enhancement 3 | title: "[FEAT]: " 4 | labels: ["Type: Feature", "Status: Triage"] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | Thanks for taking the time to fill this out! 10 | - type: textarea 11 | id: describe-need 12 | attributes: 13 | label: Describe the need 14 | description: What do you want to happen? What problem are you trying to solve? 15 | placeholder: Describe the need for the feature. 16 | validations: 17 | required: true 18 | - type: input 19 | id: sdk_version 20 | attributes: 21 | label: SDK Version 22 | description: Does this feature suggestion apply to a specific SDK version? 23 | placeholder: Octokit.rb v6.0.0 24 | validations: 25 | required: false 26 | - type: input 27 | id: api_version 28 | attributes: 29 | label: API Version 30 | description: Does this feature suggestion apply to a specific version of the GitHub REST API or GraphQL API? 31 | placeholder: ex. v1.1.1 32 | validations: 33 | required: false 34 | - type: textarea 35 | id: logs 36 | attributes: 37 | label: Relevant log output 38 | description: | 39 | Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks. 40 | Please check your logs before submission to ensure sensitive information is redacted. 41 | render: shell 42 | - type: checkboxes 43 | id: terms 44 | attributes: 45 | label: Code of Conduct 46 | description: By submitting this issue, you agree to follow our [Code of Conduct](CODE_OF_CONDUCT.md) 47 | options: 48 | - label: I agree to follow this project's Code of Conduct 49 | required: true 50 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/maintenance.yml: -------------------------------------------------------------------------------- 1 | name: Maintenance 2 | description: Dependencies, cleanup, refactoring, reworking of code 3 | title: "[MAINT]: " 4 | labels: ["Type: Maintenance", "Status: Triage"] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | Thanks for taking the time to fill this out! 10 | - type: textarea 11 | id: describe-need 12 | attributes: 13 | label: Describe the need 14 | description: What do you want to happen? 15 | placeholder: Describe the maintenance need here. 16 | validations: 17 | required: true 18 | - type: input 19 | id: sdk_version 20 | attributes: 21 | label: SDK Version 22 | description: Does this maintenance apply to a specific SDK version? 23 | placeholder: terraform-provider-github v5.7.0 24 | validations: 25 | required: false 26 | - type: input 27 | id: api_version 28 | attributes: 29 | label: API Version 30 | description: Does this maintenance apply to a specific version of the GitHub REST API or GraphQL API? 31 | placeholder: ex. v1.1.1 32 | validations: 33 | required: false 34 | - type: textarea 35 | id: logs 36 | attributes: 37 | label: Relevant log output 38 | description: | 39 | Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks. 40 | Please check your logs before submission to ensure sensitive information is redacted. 41 | render: shell 42 | - type: checkboxes 43 | id: terms 44 | attributes: 45 | label: Code of Conduct 46 | description: By submitting this issue, you agree to follow our [Code of Conduct](CODE_OF_CONDUCT.md) 47 | options: 48 | - label: I agree to follow this project's Code of Conduct 49 | required: true 50 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | Resolves #ISSUE_NUMBER 4 | 5 | ---- 6 | 7 | ### Before the change? 8 | 9 | 10 | * 11 | 12 | ### After the change? 13 | 14 | 15 | * 16 | 17 | ### Pull request checklist 18 | - [ ] Tests for the changes have been added (for bug fixes / features) 19 | - [ ] Docs have been reviewed and added / updated if needed (for bug fixes / features) 20 | 21 | ### Does this introduce a breaking change? 22 | 23 | 24 | Please see our docs on [breaking changes](https://github.com/octokit/.github/blob/master/community/breaking_changes.md) to help! 25 | 26 | - [ ] Yes 27 | - [ ] No 28 | 29 | ---- 30 | 31 | -------------------------------------------------------------------------------- /.github/renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "github>octokit/.github" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /.github/workflows/add_to_octokit_project.yml: -------------------------------------------------------------------------------- 1 | name: Add PRs and issues to Octokit org project 2 | 3 | on: 4 | issues: 5 | types: [reopened, opened] 6 | pull_request_target: 7 | types: [reopened, opened] 8 | 9 | jobs: 10 | add-to-project: 11 | name: Add issue to project 12 | runs-on: ubuntu-latest 13 | continue-on-error: true 14 | steps: 15 | - uses: actions/add-to-project@v1.0.2 16 | with: 17 | project-url: https://github.com/orgs/octokit/projects/10 18 | github-token: ${{ secrets.OCTOKITBOT_PROJECT_ACTION_TOKEN }} 19 | labeled: "Status: Stale" 20 | label-operator: NOT 21 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | name: CodeQL 2 | "on": 3 | push: 4 | branches: 5 | - main 6 | pull_request: 7 | branches: 8 | - main 9 | schedule: 10 | - cron: 36 20 * * 3 11 | jobs: 12 | analyze: 13 | name: Analyze 14 | runs-on: ubuntu-latest 15 | permissions: 16 | actions: read 17 | contents: read 18 | security-events: write 19 | strategy: 20 | fail-fast: false 21 | matrix: 22 | language: 23 | - javascript 24 | steps: 25 | - name: Checkout repository 26 | uses: actions/checkout@v4 27 | - name: Initialize CodeQL 28 | uses: github/codeql-action/init@v3 29 | with: 30 | languages: ${{ matrix.language }} 31 | - name: Autobuild 32 | uses: >- 33 | github/codeql-action/autobuild@ff3337ee1b38c9bcf43046bde6450e50c5e88ebb 34 | env: 35 | CODEQL_ACTION_RUN_MODE: Action 36 | - name: Perform CodeQL Analysis 37 | uses: github/codeql-action/analyze@v3 38 | -------------------------------------------------------------------------------- /.github/workflows/immediate-response.yml: -------------------------------------------------------------------------------- 1 | name: Issue/PR response 2 | permissions: 3 | issues: write 4 | pull-requests: write 5 | on: 6 | issues: 7 | types: 8 | - opened 9 | pull_request_target: 10 | types: 11 | - opened 12 | jobs: 13 | respond-to-issue: 14 | if: ${{ github.actor != 'dependabot[bot]' && github.actor != 'renovate[bot]' && github.actor != 'githubactions[bot]' && github.actor != 'octokitbot' }} 15 | runs-on: ubuntu-latest 16 | steps: 17 | - name: Determine issue or PR number 18 | id: extract 19 | run: echo "NUMBER=${{ github.event.issue.number || github.event.pull_request.number }}" >> "$GITHUB_OUTPUT" 20 | 21 | - name: Respond to issue or PR 22 | uses: peter-evans/create-or-update-comment@v4 23 | with: 24 | issue-number: ${{ steps.extract.outputs.NUMBER }} 25 | body: > 26 | 👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! 27 | We have a [process in place](https://github.com/octokit/.github/blob/main/community/prioritization_response.md#overview) for prioritizing and responding to your input. 28 | Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with `Status: Up for grabs`. 29 | You & others like you are the reason all of this works! So thank you & happy coding! 🚀 30 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | "on": 3 | push: 4 | branches: 5 | - main 6 | - next 7 | - beta 8 | - v*.x 9 | # These are recommended by the semantic-release docs: https://github.com/semantic-release/npm#npm-provenance 10 | permissions: 11 | contents: write # to be able to publish a GitHub release 12 | issues: write # to be able to comment on released issues 13 | pull-requests: write # to be able to comment on released pull requests 14 | id-token: write # to enable use of OIDC for npm provenance 15 | 16 | jobs: 17 | release: 18 | name: release 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@v4 22 | - uses: actions/setup-node@v4 23 | with: 24 | node-version: lts/* 25 | cache: npm 26 | - run: npm ci 27 | - run: npx semantic-release 28 | env: 29 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 30 | NPM_TOKEN: ${{ secrets.OCTOKITBOT_NPM_TOKEN }} 31 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | "on": 3 | push: 4 | branches: 5 | - main 6 | pull_request: 7 | types: 8 | - opened 9 | - synchronize 10 | jobs: 11 | test: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v4 15 | - uses: actions/setup-node@v4 16 | with: 17 | node-version: 18 18 | cache: npm 19 | - run: npm ci 20 | - run: npm test 21 | - run: npm run validate:ts 22 | - run: npm run update 23 | env: 24 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 25 | -------------------------------------------------------------------------------- /.github/workflows/update-graphql-codegen.yml: -------------------------------------------------------------------------------- 1 | name: Update graphql-codegen 2 | "on": 3 | push: 4 | branches: 5 | - dependabot/npm_and_yarn/graphql-codegen/* 6 | jobs: 7 | update_graphql-codegen: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v4 11 | - uses: actions/setup-node@v4 12 | with: 13 | cache: npm 14 | node-version: 18 15 | - run: npm ci 16 | - run: npm run generate-typescript 17 | - uses: gr2m/create-or-update-pull-request-action@v1.x 18 | env: 19 | GITHUB_TOKEN: ${{ secrets.OCTOKITBOT_PAT }} 20 | with: 21 | title: graphql-codegen updated 22 | body: An update to graphql-codegen required updates to your code. 23 | branch: ${{ github.ref }} 24 | commit-message: "chore(deps): upgrade graphql-codegen" 25 | -------------------------------------------------------------------------------- /.github/workflows/update-prettier.yml: -------------------------------------------------------------------------------- 1 | name: Update Prettier 2 | "on": 3 | push: 4 | branches: 5 | - dependabot/npm_and_yarn/prettier-* 6 | jobs: 7 | update_prettier: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v4 11 | - uses: actions/setup-node@v4 12 | with: 13 | cache: npm 14 | node-version: 18 15 | - run: npm ci 16 | - run: npm run lint:fix 17 | - uses: gr2m/create-or-update-pull-request-action@v1.x 18 | env: 19 | GITHUB_TOKEN: ${{ secrets.OCTOKITBOT_PAT }} 20 | with: 21 | title: Prettier updated 22 | body: An update to prettier required updates to your code. 23 | branch: ${{ github.ref }} 24 | commit-message: "style: prettier" 25 | -------------------------------------------------------------------------------- /.github/workflows/update.yml: -------------------------------------------------------------------------------- 1 | "on": 2 | schedule: 3 | - cron: 0 * * * * 4 | workflow_dispatch: {} 5 | name: Update 6 | jobs: 7 | update: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v4 11 | - uses: actions/setup-node@v4 12 | with: 13 | node-version: 18 14 | cache: npm 15 | - run: git checkout schema-update || true 16 | - run: npm ci 17 | - run: npm run update 18 | env: 19 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 20 | - uses: actions/create-github-app-token@v2 21 | id: app-token 22 | with: 23 | app-id: ${{ vars.OCTOKIT_APP_ID }} 24 | private-key: ${{ secrets.OCTOKIT_APP_PRIVATE_KEY }} 25 | - name: create pull request 26 | uses: gr2m/create-or-update-pull-request-action@v1.x 27 | env: 28 | GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} 29 | with: 30 | title: 🚧 🤖📯 GraphQL Schema changed 31 | body: > 32 | I found new changes in GitHub's GraphQL Schema 👋🤖 33 | 34 | 35 | I can't tell if the changes are fixes, features or breaking, you'll 36 | have to figure that out on yourself and adapt the commit messages 37 | accordingly to trigger the right release, see [our commit message 38 | conventions](https://github.com/octokit/openapi/blob/main/CONTRIBUTING.md#merging-the-pull-request--releasing-a-new-version). 39 | branch: schema-update 40 | author: Octokit Bot 41 | path: schema.graphql 42 | commit-message: "WIP: schema.graphql changed - please review" 43 | labels: "Type: Maintenance" 44 | - name: update schema.json 45 | uses: gr2m/create-or-update-pull-request-action@v1.x 46 | env: 47 | GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} 48 | with: 49 | branch: schema-update 50 | author: Octokit Bot 51 | commit-message: "build: schema.json and schema.d.ts updated" 52 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | - Using welcoming and inclusive language 12 | - Being respectful of differing viewpoints and experiences 13 | - Gracefully accepting constructive criticism 14 | - Focusing on what is best for the community 15 | - Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | - The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | - Trolling, insulting/derogatory comments, and personal or political attacks 21 | - Public or private harassment 22 | - Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | - Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at coc@martynus.net. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to contribute 2 | 3 | Support and contributions from the open source community are essential for keeping 4 | the `graphql-schema` up to date and always improving! There are a few guidelines that we need 5 | contributors to follow to keep the project consistent, as well as allow us to keep 6 | maintaining `graphql-schema` in a reasonable amount of time. 7 | 8 | Please note that this project is released with a [Contributor Code of Conduct][coc]. 9 | By participating in this project you agree to abide by its terms. 10 | 11 | [coc]: ./CODE_OF_CONDUCT.md 12 | 13 | ## Creating an Issue 14 | 15 | Before you create a new Issue: 16 | 17 | - Check the [Issues](https://github.com/octokit/graphql-schema/issues) on GitHub to ensure one doesn't already exist. 18 | - Clearly describe the issue, including the steps to reproduce the issue. 19 | - Please include links to the corresponding github documentation. 20 | 21 | ## Making Changes 22 | 23 | - Create a topic branch from the main branch. 24 | - Check for unnecessary whitespace / changes with `git diff --check` before committing. 25 | - Keep git commit messages clear and appropriate. Ideally follow commit conventions described below. 26 | 27 | ## Submitting the Pull Request 28 | 29 | - Push your changes to your topic branch on your fork of the repo. 30 | - Submit a pull request from your topic branch to the main branch on the `graphql-schema` repository. 31 | - Be sure to tag any issues your pull request is taking care of / contributing to. 32 | - Adding "Closes #123" to a pull request description will auto close the issue once the pull request is merged in. 33 | 34 | ## Merging the Pull Request & releasing a new version 35 | 36 | Releases are automated using [semantic-release](https://github.com/semantic-release/semantic-release). 37 | The following commit message conventions determine which version is released: 38 | 39 | 1. `fix: ...` or `fix(scope name): ...` prefix in subject: bumps fix version, e.g. `1.2.3` → `1.2.4` 40 | 2. `feat: ...` or `feat(scope name): ...` prefix in subject: bumps feature version, e.g. `1.2.3` → `1.3.0` 41 | 3. `BREAKING CHANGE: ` in body: bumps breaking version, e.g. `1.2.3` → `2.0.0` 42 | 43 | Only one version number is bumped at a time, the highest version change trumps the others. 44 | Besides publishing a new version to npm, semantic-release also creates a git tag and release 45 | on GitHub, generates changelogs from the commit messages and puts them into the release notes. 46 | 47 | If the pull request looks good but does not follow the commit conventions, use the "Squash & merge" button. 48 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) GitHub 2025 - Licensed as MIT. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # graphql-schema 2 | 3 | > GitHub’s GraphQL Schema with validation. Automatically updated. 4 | 5 | ![Test](https://github.com/octokit/graphql-schema/workflows/Test/badge.svg) 6 | 7 | ## Usage 8 | 9 | ### Validation 10 | 11 | ```js 12 | import { validate } from "@octokit/graphql-schema"; 13 | const errors = validate(` 14 | { 15 | viewer { 16 | login 17 | } 18 | } 19 | `); 20 | 21 | // errors is array. Contains errors if any 22 | ``` 23 | 24 | You can also load the current Schema directly as JSON or [IDL](https://en.wikipedia.org/wiki/Interface_description_language). 25 | 26 | ```js 27 | import { schema } from "@octokit/graphql-schema"; 28 | schema.json; // JSON version 29 | schema.idl; // IDL version 30 | ``` 31 | 32 | ### Schema as Types 33 | 34 | ```ts 35 | import { graphql } from "@octokit/graphql"; 36 | import { Repository } from "@octokit/graphql-schema"; 37 | 38 | const { repository } = await graphql<{ repository: Repository }>( 39 | ` 40 | { 41 | repository(owner: "octokit", name: "graphql.js") { 42 | issues(last: 3) { 43 | edges { 44 | node { 45 | title 46 | } 47 | } 48 | } 49 | } 50 | } 51 | `, 52 | { 53 | headers: { 54 | authorization: `token secret123`, 55 | }, 56 | }, 57 | ); 58 | ``` 59 | 60 | ## Local setup 61 | 62 | ``` 63 | git clone https://github.com/octokit/graphql-schema.git 64 | cd graphql-schema 65 | npm install 66 | npm test 67 | ``` 68 | 69 | Update schema files (`GITHUB_TOKEN` requires no scope) 70 | 71 | ``` 72 | GITHUB_TOKEN=... npm run update 73 | ``` 74 | 75 | ## See also 76 | 77 | - [octokit/openapi](https://github.com/octokit/openapi) – GitHub's OpenAPI specification with `x-octokit` extension 78 | - [octokit/webhooks](https://github.com/octokit/webhooks) – GitHub Webhooks specifications 79 | - [octokit/app-permissions](https://github.com/octokit/app-permissions) – GitHub App permission specifications 80 | 81 | ## LICENSE 82 | 83 | [MIT](LICENSE.md) 84 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | Thanks for helping make GitHub Open Source Software safe for everyone. 4 | 5 | GitHub takes the security of our software products and services seriously, including all of the open source code repositories managed through our GitHub organizations, such as [Octokit](https://github.com/octokit). 6 | 7 | Even though [open source repositories are outside of the scope of our bug bounty program](https://bounty.github.com/index.html#scope) and therefore not eligible for bounty rewards, we want to make sure that your finding gets passed along to the maintainers of this project for remediation. 8 | 9 | ## Reporting a Vulnerability 10 | 11 | Since this source is part of [Octokit](https://github.com/octokit) (a GitHub organization) we ask that you follow the guidelines [here](https://github.com/github/.github/blob/master/SECURITY.md#reporting-security-issues) to report anything that you might've found. 12 | -------------------------------------------------------------------------------- /bin/download.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | import { writeFileSync } from "node:fs"; 4 | import dotenv from "dotenv"; 5 | dotenv.config(); 6 | 7 | if (!process.env.GITHUB_TOKEN) { 8 | console.log("GITHUB_TOKEN not set"); 9 | process.exit(1); 10 | } 11 | 12 | import { execa } from "execa"; 13 | import { request as octokitRequest } from "@octokit/request"; 14 | const request = octokitRequest.defaults({ 15 | headers: { 16 | authorization: `bearer ${process.env.GITHUB_TOKEN}`, 17 | }, 18 | }); 19 | 20 | console.log("⌛ Loading GitHub GraphQL JSON schema …"); 21 | request("/graphql") 22 | .then((response) => { 23 | writeFileSync("schema.json", JSON.stringify(response.data.data, null, 2)); 24 | 25 | console.log("⌛ Loading GitHub GraphQL IDL schema …"); 26 | return request("/graphql", { 27 | headers: { 28 | accept: "application/vnd.github.v4.idl", 29 | }, 30 | }); 31 | }) 32 | 33 | .then(async (response) => { 34 | writeFileSync("schema.graphql", response.data.data); 35 | 36 | const { stdout } = await execa("git", ["status", "schema.graphql"]); 37 | if (/nothing to commit/.test(stdout)) { 38 | console.log("✅ Schema is up-to-date"); 39 | return; 40 | } 41 | 42 | console.log("📼 New schema recorded"); 43 | }); 44 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | import { GraphQLError } from "graphql"; 2 | 3 | type JsonSchema = { 4 | [key: string]: any; 5 | }; 6 | 7 | type Schema = { 8 | idl: string; 9 | json: JsonSchema; 10 | }; 11 | 12 | type Validate = (query: ReadonlyArray | Readonly) => ReadonlyArray; 13 | 14 | export const schema: Schema 15 | export const validate: Validate 16 | 17 | export type * from './schema.d.ts' 18 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | import { readFileSync } from 'node:fs'; 2 | import validate from './lib/validate.js'; 3 | 4 | export { validate }; 5 | export const schema = { 6 | get idl () { 7 | return readFileSync(new URL('./schema.graphql', import.meta.url), 'utf8') 8 | }, 9 | json: JSON.parse(readFileSync(new URL('./schema.json', import.meta.url), 'utf8')) 10 | } 11 | -------------------------------------------------------------------------------- /lib/validate.js: -------------------------------------------------------------------------------- 1 | export default validateQuery; 2 | 3 | import { readFileSync } from "node:fs"; 4 | import { buildClientSchema, validate } from "graphql"; 5 | import gql from "graphql-tag"; 6 | 7 | const schema = buildClientSchema( 8 | JSON.parse(readFileSync(new URL("../schema.json", import.meta.url), "utf8")), 9 | ); 10 | 11 | function validateQuery(query) { 12 | return validate(schema, gql(query)); 13 | } 14 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@octokit/graphql-schema", 3 | "version": "0.0.0-development", 4 | "publishConfig": { 5 | "access": "public", 6 | "provenance": true 7 | }, 8 | "description": "GitHub’s GraphQL Schema with validation. Automatically updated.", 9 | "type": "module", 10 | "scripts": { 11 | "lint": "prettier --check '{bin,lib,test}/**/*.{js,ts}' *.md package.json", 12 | "lint:fix": "prettier --write '{bin,lib,test}/**/*.{js,ts}' *.md package.json", 13 | "test": "node test", 14 | "validate:ts": "tsc --noEmit --noImplicitAny test/typescript-validate.ts", 15 | "postvalidate:ts": "attw --pack . --ignore-rules cjs-resolves-to-esm", 16 | "posttest": "npm run -s lint", 17 | "download": "node bin/download.js", 18 | "generate-typescript": "graphql-codegen", 19 | "update": "npm run -s download && npm run -s generate-typescript" 20 | }, 21 | "keywords": [ 22 | "github", 23 | "graphql", 24 | "schema", 25 | "validation" 26 | ], 27 | "author": "Gregor Martynus (https://twitter.com/gr2m)", 28 | "license": "MIT", 29 | "dependencies": { 30 | "graphql": "^16.0.0", 31 | "graphql-tag": "^2.10.3" 32 | }, 33 | "devDependencies": { 34 | "@arethetypeswrong/cli": "^0.17.0", 35 | "@graphql-codegen/cli": "^5.0.0", 36 | "@graphql-codegen/typescript": "^4.0.0", 37 | "@octokit/graphql": "^8.0.1", 38 | "dotenv": "^16.0.0", 39 | "execa": "^9.0.0", 40 | "prettier": "^3.0.0", 41 | "semantic-release": "^24.0.0", 42 | "typescript": "^5.0.0" 43 | }, 44 | "repository": "github:octokit/graphql-schema", 45 | "types": "index.d.ts", 46 | "sideEffects": false, 47 | "release": { 48 | "branches": [ 49 | "+([0-9]).x", 50 | "main", 51 | "next", 52 | { 53 | "name": "beta", 54 | "prerelease": true 55 | } 56 | ] 57 | }, 58 | "codegen": { 59 | "overwrite": true, 60 | "schema": "schema.graphql", 61 | "generates": { 62 | "schema.d.ts": { 63 | "plugins": [ 64 | "typescript" 65 | ], 66 | "config": { 67 | "enumsAsTypes": true, 68 | "useImplementingTypes": true 69 | } 70 | } 71 | } 72 | }, 73 | "main": "index.js", 74 | "exports": { 75 | ".": { 76 | "types": "./index.d.ts", 77 | "import": "./index.js" 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | import "./smoke.js"; 2 | import "./validate.js"; 3 | -------------------------------------------------------------------------------- /test/smoke.js: -------------------------------------------------------------------------------- 1 | import { strict } from "assert"; 2 | 3 | import { validate, schema } from "../index.js"; 4 | 5 | strict.equal(typeof validate, "function"); 6 | strict.equal(typeof schema.json, "object"); 7 | strict.equal(typeof schema.idl, "string"); 8 | -------------------------------------------------------------------------------- /test/typescript-validate.ts: -------------------------------------------------------------------------------- 1 | import { PullRequestState, validate, schema } from "../index.js"; 2 | 3 | export default async function () { 4 | const query = ` 5 | { 6 | viewer { 7 | login 8 | } 9 | } 10 | `; 11 | 12 | /* Testing named imports */ 13 | validate(query); 14 | 15 | // Obtains schemas properly 16 | schema.json; 17 | schema.idl; 18 | } 19 | 20 | const state: PullRequestState = "MERGED"; 21 | 22 | console.log(state); 23 | -------------------------------------------------------------------------------- /test/validate.js: -------------------------------------------------------------------------------- 1 | import { strict, match } from "assert"; 2 | 3 | import { validate } from "../index.js"; 4 | 5 | const goodQuery = validate(` 6 | { 7 | viewer { 8 | login 9 | } 10 | } 11 | `); 12 | const badQuery = validate(` 13 | { 14 | viewer { 15 | foo 16 | } 17 | } 18 | `); 19 | 20 | strict.equal(goodQuery[0], undefined, "goodQuery validation returns no errors"); 21 | match( 22 | badQuery[0].message, 23 | /Cannot query field "foo" on type "User"/, 24 | "badQuery validation returns GraphQLError error", 25 | ); 26 | --------------------------------------------------------------------------------