-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphQL_handler.js
52 lines (46 loc) · 1.2 KB
/
graphQL_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
const fs = require('fs');
const { ApolloServer } = require('apollo-server-express');
const { getMusicInfo, searchMusic } = require('./music.js');
const { signup, login, getUserInfo, reCAPTCHAVerify } = require('./auth.js');
const { addPlaylist, deletePlaylist, addMusic, deleteMusic, editUser} = require('./userinfo.js');
const resolvers = {
Query: {
test: () => 'Hello world',
music: getMusicInfo,
searchMusic: searchMusic,
user: getUserInfo,
rcVerify: reCAPTCHAVerify,
},
Mutation: {
playlistAdd: addPlaylist,
signup: signup,
login: login,
userEdit: editUser,
playlistDelete: deletePlaylist,
musicAdd: addMusic,
musicDelete: deleteMusic,
},
};
const server = new ApolloServer({
typeDefs: fs.readFileSync('schema.graphql', 'utf-8'),
resolvers,
context: ({ req }) => {
return req;
},
formatError: err => {
console.log(err);
return err
},
introspection: true,
playground: true,
});
// cors setting
const cors = {
origin: process.env.CORS_ORIGIN || 'http://localhost:3000',
methods: 'POST',
credentials: true
}
function installHandler(app) {
server.applyMiddleware({ app, path: '/graphql', cors });
}
module.exports = { installHandler };