npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

github-gql

v1.0.2

Published

A fully typed GraphQL client for the Github v4 API

Downloads

3

Readme

Github-gql

An end-to-end type-safe JavaScript client for the GitHub v4 GraphQL API.

Features

  • End-to-end type safe
  • Functional intellisense for both input queries and response data
  • No requirement for any external type generation process
  • Zero dependencies

Installation

npm install github-gql

Usage

import { GithubGql } from 'github-gql'

const example = async (): Promise<void> => {
  // Create the client with a personal or installation access token
  const client = new GithubGql({
    accessToken: process.env.GITHUB_ACCESS_TOKEN!
  })

  // Call the query endpoint
  const result = await client.query({
    // Specify your graphql query with complete type safety
    repository: {
      __args: {
        name: 'github-gql',
        owner: 'rpate97'
      },
      id: true,
      nameWithOwner: true,
      issues: {
        __args: {
          first: 10
        },
        nodes: {
          title: true,
          body: true,
        },
      }
    }
  })
  
  // The result will be correctly typed based on your input query
  console.log(result)
}

example()

Why does this exist?

I found the official client recommendation from GitHub to be difficult to deal with. It is not type safe and requires inline gql queries.

Typically when building my own GraphQL APIs for internal consumption, I'll achieve end-to-end type safety by using a code generation tool such as GraphQL Codegen combined with a compatible GraphQL client such as Apollo Client. Setting this sort of thing up just to interact with an external API from my GitHub bot seems like overkill to me. I believe this should be maintained in a separate package and available to others.

So I decided to create this library and release it for the benefit of anyone else working with the GitHub v4 GraphQL API. Enjoy.

Credit

This client is largely automatically generated with the help of GenQL, give them a star to show your appreciation. While you're at it, make sure you star this repo too.

License

All code is provided under the MIT license.