-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.js
More file actions
35 lines (28 loc) · 867 Bytes
/
index.js
File metadata and controls
35 lines (28 loc) · 867 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
'use strict'
require('dotenv').config()
const { makeExecutableSchema } = require('graphql-tools')
const express = require('express')
const cors = require ('cors')
const { graphqlHTTP } = require('express-graphql')
const { readFileSync } = require('fs')
const { join } = require('path')
const resolvers = require ('./lib/resolvers')
const app = express()
const port = process.env.port || 3000
const isDev = process.env.NODE_ENV !== 'production'
const typeDefs = readFileSync(
join(__dirname, 'lib', 'schema.graphql'),
'utf-8'
)
const schema = makeExecutableSchema({
typeDefs, resolvers
})
app.use(cors())
app.use('/api', graphqlHTTP({
schema: schema,
rootValue: resolvers,
graphiql: isDev
}))
app.listen(port, () => {
console.log(`Server is listening at http://localhost:${port}/api`)
})