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-graphql-v4-client

v0.1.4

Published

GitHub GraphQL(API v4) client - Multi token, concurrent control, auto retry

Downloads

6

Readme

GitHub GraphQL Client

CircleCI

This client is used to make GitHub GraphQL(API v4) query.

Requirements

Node.js: ^10.15.3

Usage

Run npm install -s github-graphql-client to install the package.

Demo:

import { GitHubClient } from "github-graphql-client";
import Logger = require("bunyan");

let client = new GitHubClient({
    // required
    // multiple token can be passed into the constructor
    // at least one token in the array
    tokens: ["xxx","yyy"],
    // optional
    // the max concurrent request number, may limited by network bandwidth
    // default value: 10
    maxConcurrentReqNumber: 20,
    // optional
    // max retry request time if the query fails
    // default value: 10
    maxRetryTimes: 5,
    // optional
    // return result with these HTTP status code will not retry and fail instantly
    // default value: [400, 401, 403, 404]
    filterStatusCode: [400, 403],
    // optional
    // a bunyan logger instance to log
    // default value: Logger.createLogger({
    //    name: "GitHub-GraphQL-Client",
    //   level: Logger.INFO
    //});
    logger: Logger.createLogger({
        name: "My-Own-Client",
        level: Logger.ERROR
    });
});

// need to call init first to init the token status
await client.init();
let result = await cient.query(query, {});

Features

This client have several features to make sure you have an excellent GraphQL query experience.

Multiple token management

As GitHub has rate limit for single token, the client supports multiple tokens in constructor options which can break the rate limit and there is no theoratical limitation if you have enough tokens to use.

And the client will automaticly handle the rate limit and reset time for every single token. To achieve this we need to add rate limit query into every query which is also done automaticly so you do not need to add rate limit in your query.

Concurrent request management

The client can make several calls at same time to speed up massive queies a time. You can set a max concurrent request number in constructor options.

The default max concurrent request number is 10, you may set it to 15 or 20 to speed up your queries. But if you have few tokens and a big max concurrent request number, you may trigger GitHub API abuse detection which will make your token invalid for a while.

Error handler

The client will handle any errors occured during a query properly.

If the query hit the token's rate limit, then the token will be invalid until the rate limit is reset, and the query will be retried by another valid token.

If the query returns NOT_FOUDN error which may be caused by fetching data from a deleted repo, the query will return null.

If the status code is in filterStatusCode array, the query will return any data if exists in the response.

Otherwise, the query will be retried until success or excceed the max retry times.

Retry handler

The client can take a max retry times option in constructor options whose default value is 10. If a query fails and retry may sovle the problem then the client will retry the query until retry time exceed the max retry times.

It is every important not to set the retry times to positive inifite because some query may always fail if it query too many data in a single query.

Contributing

Welcome to contribute to this project in any manners.

Please feel free to open an issue if you have any questions or doubts about this project.