Skip to content

Decorate existing network interface? #1

@thebigredgeek

Description

@thebigredgeek

Very pleased with this package. Glad I won't need to roll my own solution haha. I was wondering if we could expose a higher-order function to decorate an existing network interface? I am currently doing the following for subscriptions:

import { print } from 'graphql-tag/printer';

// quick way to add the subscribe and unsubscribe functions to the network interface
export default function addGraphQLSubscriptions(networkInterface, wsClient) {
  return Object.assign(networkInterface, {
    subscribe(request, handler) {
      return wsClient.subscribe({
        query: print(request.query),
        variables: request.variables,
      }, handler);
    },
    unsubscribe(id) {
      wsClient.unsubscribe(id);
    },
  });
}

It seems like this will be a normal pattern moving forward for extended the default apollo network interface. I don't think it would be too difficult to expose an interface for something like this, and I am willing to submit a PR if you don't have time for it.

Thoughts @HriBB ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions