github-graphql-schema

GitHub’s GraphQL Schema with validation. Automatically updated.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
github-graphql-schema
10.124.0a day ago4 months agoMinified + gzip package size for github-graphql-schema in KB

Readme

github-graphql-schema
GitHub’s GraphQL Schema with validation. Automatically updated.

Test
⚠️ 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'

<tr>
  <th>Your code</th>
  <th>Generated types</th>
</tr>
<tr>
  <td>
    <pre>
const GetReposQuery = gql` query GetRepos {
viewer {
  repositories {
    nodes {
      nameWithOwner
    }
  }
}
} `;
</pre>
      </td>
      <td>
<pre>
export type GetReposQuery = { typename?: "Query"; viewer: {
__typename?: "User";
repositories: {
  __typename?: "RepositoryConnection";
  nodes?: Array<{
    __typename?: "Repository";
    nameWithOwner: string;
  } | null> | null;
};
}; };
</pre>
      </td>
    </tr>

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

LICENSE

MIT