Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
apollo-datasource
Advanced tools
The apollo-datasource package is a toolkit for building data sources in Apollo Server. It provides a class-based approach to organizing your data fetching logic, allowing you to connect to different types of data sources, such as REST APIs or databases, in a structured and efficient manner. It is designed to work seamlessly with Apollo Server, making it easier to build GraphQL APIs.
Creating a REST data source
This feature allows you to extend the RESTDataSource class to connect to a REST API. You can define methods to perform HTTP requests to your API endpoints. The example code demonstrates how to create a data source for fetching user data from a REST API.
class MyAPI extends RESTDataSource {
constructor() {
super();
this.baseURL = 'https://myapi.com/';
}
async getUser(userId) {
return this.get(`users/${userId}`);
}
}
Caching responses
Apollo DataSource provides built-in support for caching responses from your data sources. This feature helps in reducing the load on your data sources and improving the performance of your GraphQL API. The example code shows how to cache the response of a REST API call for 60 seconds.
class MyAPI extends RESTDataSource {
constructor() {
super();
this.baseURL = 'https://myapi.com/';
}
async getUser(userId) {
return this.get(`users/${userId}`, undefined, {
cacheOptions: { ttl: 60 }
});
}
}
Dataloader is a generic utility to be used as part of your application's data fetching layer to provide a simplified and consistent API over various remote data sources such as databases or web services via batching and caching. While Dataloader is not tied to any specific data fetching mechanism or strategy like REST or databases, it provides a similar benefit of batching and caching requests. Unlike apollo-datasource, it doesn't provide a structured way to define data sources but offers a more flexible batching and caching mechanism.
type-graphql-dataloader is an integration of DataLoader with TypeGraphQL. It aims to simplify the process of batching and caching in GraphQL resolvers. This package is specifically designed to work with TypeGraphQL, making it less generic compared to apollo-datasource. It provides decorators and helpers to easily integrate DataLoader with TypeGraphQL, offering a more GraphQL-centric approach to data loading with a focus on type safety.
FAQs
Unknown package
The npm package apollo-datasource receives a total of 972,180 weekly downloads. As such, apollo-datasource popularity was classified as popular.
We found that apollo-datasource demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.