refactor: Use graphql schema directly with graphql-tools library
This commit is contained in:

committed by
Ömer Faruk Aydın

parent
96cca96bff
commit
9926e5589e
@@ -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);
|
||||
|
Reference in New Issue
Block a user