Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
apollo-link
Advanced tools
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.
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;
});
});
Relay Runtime is a framework from Facebook for building data-driven React applications with GraphQL. It is similar to apollo-link in that it manages GraphQL data operations, but it is tightly integrated with React and uses a different set of abstractions and optimizations specific to React applications.
Urql is a highly customizable and versatile GraphQL client, similar to apollo-link. It features a similar extensible approach with 'exchanges' which are analogous to Apollo's links. However, urql provides a more integrated caching mechanism and a simpler API, which might be preferred for smaller projects or those seeking simplicity.
apollo-link
is a standard interface for modifying control flow of GraphQL requests and fetching GraphQL results, designed to provide a simple GraphQL client that is capable of extensions.
The targeted use cases of apollo-link
are highlighted below:
Apollo Link is the interface for creating new links in your application.
npm install apollo-link --save
To use this package in a web browser or mobile app, you'll need a build system capable of loading NPM packages on the client. Some common choices include Browserify, Webpack, and Meteor +1.3.
FAQs
Flexible, lightweight transport layer for GraphQL
The npm package apollo-link receives a total of 1,024,550 weekly downloads. As such, apollo-link popularity was classified as popular.
We found that apollo-link demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.