-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
37 lines (26 loc) · 765 Bytes
/
server.js
File metadata and controls
37 lines (26 loc) · 765 Bytes
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
import express from 'express';
import { ApolloServer, gql } from 'apollo-server-express';
import cors from 'cors';
import dotEnv from 'dotenv';
import typeDefs from './typeDefs';
import resolvers from './resolvers';
// env config
dotEnv.config();
const app = express();
// setup cors
app.use(cors());
// body parser middleware
app.use(express.json({ extended: false }));
const apolloServer = new ApolloServer({
typeDefs,
resolvers,
});
apolloServer.applyMiddleware({ app, path: '/graphql' });
const PORT = process.env.PORT || 3000;
app.use('/', (req, res, next) => {
res.send({ message: 'Hello' });
});
app.listen(PORT, () => {
console.log(`Server listening at Port: ${PORT}`);
console.log(`Graphql Endpoint: ${apolloServer.graphqlPath}`);
});