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

http-link-dataloader

v0.1.6

Published

[![CircleCI](https://circleci.com/gh/graphcool/http-link-dataloader.svg?style=shield)](https://circleci.com/gh/graphcool/http-link-dataloader) [![npm version](https://badge.fury.io/js/http-link-dataloader.svg)](https://badge.fury.io/js/http-link-dataloade

Downloads

20,766

Readme

http-link-dataloader

CircleCI npm version

📚📡 HTTP Apollo Link with batching & caching provided by dataloader.

Idea

A Apollo Link that batches requests both in Node and the Browser. You may ask what's the difference to apollo-link-batch-http. Instead of having a time-frame/fixed cache size based batching approach like in apollo-link-batch-http, this library uses dataloader for batching requests. It is a more generic approach just depending on the Node.JS event loop that batches all consecutive queries directly. The main use-case for this library is the usage from a graphql-yoga server using prisma-binding, but it can be used in any environment, even the browser as the latest dataloader version also runs in browser environments.

Usage

import { HTTPLinkDataloader } from 'http-link-dataloader'

const link = new HTTPLinkDataloader()

const token = 'Auth Token'

const httpLink = new HTTPLinkDataloader({
  uri: `api endpoint`,
  headers: { Authorization: `Bearer ${token}` },
})

Caching behavior

Note that the dataloader cache aggressively caches everything! That means if you don't want to cache anymore, just create a new instance of BatchedHTTPLink. A good fit for this is every incoming HTTP request in a server environment - on each new HTTP request a new BatchedHTTPLink instance is created.

Batching

This library uses array-based batching. Querying 2 queries like this creates the following payload:

query {
  Item(id: "1") {
    id
    name
    text
  }
}
query {
  Item(id: "2") {
    id
    name
    text
  }
}

Instead of sending 2 separate http requests, it gets combined into one:

;[
  {
    query: `query {
      Item(id: "1") {
        id
        name
        text
      }
    }`,
  },
  {
    query: `query {
      Item(id: "2") {
        id
        name
        text
      }
    }`,
  },
]

Note that the GraphQL Server needs to support the array-based batching! (Prisma supports this out of the box)

Even better batching

A batching that would even be faster is alias-based batching. Instead of creating the array described above, it would generate something like this:

{
  query: `
    query {
      item_1: Item(id: "1") {
        id
        name
        text
      }
      item_2: Item(id: "2") {
        id
        name
        text
      }
    }`
}

This requires a lot more logic and resolution magic for aliases, but would be a lot faster than the array based batching as our tests have shown! Anyone intersted in working on this is more than welcome to do so! You can either create an issue or just reach out to us in slack and join our #contributors channel.

Help & Community Slack Status

Join our Slack community if you run into issues or have questions. We love talking to you!