Apollo REST Data Source
Documentation
Usage
npm install apollo-datasource-restconst { RESTDataSource } = require('apollo-datasource-rest');
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;
}
}HTTP Methods
Intercepting fetches
Resolving URLs dynamically
Accessing data sources from resolvers
Implementing custom metrics
Last updated