-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_handler.js
More file actions
54 lines (48 loc) · 1.24 KB
/
api_handler.js
File metadata and controls
54 lines (48 loc) · 1.24 KB
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 express = require('express');
const app = express();
const { ApolloServer } = require('apollo-server-express');
const GraphQLDate=require('./graphqldate')
// file sync
const fs = require('fs');
// Issues
require('dotenv').config();
const about=require('./aboutmessage')
const issue=require('./issue')
const resolvers = {
Query: {
about:about.getaboutMessage ,
issueList:issue.issueList,
issueAdd:issue.issueAdd,
examplethrow: (_, { a, b }) => {
const val = a + b;
exports.val = val;
return a + b;
},
examplecatchfromquery: () => {
const { val } = exports;
return val;
},
},
Mutation: {
setAboutMessage:about.setAboutMessage,
examplecatchfrommutation: () => {
const { val } = exports;
return val;
},
},
GraphQLDate,
};
// INstantiating the ApolloServer
const server = new ApolloServer({
typeDefs: fs.readFileSync('schema.graphql', 'utf-8'),
resolvers,
formatError: (error) => {
console.log(error);
return error;
},
});
async function startServer() {
await server.start();
server.applyMiddleware({ app, path: '/graphql', cors: false });
}
module.exports=startServer;