Skip to content

Instantly share code, notes, and snippets.

@barsumek
Created November 22, 2018 10:59
Show Gist options
  • Save barsumek/0c602869e0682ba98dd7e0da4722f401 to your computer and use it in GitHub Desktop.
Save barsumek/0c602869e0682ba98dd7e0da4722f401 to your computer and use it in GitHub Desktop.
Detox your GraphQL: Functions for starting the server
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