-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose composed middleware via getMiddleware(). #2435
Conversation
Anyone have a sec for a review here? This would unblock us from integrating with fusion.js. @martijnwalraven / @benjamn |
ping @abernix - any comments? |
@ganemone Thank you so much for taking the time to put this together — I really respect this alternate approach and plan to get it in. That said, we need to try to main some API consistency across (at least our most popular) integrations), with Express being the most pressing. To maintain that consistency, I took the time to apply the same concept you've used here to To be clear, I think Express, Hapi and Koa are the main candidates here. Other integrations which already have a "handler" are already a bit more "exposed". Lastly, I'm tempted to call this exposed method |
@abernix - I included your changes into this PR. I also looked into hapi but I don't think this pattern makes much sense for hapi because of how hapi has multiple middleware stacks. Express and koa both have a single middleware stack so exposing a composed middleware makes a lot of sense. I understand the desire for API consistency, and this gets us closer to that, but I also think that things will never be 100% identical simply due to the fundamental differences between some of these underlying server abstractions. |
Thank you for this! 🎉 |
* Re-land "Expose composed middleware via getMiddleware()" This reverts commit d05aceb which was originally #2435, but was reverted in 52ab22e (#3046) as a precaution, prior to releasing 2.7.0. This attempts to reland it. * Use an `express.Router` rather than `compose-middleware`. Aside from avoiding unnecessary dependencies, by using this Router, we avoid the `apollo-server` base package from behaving different than it has in the past. Specifically, `apollo-server` uses `/` as the default path, but it does so in a wild-card way which serves GraphQL requests on _any_ path. That means that `/graphqlllll` and `/graphql` both also served the GraphQL Playground interface, and also responded to GraphQL execution requests. Since some may be leveraging that behavior, we should preserve it, if we can. * Add CHANGELOG.md link to #3184, for awareness.
Finally landed this in Apollo Server 2.9.0, with some adjustments. 😄 🎉 Copying and pasting my comments from #1308 (comment), since the proposal I mentioned is certainly a direction I see us going, and this seems like a good audience to float it by:
|
This PR exposes the composed koa middleware via the
server.getMiddleware()
function. This is useful for integrating with systems which may not expose the koa app directly such as Fusion.js. This is an alternative approach to try and resolve some comments on #2244