apollographql / apollo-server

🌍  Spec-compliant and production ready JavaScript GraphQL server that lets you develop in a schema-first way. Built for Express, Connect, Hapi, Koa, and more.
https://www.apollographql.com/docs/apollo-server/
MIT License
13.8k stars 2.03k forks source link

[breaking] Consider dropping built-in integration with Express v4 and replacing it with Express v5 #7928

Open joergbaier opened 2 months ago

joergbaier commented 2 months ago

@apollo/server has express v4 as a dependency. After several years, express is moving forward with releasing v5 (currently published as next tag). Having support for v5 here would unblock and encourage people to upgrade.

https://www.npmjs.com/package/express?activeTab=versions https://github.com/expressjs/express/releases/tag/v5.0.0

At this time, I have not checked for breaking changes in this repo, but wanted to open this issue to get things rolling. Any changes could be published under the next tag as well.

joergbaier commented 2 months ago

Typing updates for @types/express & @types/express-serve-static-core https://github.com/DefinitelyTyped/DefinitelyTyped/pull/70563

RobinTail commented 2 months ago

Breaking changes are listed in the migration guide, which is not yet up to date. Besides the listed changes there is also Node.js min supported version: 18. The primary feature is proper handling of asynchronous handlers.

glasser commented 2 months ago

I think it would be a good start if community members wanted to publish Express 5 integrations separately (perhaps under the @as-integrations npm org / apollo-server-integrations GitHub org)! While we could add a @apollo/server/express5 directory directly to Apollo Server, it might be challenging to do so in a way that uses different dependencies for two different parts of the same npm module, so getting this in core might be more likely a thing for the next major version of AS, which is not currently scheduled.

RobinTail commented 1 month ago

I made types. Enjoy :)

image

P4sca1 commented 1 month ago

I am using express5 beta with apollo server 4 for the past year without any problems. After upgrading @types/express and @types/express-serve-static-core to v5, I needed to override the version in apollo server to avoid type mismatches. e.g. for pnpm:

{
        "pnpm": {
                "overrides": {
                        "@types/express": "5.0.0",
                        "@types/express-serve-static-core": "5.0.0"
                }
        }
}
AndKiel commented 3 weeks ago

I tried upgrading to express v5 and it looks like apollo-server is incompatible. This check:

https://github.com/apollographql/apollo-server/blob/597f6e1cb7abc65282737ff46d3c008bc8384c25/packages/server/src/express4/index.ts#L47

is invalid because of the following breaking change:

The req.body property returns undefined when the body has not been parsed. In Express 4, it returns {} by default.

EDIT: I mainly wrote this comment because the one above said that the upgrade to beta worked without any problems.

glasser commented 3 weeks ago

I don't think it should be a big surprise that the code in the express4 directory does not work with Express 5.

The main interface for Apollo Server is the generic interface that works with any web server if you write a short adapter. Apollo Server does ship with one "first party" binding for the most popular and stable web framework, Express v4. But it's an explicit goal of the AS4 rewrite that it is not the job of Apollo Server itself to provide bindings to every web framework out there. That's how things worked in AS3 — the core project needed to have direct integrations to all supported web frameworks and there was no extensibility. In AS4 we provide a built-in integration with the most popular framework (Express v4) and community packages can provide integrations (typically about a page of code) with other frameworks.

It is likely that at some point in the future, Express v5 may be the most popular and stable web framework, but for today, that's still Express v4. So as mentioned above in https://github.com/apollographql/apollo-server/issues/7928#issuecomment-2354138374 I'd encourage folks on the cutting edge to put together a community package for @as-integrations/express5.

Perhaps Apollo Server v5 would incorporate that as its default and shift Express v4 to "community/external". But for now I would assume the place to start is with an integration.