-
Notifications
You must be signed in to change notification settings - Fork 1
/
StarWarsAPI.js
54 lines (40 loc) · 1.03 KB
/
StarWarsAPI.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const { RESTDataSource } = require('apollo-datasource-rest');
module.exports = class StarWarsAPI extends RESTDataSource {
constructor(...args) {
super(args)
this.baseURL = 'https://swapi.co/api/';
}
willSendRequest(req) {
//console.log('will send request');
}
async getPersonList(page = 1) {
return this.get(`people/?page=${page}`);
}
async getPerson(id) {
return this.get(`people/${id}`);
}
async getStarshipList(page = 1) {
return this.get(`starships/?page=${page}`);
}
async getStarship(id) {
return this.get(`starships/${id}`);
}
async getVehicleList(page = 1) {
return this.get(`vehicles/?page=${page}`);
}
async getVehicle(id) {
return this.get(`vehicles/${id}`);
}
async getSpeciesList(page = 1) {
return this.get(`species/?page=${page}`);
}
async getSpecies(id) {
return this.get(`species/${id}`);
}
async getPlanetList(page = 1) {
return this.get(`planets/?page=${page}`);
}
async getPlanet(id) {
return this.get(`planets/${id}`);
}
}