Code tidy.

This commit is contained in:
Jayden Seric 2018-01-15 16:59:15 +11:00
parent b94f6c328b
commit 1aa945c986

View File

@ -3,36 +3,30 @@ import cors from 'kcors'
import compress from 'koa-compress' import compress from 'koa-compress'
import KoaRouter from 'koa-router' import KoaRouter from 'koa-router'
import koaBody from 'koa-bodyparser' import koaBody from 'koa-bodyparser'
import { makeExecutableSchema } from 'graphql-tools'
import { graphqlKoa } from 'graphql-server-koa'
import { apolloUploadKoa } from 'apollo-upload-server' import { apolloUploadKoa } from 'apollo-upload-server'
import types from './schema.mjs' import { graphqlKoa } from 'graphql-server-koa'
import { makeExecutableSchema } from 'graphql-tools'
import typeDefs from './schema.mjs'
import resolvers from './resolvers.mjs' import resolvers from './resolvers.mjs'
const server = new Koa() const app = new Koa()
const router = new KoaRouter() const router = new KoaRouter()
server
// Enable Cross-Origin Resource Sharing (CORS)
.use(cors())
// Enable gzip
.use(compress())
// GraphQL API
router.post( router.post(
'/graphql', '/graphql',
koaBody(), koaBody(),
apolloUploadKoa(), apolloUploadKoa(),
graphqlKoa({ graphqlKoa({ schema: makeExecutableSchema({ typeDefs, resolvers }) })
schema: makeExecutableSchema({ typeDefs: [types], resolvers })
})
) )
server.use(router.routes()).use(router.allowedMethods()) app
.use(cors())
server.listen(process.env.PORT, error => { .use(compress())
if (error) throw new Error(error) .use(router.routes())
.use(router.allowedMethods())
app.listen(process.env.PORT, error => {
if (error) throw error
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.info( console.info(
`Serving http://localhost:${process.env.PORT} for ${process.env.NODE_ENV}.` `Serving http://localhost:${process.env.PORT} for ${process.env.NODE_ENV}.`