github-graphql-schema
v10.198.0
Published
GitHub’s GraphQL Schema with validation. Automatically updated.
Downloads
147
Maintainers
Readme
github-graphql-schema
GitHub’s GraphQL Schema with validation. Automatically updated.
⚠️ This is a fork of octokit/graphql-schema with automatic update enabled and fixes integrated. Compare the fork with the origin to browse the differences.
Usage
Validation
const { validate } = require("github-graphql-schema");
const errors = validate(`
{
viewer {
login
}
}
`);
// errors is array. Contains errors if any
You can also load the current Schema directly as JSON or IDL.
const { schema } = require("github-graphql-schema");
schema.json; // JSON version
schema.idl; // IDL version
Schema as Types
import { graphql } from "@octokit/graphql";
import { Repository } from "github-graphql-schema";
const { repository } = await graphql<{ repository: Repository }>(
`
{
repository(owner: "octokit", name: "graphql.js") {
issues(last: 3) {
edges {
node {
title
}
}
}
}
}
`,
{
headers: {
authorization: `token secret123`,
},
}
);
CLI
This package comes with a CLI that can be used to generate types based on GitHub's GraphQL schema.
Generate types for your operations (queries, mutations, subscriptions)
# don't forget the quotes when using a glob
github-graphql-schema operations -i './src/**/*.ts'
Local setup
git clone https://github.com/zhouzi/github-graphql-schema.git
cd github-graphql-schema
npm install
npm test
Update schema files (GITHUB_TOKEN
requires no scope)
GITHUB_TOKEN=... npm run update
See also
- octokit/openapi – GitHub's OpenAPI specification with
x-octokit
extension - octokit/webhooks – GitHub Webhooks specifications
- octokit/app-permissions – GitHub App permission specifications