move to using express instead of micro

This commit is contained in:
James Baxley 2018-04-09 12:26:54 -04:00 committed by Evans Hauser
parent f3bb8267fc
commit 4ed7e5d4f2
No known key found for this signature in database
GPG key ID: 88AF586817F52EEC
2 changed files with 10 additions and 35 deletions

View file

@ -27,9 +27,9 @@
"@types/cors": "^2.8.3",
"@types/express": "^4.11.1",
"@types/graphql": "^0.12.7",
"@types/micro": "^7.3.1",
"@types/microrouter": "^2.2.2",
"@types/hapi": "^17.0.9",
"@types/node": "^9.6.1",
"apollo-engine": "^1.0.6",
"typescript": "2.8.1"
},
"peerDependencies": {
@ -41,14 +41,13 @@
},
"dependencies": {
"apollo-server-express": "^1.3.4",
"apollo-server-hapi": "^1.3.4",
"apollo-server-micro": "^1.3.4",
"body-parser": "^1.18.2",
"cors": "^2.8.4",
"express": "^4.16.3",
"graphql-subscriptions": "^0.5.8",
"graphql-tools": "^2.23.1",
"micro": "^9.1.4",
"microrouter": "^3.1.1",
"subscriptions-transport-ws": "^0.9.7"
}
}

View file

@ -1,8 +1,8 @@
import micro, { send } from 'micro';
import * as express from 'express';
import * as cors from 'cors';
import { json } from 'body-parser';
import { microGraphiql, microGraphql } from 'apollo-server-micro';
import { get, post, router } from 'microrouter';
import { graphqlExpress, graphiqlExpress } from 'apollo-server-express';
import { Server as HttpServer } from 'http';
@ -11,36 +11,12 @@ import { ListenOptions, ServerInfo } from './types';
export * from './exports';
const applyMiddleware = (middleware, req, res) =>
new Promise(s => middleware(req, res, s));
import { ApolloServer as ExpressServer } from './express';
export class ApolloServer extends ApolloServerBase<HttpServer> {
export class ApolloServer extends ExpressServer {
constructor(opts) {
opts.app = express();
super(opts);
}
createApp(): HttpServer {
const graphql = microGraphql(this.request.bind(this));
const graphiql = (req, res) =>
microGraphiql({
endpointURL: '/graphql',
subscriptionsEndpoint: `ws://${req.headers.host}/graphql`,
})(req, res);
return micro(async (req, res) => {
// cors
await applyMiddleware(cors(), req, res);
// execute queries and serve graphiql
return router(
get('/graphql', graphql),
post('/graphql', graphql),
get('/graphiql', graphiql),
// XXX lets make a nice 404 page here
)(req, res);
});
}
getHttpServer(app) {
return app;
super.applyMiddleware();
}
}