index.js 467 B

12345678910111213141516171819202122
  1. import { Schema } from './schema.js';
  2. import graphqlHTTP from 'express-graphql';
  3. import express from 'express';
  4. import cors from 'cors';
  5. import bodyParser from 'body-parser';
  6. const app = express();
  7. app.use(cors());
  8. app.get('/', function (req, res) {
  9. res.redirect('/graphql');
  10. });
  11. app.use('/graphql', bodyParser.json(), graphqlHTTP({
  12. schema: Schema,
  13. graphiql: true
  14. }));
  15. app.listen(3000);
  16. console.log('Go to http://localhost:3000/graphql to run queries!');