-
Notifications
You must be signed in to change notification settings - Fork 0
/
resolvers.js
47 lines (42 loc) · 1.44 KB
/
resolvers.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
const AWS = require('aws-sdk');
const Genius = require('genius-lyrics');
const ArtistService = require('./artists/artist-service');
const SongService = require('./song/song-service');
const SecretsManager = require('./secrets/secrets-manager');
const client = new AWS.SecretsManager({
region: 'us-east-1',
});
const secretsManager = new SecretsManager(client);
const artistService = (async ()=>{
const apiKey = await secretsManager.getSecrets('genius/apiKey');
return new ArtistService(new Genius.Client(apiKey.GENIUS_API_KEY));
})();
const songService = (async ()=>{
const apiKey = await secretsManager.getSecrets('genius/apiKey');
return new SongService(new Genius.Client(apiKey.GENIUS_API_KEY));
})();
module.exports = {
Query: {
async artists(parent, args, context, info) {
return (await artistService).find(args.search).then((result) => {
return result;
}).catch((e)=>{
const error =
new Error(`error searching for artist. query=${args.search}`);
console.error(error);
console.error(e);
throw error;
});
},
async songs(parent, args, context, info) {
return (await songService).getSongs(args.artistId, args.top, args.filter)
.catch((e) => {
const error =
new Error(`error getting songs for artist=${args.artistId}`);
console.error(error);
console.error(e);
throw error;
});
},
},
};