question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature: Allow switching between batched and non-batched transport based on request

See original GitHub issue

Based on this conversation: https://apollographql.slack.com/archives/C11QBB84R/p1495471281173263

It would be great to have a new NetworkInterface type that uses a batch transport by default but allows you to force a single request if you don’t want it to batch. This is useful since it’s possible for automatic batching to hold up an entire page because fast important queries are batched with slow unimportant ones, which end up blocking all requests on the slowest query

A possible implementation / design would be a new HTTPHybridNetworkInterface (or a better name if people have one) that would wrap a HTTPFetchNetworkInterface and a HTTPBatchNetworkInterface and route requests to one or the other based on a property of the request

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
gauravmkcommented, Jun 6, 2017
1reaction
gauravmkcommented, Jun 1, 2017

Yep, that’s exactly what I ended up doing and it works for us.

For other folks who want to do something similar, we’re basically doing this:

/* @flow */
import {
  createBatchingNetworkInterface,
  createNetworkInterface,
  HTTPBatchedNetworkInterface,
  HTTPFetchNetworkInterface,
  Request,
} from 'apollo-client';

export class HTTPHybridNetworkInterface {
  batchedInterface: HTTPBatchedNetworkInterface;
  networkInterface: HTTPFetchNetworkInterface;

  constructor(opts: Object) {
    this.batchedInterface = createBatchingNetworkInterface(opts);
    this.networkInterface = createNetworkInterface(opts);
  }

  query(request: Request) {
    if (request.variables && request.variables.__disableBatch) {
      return this.networkInterface.query(request);
    } else {
      return this.batchedInterface.query(request);
    }
  }

  use(middlewares: Array<*>) {
    this.networkInterface.use(middlewares);
    this.batchedInterface.use(middlewares);
    return this;
  }

  useAfter(afterwares: Array<*>) {
    this.networkInterface.useAfter(afterwares);
    this.batchedInterface.useAfter(afterwares);
    return this;
  }
}

export function createHybridNetworkInterface(opts: Object) {
  return new HTTPHybridNetworkInterface(opts);
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Batching Client GraphQL Queries
Batching is the process of taking a group of requests, combining them into one, and making a single request with the same data...
Read more >
Jira notifications piling up in the mail queue due to SMTP ...
All notification emails from Jira (batched notifications, non-batched notifications, customer notifications) are piling up in the queue and ...
Read more >
Integrating NVIDIA Triton Inference Server with Kaldi ASR
Dynamic batcher: Inference requests can be combined by the server, so that a batch ... this requires a context switch between batches (d)....
Read more >
JSON 2.0 batch - Google Groups
Hi, I saw the batch in the new proposed specification. And I'm wondering: what is the benefit? It seems, the server is not...
Read more >
Communications Programming Concepts - RPC Features
The features of Remote Procedure Call (RPC) include batching calls, ... Callback procedures permit a server to become a client and make an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found