Skip to content
This repository was archived by the owner on Feb 16, 2024. It is now read-only.

GitHub’s GraphQL Schema with validation. Automatically updated.

License

Notifications You must be signed in to change notification settings

zhouzi/github-graphql-schema

 
 

Repository files navigation

github-graphql-schema

GitHub’s GraphQL Schema with validation. Automatically updated.

Test

⚠️ Update Feb 16 2024: octokit/graphql-schema is back with automatic updates and bug fixes. There's no need to use this fork anymore, use the official channel instead.

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

About

GitHub’s GraphQL Schema with validation. Automatically updated.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 87.8%
  • TypeScript 12.2%