chore: Integrate graphql to the express app
This commit is contained in:
@@ -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) {
|
||||
|
Reference in New Issue
Block a user