chore: Integrate graphql to the express app

This commit is contained in:
Faruk AYDIN
2021-10-04 19:42:23 +02:00
committed by Ali BARIN
parent 7a675e6c79
commit 7d98333a8a
7 changed files with 76 additions and 15 deletions

View File

@@ -1,10 +1,12 @@
import appConfig from './config/app'
import createError from 'http-errors';
import express, { Request, Response, NextFunction } from 'express';
import { graphqlHTTP } from 'express-graphql';
import logger from './helpers/logger';
import morgan from './helpers/morgan';
import indexRouter from './routes/index';
import rootResolver from './graphql/root-resolver'
import graphQLSchema from './graphql/graphql-schema'
const app = express();
const port = appConfig.port;
@@ -13,7 +15,14 @@ app.use(morgan);
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use('/', indexRouter);
app.use(
'/graphql',
graphqlHTTP({
schema: graphQLSchema,
rootValue: rootResolver,
graphiql: true,
}),
);
// catch 404 and forward to error handler
app.use(function(req: Request, res: Response, next: NextFunction) {