chore: Extract error handler and graphql instance to seperate files
This commit is contained in:
13
packages/backend/src/helpers/error-handler.ts
Normal file
13
packages/backend/src/helpers/error-handler.ts
Normal 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;
|
11
packages/backend/src/helpers/graphql-instance.ts
Normal file
11
packages/backend/src/helpers/graphql-instance.ts
Normal 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;
|
Reference in New Issue
Block a user