-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
46 lines (37 loc) · 1.32 KB
/
index.ts
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
import dotenv from 'dotenv';
dotenv.config();
import { ApolloServer } from 'apollo-server-express';
import { makeExecutableSchema } from 'graphql-tools';
import { ApolloServerPluginDrainHttpServer, ApolloServerPluginLandingPageGraphQLPlayground } from 'apollo-server-core';
import { schemaDefs } from './schema';
import { resolvers } from './resolvers';
import http from 'http';
import { app } from './app';
import { initAppMiddleware } from './app';
import { GraphQLSchema } from 'graphql';
const PORT = process.env.PORT || 4000;
async function startApolloServer(schema: GraphQLSchema) {
const httpServer = http.createServer(app);
const server = new ApolloServer({
schema: schema,
plugins: [ApolloServerPluginDrainHttpServer({ httpServer }),
ApolloServerPluginLandingPageGraphQLPlayground]
});
await server.start();
server.applyMiddleware({
app,
path: '/graphql'
});
initAppMiddleware();
await new Promise<void>(resolve => httpServer.listen({ port: PORT }, resolve));
console.log(`🚀 Server ready at http://localhost:${PORT}${server.graphqlPath}`);
}
const schema = makeExecutableSchema({
typeDefs: schemaDefs,
resolvers,
});
startApolloServer(schema ).then( () => {
console.log('start server finished');
}).catch(err => {
console.error(err);
});