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

gh-graphql-paginator

v1.0.1

Published

Simple GitHub GraphQL Paginator is a Node.js project that uses cursor-based pagination to paginate a GitHub GraphQL query Connection for single object.

Downloads

950

Readme

Simple GitHub GraphQL Paginator

Simple GitHub GraphQL Paginator is a Node.js project that uses cursor-based pagination to paginate a GitHub GraphQL query Connection for a single object.

Installation

Use the Node package manager npm to install Simple GitHub GraphQL Paginator.

npm install gh-graphql-paginator

Usage

Required:

  • Set an environment variable called GITHUB_TOKEN that stores a valid GitHub PAT that will be used for GitHub GraphQL API authentication.
  • The GraphQL query must include a variable called endCursor that is passed as the after argument value for the object which requires pagination. See the examples below.
  • Use Connections for the object you need to paginate, do not use Edges. See the examples below.
  • The Connection that requires pagination must also include pageInfo with hasNextPage and endCursor as well as totalCount. See the examples below.
  • The Connection that requires pagination must be a child of a single object. For example, this project cannot paginate issues and subsequently paginate comments for every issue. This project can paginate all issues pertaining to a repository or all issue comments for an issue.

Examples:

This query is fetching public repositories from the GitHub organization. The query will be paginated and all public repositories from the GitHub organization will be returned.

import { paginate } from 'gh-graphql-paginator'
const query = `
  query ($endCursor: String) {
    organization(login: "github") {
      repositories(first: 100, after: $endCursor, privacy: PUBLIC) {
        nodes {
          id
          name
        }
        totalCount
        pageInfo {
          hasNextPage
          endCursor
        }
      }
    }
  }
`;

async function paginateQuery() {
  const results = await paginate(query);
  console.log(JSON.stringify(results));
}

This query is fetching issue comments from Issue #3 in the github/github repo. The query will be paginated and all issue comments for the issue will be returned.

import { paginate } from 'gh-graphql-paginator'
const query = `
  query ($endCursor: String) {
    repository(name: "github", owner: "github") {
      issue(number: 3) {
        id
        comments(first: 1, after: $endCursor) {
          nodes {
            id
            body
          }
          totalCount
          pageInfo {
            hasNextPage
            endCursor
          }
        }
      }
    }
  }
`;

async function paginateQuery() {
  const results = await paginate(query);
  console.log(JSON.stringify(results));
}

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Supporting Docs