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

graphql-query-factory

v1.0.24

Published

![CI Build Status Bar](https://travis-ci.org/alechp/graphql-query-factory.svg?branch=flow)

Downloads

17

Readme

GraphQL Query Batcher

CI Build Status Bar

Note: "Query" is used broadly to mean both query and mutation

Overview

  • build GraphQL queries
  • batch execute those queries

Need quick batching? factory function is the answer Need to split the query build and query batching process? Checkout builder and batcher


Sample project: graphql-query-factory-test

Status

  • factory included as of 1.0.20 (shim around builder and batcher)
  • batcher included as of 1.0.20 (executes array of queries)
  • builder updated (this builds query strings from query/mutation and variables)

Action Items

You can see TODOs and release plans in todo.md

Getting Started

Installation

npm install graphql-query-factory -S

Configuration (Environment Variables)

When using factory or batcher you must include two environment variables:

  • GQL_SIMPLE_ENDPOINT
  • GQL_AUTH_TOKEN

Examples

All of these examples can be seen at graphql-query-factory-test

All mock variables (e.g. "mock.template", "mock.variables") can be viewed here: .../tests/_mock.js


builder

const { builder } = require('graphql-query-factory');

let queries = builder(mock.template, mock.variables);
log(`builder(mock.template, mock.variables): ${queries}`);

NOTE: async version has been replaced here with sync version. Will be adding async version of builder in future along with a stream. See todo.md for details.


factory

const { factory } = require('graphql-query-factory');

factory(mock.template, mock.variables)
  .then(data =>
    log(
      `factory(mock.template, mock.variables): ${JSON.stringify(data, null, 4)}`
    )
  )
  .catch(err => log(`factory(mock.template, mock.variables): ${err}`));

batcher

const { batcher } = require('graphql-query-factory');

batcher
  .batch(mock.batchQuery)
  .then(data =>
    log(`batcher.batch(mock.batchQuery): ${JSON.stringify(data, null, 4)}`)
  )
  .catch(err => log(`batcher.batch(mock.batchQuery): ${err}`));

Output

The following output is generated by the example project, graphql-query-factory-test

Data being saved to Graph.cool

graphcool

builder

mutation {
  createContent(
    markup: "markupA"
    raw: "rawA"
  ) {
    markup
    raw
  }
},mutation {
  createContent(
    markup: "markupB"
    raw: "rawB"
  ) {
    markup
    raw
  }
},mutation {
  createContent(
    markup: "markupC"
    raw: "rawC"
  ) {
    markup
    raw
  }
},mutation {
  createContent(
    markup: "markupD"
    raw: "rawD"
  ) {
    markup
    raw
  }
},mutation {
  createContent(
    markup: "markupE"
    raw: "rawE"
  ) {
    markup
    raw
  }
},mutation {
  createContent(
    markup: "markupF"
    raw: "rawF"
  ) {
    markup
    raw
  }
},mutation {
  createContent(
    markup: "markupG"
    raw: "rawG"
  ) {
    markup
    raw
  }
}

batcher

[
    {
        "createContent": {
            "markup": "markupA",
            "raw": "rawA"
        }
    },
    {
        "createContent": {
            "markup": "markupB",
            "raw": "rawB"
        }
    },
    {
        "createContent": {
            "markup": "markupC",
            "raw": "rawC"
        }
    },
    {
        "createContent": {
            "markup": "markupD",
            "raw": "rawD"
        }
    },
    {
        "createContent": {
            "markup": "markupE",
            "raw": "rawE"
        }
    },
    {
        "createContent": {
            "markup": "markupF",
            "raw": "rawF"
        }
    },
    {
        "createContent": {
            "markup": "markupG",
            "raw": "rawG"
        }
    }
]

factory

[
    {
        "createContent": {
            "markup": "markupA",
            "raw": "rawA"
        }
    },
    {
        "createContent": {
            "markup": "markupB",
            "raw": "rawB"
        }
    },
    {
        "createContent": {
            "markup": "markupC",
            "raw": "rawC"
        }
    },
    {
        "createContent": {
            "markup": "markupD",
            "raw": "rawD"
        }
    },
    {
        "createContent": {
            "markup": "markupE",
            "raw": "rawE"
        }
    },
    {
        "createContent": {
            "markup": "markupF",
            "raw": "rawF"
        }
    },
    {
        "createContent": {
            "markup": "markupG",
            "raw": "rawG"
        }
    }
]