Last active
May 17, 2016 23:16
-
-
Save idkjs/b7960f963cc5f8b05a6e931b4f2371bc 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
import express from 'express'; | |
import schema from './data/schema'; | |
import GraphGQLHTTP from 'express-graphql'; | |
import {MongoClient} from 'mongodb'; | |
let app = express(); | |
app.use(express.static('public')); | |
/** | |
* ES7 Async Await Function | |
* Note: There is no callback on the ES7 version of 'let db ='. Await takes care of waiting for response | |
* and throwing its errors. | |
* Wrap the code with the async method in the async function with the => and call it with '()' immediately after | |
* because its an anonymous function or it wont do anything. | |
*/ | |
(async () => { | |
let db = await MongoClient.connect(process.env.MONGO_URL); | |
app.use('/graphql', GraphGQLHTTP({ | |
schema: schema(db), | |
graphiql: false | |
})); | |
app.listen(3000, () => console.log('Listening on port 3000')); | |
})(); | |
/** | |
ES6 Async | |
*/ | |
let db; | |
MongoClient.connect(process.env.MONGO_URL, (err, database) => { | |
if (err) throw err; | |
db = database; | |
app.use('/graphql', GraphGQLHTTP({ | |
schema: schema(db), | |
graphiql: false | |
})); | |
app.listen(3000, () => console.log('Listening on port 3000')); | |
}); | |
/** https://app.pluralsight.com/player?course=react-apps-with-relay-graphql-flux&author=samer-buna&name=react-apps-with-relay-graphql-flux-m5&clip=1&mode=live */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment