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

apollo-datasource

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-datasource

  • 0.4.1-alpha.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.2M
decreased by-6.5%
Maintainers
1
Weekly downloads
 
Created

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

Package last updated on 27 May 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