chore: Extract error handler and graphql instance to seperate files

This commit is contained in:
Faruk AYDIN
2021-10-05 18:34:40 +02:00
committed by Ali BARIN
parent 4039e520d6
commit c41d938f9e
3 changed files with 28 additions and 23 deletions

View File

@@ -0,0 +1,13 @@
import { Request, Response, NextFunction } from 'express';
import logger from './logger';
const errorHandler = (err: any, req: Request, res: Response, _next: NextFunction) => {
if(err.message === 'Not Found') {
res.status(404).end()
} else {
logger.error(err.message)
res.status(500).end()
}
}
export default errorHandler;

View File

@@ -0,0 +1,11 @@
import { graphqlHTTP } from 'express-graphql';
import rootResolver from '../graphql/root-resolver'
import graphQLSchema from '../graphql/graphql-schema'
const graphQLInstance = graphqlHTTP({
schema: graphQLSchema,
rootValue: rootResolver,
graphiql: true,
})
export default graphQLInstance;