Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apollo-link

Package Overview
Dependencies
Maintainers
4
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-link

Flexible, lightweight transport layer for GraphQL

  • 1.2.10
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
976K
decreased by-12.58%
Maintainers
4
Weekly downloads
 
Created

What is apollo-link?

The apollo-link package provides a standard interface for modifying control flow of GraphQL requests and fetching GraphQL results. It is part of the Apollo ecosystem and allows developers to create a chain of link objects to handle GraphQL operations. This modular approach enables fine-grained control over the request/response cycle in a composable way.

What are apollo-link's main functionalities?

Middleware functionality

This feature allows developers to modify requests before they are sent to the server. In the code sample, a middleware link is created that injects an authorization token into the headers of each request.

import { ApolloLink } from 'apollo-link';

const middlewareLink = new ApolloLink((operation, forward) => {
  operation.setContext({ headers: { authorization: getAuthToken() } });
  return forward(operation);
});

Error handling

This feature allows developers to handle errors that occur during the GraphQL operation. The code sample demonstrates how to catch and process errors before they propagate further.

import { ApolloLink, Observable } from 'apollo-link';

const errorLink = new ApolloLink((operation, forward) => {
  return new Observable(observer => {
    const sub = forward(operation).subscribe({
      next: observer.next.bind(observer),
      error: error => {
        handleError(error);
        observer.error(error);
      },
      complete: observer.complete.bind(observer)
    });
    return () => sub.unsubscribe();
  });
});

Afterware functionality

This feature allows developers to modify responses returned from the server. In the code sample, an afterware link is used to check for server errors after a response is received but before it is processed further.

import { ApolloLink } from 'apollo-link';

const afterwareLink = new ApolloLink((operation, forward) => {
  return forward(operation).map(response => {
    checkForServerErrors(response);
    return response;
  });
});

Other packages similar to apollo-link

FAQs

Package last updated on 14 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc