import http from 'http';
import express from 'express';
import bodyParser from 'body-parser';
import cors from 'cors';
import { makeExecutableSchema } from 'graphql-tools';
import { graphqlExpress } from 'apollo-server-express';
import graphqlPlayground from 'graphql-playground-middleware-express';
import { graphqlSchema, graphqlResolvers } from './graphql';
import config from './constants/config';

const app = express();
app.server = http.createServer(app);

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cors());

const executableSchema = makeExecutableSchema({
  typeDefs: [graphqlSchema],
  resolvers: graphqlResolvers,
});

app.use(
  '/graphql',
  bodyParser.json(),
  graphqlExpress({
    schema: executableSchema,
    formatError: error => ({
      message: error.message,
      path: error.path,
    }),
    tracing: true,
  }),
);

app.get('/playground', graphqlPlayground({ endpoint: '/graphql' }));

app.get('/', (req, res) => res.redirect('/playground'));

app.server.listen(process.env.PORT || config.server.port);
// eslint-disable-next-line no-console
console.log(`🚀  Server listening on port ${app.server.address().port}...`);

@@ -809,21 +809,31 @@
 ge: 
-error.message
+'Internal Server Error'
 ,%0A  

Mask internal server errors