🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more
Socket
Book a DemoInstallSign in
Socket

@envelop/apollo-datasources

Package Overview
Dependencies
Maintainers
1
Versions
1351
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@envelop/apollo-datasources

This plugin integrates Apollo DataSources into Envelop.

Source
npmnpm
Version
5.1.3-alpha-20250306152819-85579bd42888d16682c982a98e5c72d4d7af6a19
Version published
Weekly downloads
2.9K
-30.93%
Maintainers
1
Weekly downloads
 
Created
Source

@envelop/apollo-datasources

This plugin integrates Apollo DataSources into Envelop.

Getting Started

yarn add @envelop/apollo-datasources

Usage Example

import { RESTDataSource } from 'apollo-datasource-rest'
import { execute, parse, specifiedRules, subscribe, validate } from 'graphql'
import { useApolloDataSources } from '@envelop/apollo-datasources'
import { envelop, useEngine } from '@envelop/core'

class MoviesAPI extends RESTDataSource {
  constructor() {
    super()
    this.baseURL = 'https://movies-api.example.com/'
  }

  async getMovie(id) {
    return this.get(`movies/${encodeURIComponent(id)}`)
  }

  async getMostViewedMovies(limit = 10) {
    const data = await this.get('movies', {
      per_page: limit,
      order_by: 'most_viewed'
    })
    return data.results
  }
}

const getEnveloped = envelop({
  plugins: [
    useEngine({ parse, validate, specifiedRules, execute, subscribe }),
    // ... other plugins ...
    useApolloDataSources({
      dataSources() {
        return {
          moviesAPI: new MoviesAPI()
        }
      }
      // To provide a custom cache, you can use the following code (InMemoryLRUCache is used by default):
      // cache: new YourCustomCache()
    })
  ]
})

FAQs

Package last updated on 06 Mar 2025

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