-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.js
81 lines (74 loc) · 1.88 KB
/
handler.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const { graphql, buildSchema } = require('graphql');
const { makeExecutableSchema } = require('graphql-tools');
module.exports.graphql = async (event, context) => {
const graphqlPayload = JSON.parse(event.body);
const typeDefs = `
type Setlist {
id: String,
name: String,
songs: [Song]
}
type Song {
id: String,
name: String,
setlist: Setlist
}
type Artist {
id: String,
name: String,
songs: [Song],
setlists: [Setlist]
}
type Query {
artist: Artist,
song: Song,
setlist(artist: String): Setlist
}
`;
const getSongs = () => [{ id: '1', name: 'Run to the hills' }, { id: '2', name: 'Sea of madness' }];
const getSetlists = () => [{ id: '1', name: 'thesetlist' }, { id: '2', name: 'thesetldafafist' }];
const resolvers = {
Query: {
artist: () => {
return 'bruuuuuuuuce';
},
song: () => getSongs()[0],
setlist: () => getSetlists()
},
Setlist: {
// hejsan: () => { return 'dsfasf'},
id: (obj) => {
return obj.id;
},
songs: (obj) => {
console.log(obj);
return getSongs().filter(song => song.id === obj[0].id)
}
},
Song: {
setlist: (_, args) => {
console.log('arrtgsgsgs', args);
return getSetlists();
}
}
};
const graphQLSchema = makeExecutableSchema({
typeDefs,
resolvers
});
return {
statusCode: 200,
body: JSON.stringify(await graphql(graphQLSchema, graphqlPayload.query, {}))
};
};
module.exports.hello = async (event, context) => {
return {
statusCode: 200,
body: JSON.stringify({
message: 'Go Tailwind v1.0! Your function executed successfully!',
input: event
})
};
// Use this code if you don't use the http event with the LAMBDA-PROXY integration
// return { message: 'Go Serverless v1.0! Your function executed successfully!', event };
};