refactor: Use graphql schema directly with graphql-tools library

This commit is contained in:
Faruk AYDIN
2022-03-06 18:16:28 +03:00
committed by Ömer Faruk Aydın
parent 96cca96bff
commit 9926e5589e
48 changed files with 551 additions and 839 deletions

View File

@@ -1,11 +1,24 @@
import { graphqlHTTP } from 'express-graphql';
import graphQLSchema from '../graphql/graphql-schema';
import logger from '../helpers/logger';
import { applyMiddleware } from 'graphql-middleware';
import authentication from '../helpers/authentication';
import { join } from 'path';
import { loadSchemaSync } from '@graphql-tools/load';
import { GraphQLFileLoader } from '@graphql-tools/graphql-file-loader';
import { addResolversToSchema } from '@graphql-tools/schema';
import resolvers from '../graphql/resolvers';
const schema = loadSchemaSync(join(__dirname, '../graphql/schema.graphql'), {
loaders: [new GraphQLFileLoader()],
});
const schemaWithResolvers = addResolversToSchema({
schema,
resolvers,
});
const graphQLInstance = graphqlHTTP({
schema: applyMiddleware(graphQLSchema, authentication),
schema: applyMiddleware(schemaWithResolvers, authentication),
graphiql: true,
customFormatErrorFn: (error) => {
logger.error(error.path + ' : ' + error.message + '\n' + error.stack);