-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (27 loc) · 948 Bytes
/
index.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
const express = require('express')
const { ApolloServer } = require('apollo-server-express')
const cors = require('cors')
const {
ApolloServerPluginLandingPageGraphQLPlayground
} = require('apollo-server-core');
// Load schema & resolvers
const typeDefs = require('./schema')
const resolvers = require('./resolver')
async function startApolloServer() {
const server = new ApolloServer({
typeDefs,
resolvers,
plugins: [
ApolloServerPluginLandingPageGraphQLPlayground(),
],
});
await server.start();
const app = express();
// Additional middleware can be mounted at this point to run before Apollo.
// Mount Apollo middleware here.
server.applyMiddleware({ app });
await new Promise(resolve => app.listen({ port: 4000 }, resolve));
console.log(`🚀 Server ready at http://localhost:4000${server.graphqlPath}`);
return { server, app };
}
startApolloServer();