Last active
November 21, 2017 09:32
-
-
Save reyhansofian/6148b9158a4c989d32af37b009592dad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const { graphqlExpress, graphiqlExpress } = require('apollo-server-express'); | |
const bodyParser = require('body-parser'); | |
const bunyan = require('bunyan'); | |
const mysql = require('mysql2'); | |
const graphQLServer = express(); | |
const logger = bunyan.createLogger({ name: 'server' }); | |
const GRAPHQL_PORT = 3003; | |
const context = { | |
logger, | |
}; | |
const serverConfig = { | |
MYSQL_HOST: '192.168.99.100', | |
MYSQL_PORT: '32987', | |
MYSQL_USERNAME: 'root', | |
MYSQL_PASSWORD: 'secret', | |
MYSQL_DATABASE: 'test', | |
}; | |
const conn = mysql.createConnection({ | |
host: serverConfig.MYSQL_HOST, | |
port: serverConfig.MYSQL_PORT, | |
user: serverConfig.MYSQL_USERNAME, | |
password: serverConfig.MYSQL_PASSWORD, | |
database: serverConfig.MYSQL_DATABASE, | |
debug: true, | |
}); | |
conn.connect(); | |
graphQLServer.get('/test', (req, res) => { | |
const [rows] = conn.query('SELECT * FROM static_data'); | |
res.send(200); | |
}); | |
graphQLServer.listen(GRAPHQL_PORT, () => console.log( | |
`GraphiQL is now running on http://localhost:${GRAPHQL_PORT}/graphiql` | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment