2016-10-10 18:37:26 +03:00
|
|
|
const express = require('express');
|
2017-09-20 12:30:53 +03:00
|
|
|
const graphqlHTTP = require('express-graphql');
|
2017-09-14 14:26:57 +03:00
|
|
|
const cors = require('cors');
|
2016-10-10 18:37:26 +03:00
|
|
|
|
2017-09-20 12:30:53 +03:00
|
|
|
const schema = require('./schema');
|
|
|
|
|
2016-10-10 18:37:26 +03:00
|
|
|
const app = express();
|
|
|
|
|
2017-09-14 14:26:57 +03:00
|
|
|
app.use(cors());
|
|
|
|
app.options('*', cors());
|
|
|
|
|
2017-09-20 12:30:53 +03:00
|
|
|
app.post(
|
|
|
|
'/graphql',
|
|
|
|
graphqlHTTP({
|
|
|
|
schema,
|
|
|
|
graphiql: false
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
app.get(
|
|
|
|
'/graphql',
|
|
|
|
graphqlHTTP({
|
|
|
|
schema,
|
|
|
|
graphiql: true
|
|
|
|
})
|
|
|
|
);
|
2016-10-10 18:37:26 +03:00
|
|
|
|
2017-04-27 21:26:15 +03:00
|
|
|
const server = app.listen(4000, err => {
|
2016-10-10 18:37:26 +03:00
|
|
|
if (err) {
|
2017-05-18 21:21:33 +03:00
|
|
|
// eslint-disable-next-line no-console
|
2017-04-27 21:26:15 +03:00
|
|
|
console.error(err);
|
2016-10-10 18:37:26 +03:00
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
2017-05-18 21:21:33 +03:00
|
|
|
// eslint-disable-next-line no-console
|
2017-04-27 21:26:15 +03:00
|
|
|
console.log(`Listening at http://0.0.0.0:${server.address().port}/graphql`);
|
2016-10-10 18:37:26 +03:00
|
|
|
});
|