Created
November 22, 2018 10:59
-
-
Save barsumek/0c602869e0682ba98dd7e0da4722f401 to your computer and use it in GitHub Desktop.
Detox your GraphQL: Functions for starting the server
This file contains hidden or 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 PORT = 8089; | |
let graphQLServerApp; | |
let httpServer; | |
function startHttpServer() { | |
return new Promise(resolve => { | |
httpServer = graphQLServerApp.listen(PORT, () => { | |
resolve(); | |
}); | |
}); | |
} | |
async function startGraphQLServer(mock = {}) { | |
if (httpServer) { | |
console.warn("Tried to start HTTP server, when there's already one."); | |
return; | |
} | |
graphQLServerApp = express(); | |
const server = createServerWithMockedSchema(mock); | |
server.applyMiddleware({ | |
app: graphQLServerApp | |
}); | |
// we want to wait for the server to start listening | |
await startHttpServer(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment