-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
51 lines (37 loc) · 1.23 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
49
50
51
const express = require('express')
const app = express()
const cors = require('cors')
const swaggerUi = require('swagger-ui-express')
/* Libraries for GraphQL */
const { makeExecutableSchema } = require('graphql-tools')
const { graphqlHTTP } = require('express-graphql')
const { readFileSync } = require('fs')
const { join } = require('path')
const resolvers = require('./graphql/resolvers')
const newsRoute = require('./routes/news')
const { port } = require('./config/config')
const { logError, errorHandler } = require('./utils/middlewares/errorHandler')
const swaggerDoc = require('./swagger.json')
/* Define Graphql schema */
const typeDefs = readFileSync(
join(__dirname, 'graphql', 'schema.graphql'), 'utf-8'
)
const schema = makeExecutableSchema({ typeDefs, resolvers })
/* Middlewares execute */
app.use(express.json())
app.use(cors())
// app.use('/api/news', )
newsRoute(app)
app.use('/search', graphqlHTTP({
schema: schema,
rootValue: resolvers,
graphiql: true
}))
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDoc))
app.use(logError) // Error Handlers
app.use(errorHandler) // Error Handlers
// Where listen the server?
app.listen(port, () => {
console.log(`App listen on ${port}`)
})
module.exports = app