-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (36 loc) · 1.14 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import express from 'express';
import dotenv from 'dotenv';
import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.mjs';
import { ApolloServer } from 'apollo-server-express';
import cors from 'cors';
import { databaseConnection } from './config/databaseConnection.js';
dotenv.config();
import typeDefs from './types/index.js';
import resolvers from './resolvers/index.js';
const app = express();
app.use(cors());
app.use(graphqlUploadExpress());
const PORT = process.env.PORT || 4000;
const DATABASE_URL = process.env.DATABASE_URL;
const DATABASE_NAME = process.env.DATABASE_NAME;
const startServer = async() => {
const server = new ApolloServer({
typeDefs,
resolvers,
uploads: true,
context: ({ req }) => {
return {
headers: req.headers,
}
}
});
await server.start();
server.applyMiddleware({ app });
app.use(graphqlUploadExpress());
databaseConnection(DATABASE_URL, DATABASE_NAME);
app.listen(PORT, () => {
console.log(`Server is running at http://localhost:${PORT}`);
console.log(`GraphQL endpoint: http://localhost:${PORT}${server.graphqlPath}`);
})
};
startServer();