build schema in graphql folder not in index

This commit is contained in:
Ulf Gebhardt 2021-09-24 14:10:54 +02:00
parent 91849b5130
commit 4601c3df34
No known key found for this signature in database
GPG Key ID: 81308EFE29ABFEBD
2 changed files with 21 additions and 14 deletions

View File

@ -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<GraphQLSchema> => {
return buildSchema({
resolvers: resolvers(),
authChecker: isAuthorized,
})
}
export { schema }

View File

@ -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