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 🙏

© 2026 – Pkg Stats / Ryan Hefner

gqlg

v1.0.2

Published

Generate queries from graphql schema, used for test;

Readme

gql-generator

Generate queries from graphql schema, used for test;

Usage

# Install
npm install gql-generator -g

# see the usage
gqlg --help

# Generate sample queries from typeDefs
gqlg --schemaFilePath ./example/sampleTypeDef.graphql --destDirPath ./example/output

Now you can find the generated queries in the destDir: ./example/output.

# Sample schema
type Query {
    user(id: Int!): User!
}

type User {
    id: Int!
    username: String!
    email: String!
    createdAt: String!
}
# Sample query generated
query user($id: Int!) {
    user(id: $id){
        id
        username
        email
        createdAt
    }
}

This tool will generate 3 folders holding the queries: mutations, queries and subscriptions. And generate a index.js exports the queries in each folder.

Also another index.js is generated in the root destPath to export all the queries (you can look into the example folder for details of generated files).

After generating the queries, you can require them like this:

// require all the queries
const queries = require('./example/output');
// require mutations only
const mutations = require('./example/output/mutations');

// sampe content
console.log(queries.mutations.signup);
console.log(mutations.signup);
/*
mutation signup($username: String!, email: String!, password: String!){
    signup(username: $username, email: $email, password: $password){
        token
        user {
            id
            username
            email
            createdAt
        }
    }
}
*/

Sample result:

The output folder inside example folder is generated from the sampleTypeDef.graphql by this command:

gqlg --schemaFilePath ./example/sampleTypeDef.graphql --destDirPath ./example/output

Usage example

Say you have a graphql schema like this:

type Mutation {
    signup(
        email: String!
        username: String!
        password: String!
    ): UserToken!
}

type UserToken {
    token: String!
    user: User!
}

type User {
    id: Int!
    username: String!
    email: String!
    createdAt: String!
}

Before this tool, you write graphql api test like this:

const { GraphQLClient } = require('graphql-request');
require('should');

const host = 'http://localhost:8080/graphql';

test('signup', async () => {
    const gql = new GraphQLClient(host);
    const query = `mutation signup($username: String!, email: String!, password: String!){
        signup(username: $username, email: $email, password: $password){
            token
            user {
                id
                username
                email
                createdAt
            }
        }
    }`;

    const data = await gql.request(query, {
        username: 'tim',
        email: '[email protected]',
        password: 'samplepass',
    });

    (typeof data.signup.token).should.equal('string');
);

As gqlg generated the queries for you, you don't need to write the query yourself, so your test will becomes:

const { GraphQLClient } = require('graphql-request');
require('should');
const mutations = require('./example/output/mutations');

const host = 'http://localhost:8080/graphql';

test('signup', async () => {
    const gql = new GraphQLClient(host);

    const data = await gql.request(mutations.signup, {
        username: 'tim',
        email: '[email protected]',
        password: 'samplepass',
    });

    (typeof data.signup.token).should.equal('string');
);

Notice

As this tool is used for test, it expends all the fields in a query. And as we know, there might be recursive field in the query. So gqlg ignores the types which has been added in the parent queries already.