| 39 | */ |
| 40 | |
| 41 | const startTestServer = async server => { |
| 42 | // if using apollo-server-express... |
| 43 | // const app = express(); |
| 44 | // server.applyMiddleware({ app }); |
| 45 | // const httpServer = await app.listen(0); |
| 46 | |
| 47 | const httpServer = await server.listen({ port: 0 }); |
| 48 | |
| 49 | const link = new HttpLink({ |
| 50 | uri: `http://localhost:${httpServer.port}`, |
| 51 | fetch, |
| 52 | }); |
| 53 | |
| 54 | const executeOperation = ({ query, variables = {} }) => |
| 55 | execute(link, { query, variables }); |
| 56 | |
| 57 | return { |
| 58 | link, |
| 59 | stop: () => httpServer.server.close(), |
| 60 | graphql: executeOperation, |
| 61 | }; |
| 62 | }; |
| 63 | |
| 64 | module.exports.startTestServer = startTestServer; |