-
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
Export graphqlKoa #2244
Export graphqlKoa #2244
Conversation
fe41c00
to
ac9f9c9
Compare
Being able to access graphqlKoa is useful for koa-based frameworks that don't expose the app object. This was previously exported in an earlier version of apollo-server and would be useful to export in the 2.x release as well. Here's an example of how we're currently consuming this: https://github.com/fusionjs/fusion-plugin-apollo-server/blob/90e95ef1480659073c7e4e042b75ea6205cc068f/src/server.js#L37
ac9f9c9
to
94ecd27
Compare
@KevinGrandon The problem with exporting I realize there is a need to expose integration points with frameworks like Koa, but with the current structure I'm afraid this isn't the way to do it. If |
@KevinGrandon hey, man. If would be awesome to get the old way of doing things in apollo koa. The linked issue already has > 50 upvotes, no response or interest from core team though. Maybe you'll be lucky to change this 😉🙏 |
@vladshcherbin Have you read my reply above? |
@martijnwalraven yeah, I've been tracking this change since v2 koa PR and finally I see the answer to it from core team member for the first time in several months. Hopefully, it'll be possible to export old middlewares with necessary changes (in koa or in core). |
@martijnwalraven Care to elaborate on this, please? To me, these assertions seem more like forced, conscious design choices on your front and less than |
@nfantone Of course these are design decisions, and they are more opinionated than before. There are good reasons for those changes however. Unlike the middleware functions exposed in v1, That doesn't mean I'm happy with the current integration API. We actually want future versions of Apollo Server to be less dependent on existing frameworks, by making the integration API more lightweight. This could very well work by exposing middlewares, as long as these have access to an The current |
I think the problem we're having is that creating a server is simple in Node. The expectation is that Apollo server can work as a Perhaps what we're not understanding is why these features prevent a middleware signature? |
None of this prevents a middleware signature! In fact, I strongly prefer a simple Exposing One strong requirement of whatever API we land on is that we need to be able to keep shared internal state between requests, to avoid repeated initialization of persisted queries and other configuration, to cache parsed documents, to keep an open connection with a Memcache cluster for data source and response caching, etc. To make this more concrete, a possible API for 3.0 might look like: import { GraphQLService } from "apollo-server";
import { graphqlEndpoint } from "apollo-server-koa";
const service = new GraphQLService(...)
const app = new Koa();
app.use(graphqlEndpoint(service)); |
@martijnwalraven Well... that last snippet looks pretty close to v1, doesn't it? Unless
I keep reading this argument and I honestly fail to see a compelling, solid reason behind it to support your design approach. I'd like to refer you to a comment I made a while back addressing exactly this and expanding on what I outlined in my previous paragraph. Here's an abstract:
Also,
Apart from built-in Engine, a private service behind a paywall, v1 had (and still has) all those things. |
@nfantone I'm all with you on If your objective is to integrate with an existing framework like Koa, I think you're right we can expect you to set up your own middleware stack, and you do need a certain amount of flexibility in that. A lightweight function like You shouldn't extrapolate too much from your own experience however. You'd be surprised how much of a stumbling block configuring a server has been for people (that was the main reason people started using GraphQL Yoga for example), so that's why we also want to offer an easy way to construct a stand alone The difference between the old middleware functions and the proposed
Your statement that v1 had all those things is simply false: while we offered persisted queries and caching, that relied on putting our closed source native proxy in front of your Apollo Server. What we did with v2 was to actually move these features into open source and make them available to everyone. I'm the first to admit that we made mistakes in the process, but I hope we can bring back some of the flexibility we lost while keeping the added convenience and efficiency a more opinionated design gives you. By encapsulating schema construction and GraphQL-specific request processing into a class like Another reason for this separation is that development and tooling workflows often require you to initialize a GraphQL service without starting up an entire server (or without starting up the same type of server that is used in production). Cleanly separating the GraphQL service from the server environment that it runs in gives us more flexibility in how services are used across development and deployment. |
It's okay if const graphQLService = new GraphQLService(...)
router
.get('/graphql', graphqlPlayground(graphQLService))
.post('/graphql', koaBody(), graphqlEndpoint(graphQLService)) For the other part of devs you can always export a full-featured, zero-config So, if the path is kinda clear, the real question is when should we wait for this changes? While |
@vladshcherbin Glad to hear you like the direction! I'm hoping we can make progress on this soon. Our plan is to get the core |
Exactly what @vladshcherbin said. @martijnwalraven Allow me to intertwine both your answers.
I agree on the extrapolation part. I probably shouldn't. The development ecosystem is vast and inviting newcomers and providing good initial experiences is a great goal to strive for. But the fact remains that by the time I learned about the new v2 API and came to this very repository, there were already people raising their concerns about the proposal - even before the original PR for a Koa implementation was merged. Today, while there isn't a single congruent place for this, #1308 (a petition to re-export middlewares) is one of the top ranked issues in the
Respectfully, I don't agree. I am currently running two (from @vladshcherbin)
I feel like this would be a smart approach. Build stuff from middlewares and export an optional fully featured server instance, already configured, constructed off of them. I'd love to see an approach where enabling/disabling features would require declaring a middleware: router
.post(
'/graphql',
koaBody(),
graphqlEndpoint(graphQLService),
graphqlCache(),
graphqlUpload()
/*, ... */
); |
Jumping over from being a long time watcher of #1308. I just want to say I agree with everything @nfantone and @vladshcherbin are asking for here. The suggested API above of
is all I would need to see to upgrade our current production servers from v1, and I think the apollo-boost analogy is a perfect way to address newcomers in setting up quickly. Being stuck on v1 is causing us several issues and i'm confident we are not the only ones, apologies for being largely a big fat +1 to this, but I'm excited to see some agreement, progress and discussion of the future API 👍 |
Obsoleted by #2435. |
#2435 finally landed in Apollo Server 2.9.0. 😄 Copying and pasting my comments from #1308 (comment):
|
@abernix is there a guide to create integration with custom framework ? |
Being able to access graphqlKoa is useful for koa-based frameworks that don't expose the app object. This was previously exported in an earlier version of apollo-server and would be useful to export in the 2.x release as well.
Here's an example of how we're currently consuming this: https://github.com/fusionjs/fusion-plugin-apollo-server/blob/90e95ef1480659073c7e4e042b75ea6205cc068f/src/server.js#L37