4.0.0 • Published 7 months ago

@envelop/apollo-datasources v4.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

@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()
    })
  ]
})
4.0.0

7 months ago

3.0.3

8 months ago

3.0.2

8 months ago

3.0.1

9 months ago

3.0.0

1 year ago

2.0.5

1 year ago

2.0.6

1 year ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.4

1 year ago

2.0.1

2 years ago

2.0.0

2 years ago

1.2.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.3.0

2 years ago

1.1.2

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago