github-graphql-schema
TypeScript icon, indicating that this package has built-in type declarations

10.198.0 • Public • Published

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'
Your code Generated types
const GetReposQuery = gql`
  query GetRepos {
    viewer {
      repositories {
        nodes {
          nameWithOwner
        }
      }
    }
  }
`;
        
export type GetReposQuery = {
  __typename?: "Query";
  viewer: {
    __typename?: "User";
    repositories: {
      __typename?: "RepositoryConnection";
      nodes?: Array<{
        __typename?: "Repository";
        nameWithOwner: string;
      } | null> | null;
    };
  };
};
        

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

Package Sidebar

Install

npm i github-graphql-schema

Weekly Downloads

6

Version

10.198.0

License

MIT

Unpacked Size

6.83 MB

Total Files

22

Last publish

Collaborators

  • gabinzhouzi