From 4601c3df345d4c9e0b33108f36387814a3e9e603 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Fri, 24 Sep 2021 14:10:54 +0200 Subject: [PATCH] build schema in graphql folder not in index --- backend/src/graphql/index.ts | 14 ++++++++++++++ backend/src/index.ts | 21 +++++++-------------- 2 files changed, 21 insertions(+), 14 deletions(-) create mode 100644 backend/src/graphql/index.ts diff --git a/backend/src/graphql/index.ts b/backend/src/graphql/index.ts new file mode 100644 index 000000000..a36d1dcdf --- /dev/null +++ b/backend/src/graphql/index.ts @@ -0,0 +1,14 @@ +import { GraphQLSchema } from 'graphql' +import { buildSchema } from 'type-graphql' + +import resolvers from './resolvers' +import { isAuthorized } from '../auth/auth' + +const schema = async (): Promise => { + return buildSchema({ + resolvers: resolvers(), + authChecker: isAuthorized, + }) +} + +export { schema } diff --git a/backend/src/index.ts b/backend/src/index.ts index 679221691..c6121aeee 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -3,7 +3,6 @@ import 'reflect-metadata' import express from 'express' import cors from 'cors' -import { buildSchema } from 'type-graphql' import { ApolloServer } from 'apollo-server-express' // config @@ -14,10 +13,7 @@ import connection from './typeorm/connection' import getDBVersion from './typeorm/getDBVersion' // graphql -import resolvers from './graphql/resolvers' - -// auth -import { isAuthorized } from './auth/auth' +import { schema } from './graphql' // TODO implement // import queryComplexity, { simpleEstimator, fieldConfigEstimator } from "graphql-query-complexity"; @@ -54,14 +50,6 @@ async function main() { ) } - const schema = await buildSchema({ - resolvers: resolvers(), - authChecker: isAuthorized, - }) - - // Graphiql interface - const playground = CONFIG.GRAPHIQL - // Express Server const server = express() @@ -89,7 +77,12 @@ async function main() { ] // Apollo Server - const apollo = new ApolloServer({ schema, playground, context, plugins }) + const apollo = new ApolloServer({ + schema: await schema(), + playground: CONFIG.GRAPHIQL, + context, + plugins, + }) apollo.applyMiddleware({ app: server }) // Start Server