graphbrainz/src/index.js

25 lines
572 B
JavaScript
Raw Normal View History

2016-08-08 07:54:06 +00:00
import express from 'express'
import graphqlHTTP from 'express-graphql'
import schema from './schema'
2016-08-20 05:59:32 +00:00
import { lookupLoader, browseLoader, searchLoader } from './loaders'
2016-08-08 07:54:06 +00:00
const app = express()
app.use('/graphql', graphqlHTTP({
schema,
2016-08-20 05:59:32 +00:00
context: { lookupLoader, browseLoader, searchLoader },
pretty: true,
2016-08-08 07:54:06 +00:00
graphiql: true,
formatError: error => ({
message: error.message,
locations: error.locations,
stack: error.stack
})
}))
2016-08-20 05:59:32 +00:00
app.get('/graphiql', (req, res) => {
res.redirect(`/graph${req.url.slice(7)}`)
})
app.listen(process.env.PORT || 3001)