-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
32 lines (27 loc) · 826 Bytes
/
server.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
require("dotenv").config();
const express = require("express");
const app = express();
const { ApolloServer } = require("apollo-server-express");
const dbConnection = require("./connection");
const typeDefs = require("./graphql/schema");
const resolvers = require("./graphql/resolvers");
const context = require("./graphql/context");
//graphql server
async function startServer() {
const apolloServer = new ApolloServer({
typeDefs,
resolvers,
formatError: (err) => err.message,
context: context,
});
await apolloServer.start();
apolloServer.applyMiddleware({ app });
}
startServer();
app.get("/", (req, res) => {
res.redirect("/graphql");
});
app.listen(process.env.PORT, async () => {
await dbConnection();
console.log(`🚀 Server is running at http://localhost:${process.env.PORT}`);
});