JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1920
  • Score
    100M100P100Q120858F
  • License MIT

light weight query batcher for graphql

Package Exports

  • graphql-query-batcher

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (graphql-query-batcher) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Graphql Query Batcher

A light weight graphql query batcher for javascript.

Usage

import QueryBatcher from 'graphql-query-batcher';

var client = New QueryBatcher('/graphql' /*, options */);

// although I am making 2 requests (different IDs), the client will batch them resulting
// in only 1 call to my server
client.fetch(`
  query getHuman($id: ID!) {
    human(id: $id) {
      name
      height
    }
  }
  `, { id: "1000" })
  .then(human => {
    // do something with human
    console.log(human);
  });

client.fetch(`
  query getHuman($id: ID!) {
    human(id: $id) {
      name
      height
    }
  }
  `, { id: "1001" })
  .then(human => {
    // do something with human
    console.log(human);
  });

Options

const options = {
  shouldBatch: true,  // should we batch queries?
  batchInterval: 6,   // duration of each batch window (in MS)
  maxBatch: 0,        // max number of requests in a batch (0 = no max)
};

Requirements

The graphql implementation you are using must suppoprt batching! To learn more read this: https://dev-blog.apollodata.com/query-batching-in-apollo-63acfd859862