feat: Convert helpers to use JS files

This commit is contained in:
Faruk AYDIN
2024-01-04 19:55:41 +01:00
parent 8819ddefa7
commit 85141812d9
48 changed files with 259 additions and 384 deletions

View File

@@ -0,0 +1,47 @@
import { join } from 'node:path';
import { graphqlHTTP } from 'express-graphql';
import { loadSchemaSync } from '@graphql-tools/load';
import { GraphQLFileLoader } from '@graphql-tools/graphql-file-loader';
import { addResolversToSchema } from '@graphql-tools/schema';
import { applyMiddleware } from 'graphql-middleware';
import appConfig from '../config/app';
import logger from './logger';
import authentication from './authentication';
import * as Sentry from './sentry.ee';
import resolvers from '../graphql/resolvers';
import HttpError from '../errors/http';
const schema = loadSchemaSync(join(__dirname, '../graphql/schema.graphql'), {
loaders: [new GraphQLFileLoader()],
});
const schemaWithResolvers = addResolversToSchema({
schema,
resolvers,
});
const graphQLInstance = graphqlHTTP({
schema: applyMiddleware(schemaWithResolvers, authentication),
graphiql: appConfig.isDev,
customFormatErrorFn: (error) => {
logger.error(error.path + ' : ' + error.message + '\n' + error.stack);
if (error.originalError instanceof HttpError) {
delete error.originalError.response;
}
Sentry.captureException(error, {
tags: { graphql: true },
extra: {
source: error.source?.body,
positions: error.positions,
path: error.path,
},
});
return error;
},
});
export default graphQLInstance;