Skip to content

Commit

Permalink
fix: add client fetching to server
Browse files Browse the repository at this point in the history
  • Loading branch information
calebmer committed Apr 15, 2016
1 parent 2f72cb2 commit ea1e2e7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/createExpressServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from 'path'
import Express from 'express'
import logger from 'morgan'
import favicon from 'serve-favicon'
import pg from 'pg'
import { formatError } from 'graphql'
import graphql from 'express-graphql'

Expand All @@ -10,22 +11,24 @@ import graphql from 'express-graphql'
*
* @param {Object} config
* @param {GraphQLSchema} config.graphqlSchema
* @param {Object} config.pgConfig
* @param {string} config.route
* @param {boolean} config.development
* @returns {Server}
*/
const createServer = async ({ graphqlSchema, route, development }) => {
const createServer = async ({ graphqlSchema, pgConfig, route, development }) => {
const server = new Express()

server.use(logger(development ? 'dev' : 'common'))
server.use(favicon(path.join(__dirname, '../public/favicon.ico')))

server.use(route || '/', graphql({
server.use(route || '/', graphql(async () => ({
schema: graphqlSchema,
context: { client: await pg.connectAsync(pgConfig) },
pretty: development,
graphiql: development,
formatError: development ? developmentFormatError : formatError,
}))
})))

// Lol, we actually return an express server, but we might not in the
// future ;)
Expand Down
1 change: 1 addition & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const main = async () => {
// Create the GraphQL HTTP server.
const server = await createExpressServer({
graphqlSchema,
pgConfig,
route,
development,
})
Expand Down

0 comments on commit ea1e2e7

Please sign in to comment.