-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
46 lines (40 loc) · 1.18 KB
/
main.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
const Koa = require('koa');
const { gql, ApolloServer,makeExecutableSchema } = require('apollo-server-koa');
const { importSchema } = require('graphql-import');
const fs = require('fs');
const path = require('path');
const query = require('./resolvers/query')
const mutation = require('./resolvers/mutation')
const db = require('./service/db');
const config = require('./config.js');
require('dotenv').config();
const app = new Koa();
const typeDefs = importSchema('./schema.graphql');
const resolvers = {
Person: {
__resolveType(obj, context, info){
if(obj.company){
return 'ExternalWorker';
}
return 'Employee';
},
},
Employee: {
salary: ({ salary }, { currency }) => currency === 'Euro' ? salary : salary * 1.14
},
Query: query,
Mutation: mutation,
};
const schema = makeExecutableSchema({
typeDefs,
resolvers,
resolverValidationOptions: { requireResolversForResolveType: false },
});
const server = new ApolloServer({
schema,
})
server.applyMiddleware({ app });
db.connect()
app.listen({ port: config.get('server.port') }, () =>
console.log(`🚀 Server ready at http://localhost:${config.get('server.port')}${server.graphqlPath}`),
);