-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
49 lines (41 loc) · 1.25 KB
/
app.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
import express from 'express'
import bodyParser from 'body-parser'
import { graphqlExpress, graphiqlExpress } from 'apollo-server-express'
import { makeExecutableSchema } from 'graphql-tools'
// The GraphQL schema in string form
import typeDefs from './src/schema'
// The resolvers
import resolvers from './src/resolvers'
// The models
import models from './src/models'
// private info setup
require('dotenv').config()
const PORT = process.env.PORT || 5008
const ENDPOINT = process.env.ENDPOINT || '/graphql'
const SECRET = process.env.SECRET || 'sfgsfgtrewtgnasvksdafnvsdfkgnakfga'
const SECRET2 = process.env.SECRET2 || 'vnmvnbmioyiukhlhjeqwrewqzcxvczxvfgsd'
// Put together a schema
const schema = makeExecutableSchema({
typeDefs,
resolvers
})
const app = express()
app.use(bodyParser.json())
// The GraphQL endpoint && GraphiQL, a visual editor for queries
app.use(ENDPOINT, graphqlExpress({ schema,
context: {
models,
token: {
id: 1 // will be passed as a web token
},
SECRET,
SECRET2
}
}))
app.use('/graphiql', graphiqlExpress({ endpointURL: ENDPOINT }))
app.get('/', (req, res) => { res.send('WE ARE LIVE') })
models.sequelize.sync().then(() => {
app.listen(PORT, () => {
console.log(`Express is up on ${PORT}`)
})
})