mirror of
https://github.com/vale981/apollo-server
synced 2025-03-06 10:11:40 -05:00
move to using express instead of micro
This commit is contained in:
parent
f3bb8267fc
commit
4ed7e5d4f2
2 changed files with 10 additions and 35 deletions
|
@ -27,9 +27,9 @@
|
||||||
"@types/cors": "^2.8.3",
|
"@types/cors": "^2.8.3",
|
||||||
"@types/express": "^4.11.1",
|
"@types/express": "^4.11.1",
|
||||||
"@types/graphql": "^0.12.7",
|
"@types/graphql": "^0.12.7",
|
||||||
"@types/micro": "^7.3.1",
|
"@types/hapi": "^17.0.9",
|
||||||
"@types/microrouter": "^2.2.2",
|
|
||||||
"@types/node": "^9.6.1",
|
"@types/node": "^9.6.1",
|
||||||
|
"apollo-engine": "^1.0.6",
|
||||||
"typescript": "2.8.1"
|
"typescript": "2.8.1"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
@ -41,14 +41,13 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"apollo-server-express": "^1.3.4",
|
"apollo-server-express": "^1.3.4",
|
||||||
|
"apollo-server-hapi": "^1.3.4",
|
||||||
"apollo-server-micro": "^1.3.4",
|
"apollo-server-micro": "^1.3.4",
|
||||||
"body-parser": "^1.18.2",
|
"body-parser": "^1.18.2",
|
||||||
"cors": "^2.8.4",
|
"cors": "^2.8.4",
|
||||||
"express": "^4.16.3",
|
"express": "^4.16.3",
|
||||||
"graphql-subscriptions": "^0.5.8",
|
"graphql-subscriptions": "^0.5.8",
|
||||||
"graphql-tools": "^2.23.1",
|
"graphql-tools": "^2.23.1",
|
||||||
"micro": "^9.1.4",
|
|
||||||
"microrouter": "^3.1.1",
|
|
||||||
"subscriptions-transport-ws": "^0.9.7"
|
"subscriptions-transport-ws": "^0.9.7"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import micro, { send } from 'micro';
|
import * as express from 'express';
|
||||||
import * as cors from 'cors';
|
import * as cors from 'cors';
|
||||||
|
import { json } from 'body-parser';
|
||||||
|
|
||||||
import { microGraphiql, microGraphql } from 'apollo-server-micro';
|
import { graphqlExpress, graphiqlExpress } from 'apollo-server-express';
|
||||||
import { get, post, router } from 'microrouter';
|
|
||||||
|
|
||||||
import { Server as HttpServer } from 'http';
|
import { Server as HttpServer } from 'http';
|
||||||
|
|
||||||
|
@ -11,36 +11,12 @@ import { ListenOptions, ServerInfo } from './types';
|
||||||
|
|
||||||
export * from './exports';
|
export * from './exports';
|
||||||
|
|
||||||
const applyMiddleware = (middleware, req, res) =>
|
import { ApolloServer as ExpressServer } from './express';
|
||||||
new Promise(s => middleware(req, res, s));
|
|
||||||
|
|
||||||
export class ApolloServer extends ApolloServerBase<HttpServer> {
|
export class ApolloServer extends ExpressServer {
|
||||||
constructor(opts) {
|
constructor(opts) {
|
||||||
|
opts.app = express();
|
||||||
super(opts);
|
super(opts);
|
||||||
}
|
super.applyMiddleware();
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue