Socket
Socket
Sign inDemoInstall

apollo-datasource

Package Overview
Dependencies
11
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-datasource


Version published
Maintainers
1
Weekly downloads
1,459,272
decreased by-0.81%
Install size
597 kB

Weekly downloads

Package description

What is apollo-datasource?

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.

What are apollo-datasource's main functionalities?

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 }
    });
  }
}

Other packages similar to apollo-datasource

FAQs

Last updated on 15 Jun 2022

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc