Coder Social home page Coder Social logo

graphql-query-factory's Introduction

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"
        }
    }
]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.