Skip to content

chore: replaced apollo-server-express with @apollo/server in tests #1675

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

aryamohanan
Copy link
Contributor

@aryamohanan aryamohanan commented Apr 8, 2025

This PR removes the use of apollo-server-express and migrates the tests to @apollo/server, which is the officially supported package starting from Apollo Server v4.

Changes Made

  • Removed deprecated apollo-server-express package.
  • Added @apollo/server, @apollo/server/express4, and cors.
  • Replaced server.applyMiddleware({ app }) with:
    app.use('/graphql', cors(), expressMiddleware(server));
  • Added explicit CORS middleware configuration, as required in v4.

Notes

For reference and detailed migration steps, see the official guide:

🔗 https://www.apollographql.com/docs/apollo-server/migration#migrate-from-apollo-server-express

ref INSTA-780

await server.start();
server.applyMiddleware({ app });

app.use('/graphql', cors(), expressMiddleware(server));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

server.applyMiddleware({ app }) is removed in Apollo Server 4.

  • '/graphql' is the path for the GraphQL endpoint.
  • cors() handles CORS.
  • expressMiddleware(server) connects Apollo Server to Express.

CORS needs to be added explicitly before expressMiddleware in Apollo Server 4.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we suddenly need cors module?


const { useServer } = require('graphql-ws/use/ws');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the require statements to the top

app.get('/', (req, res) => {
res.sendStatus(200);
});

(async () => {
const { schema, executor } = await gateway.load();
const server = new ApolloServer({ schema, executor });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apollo Server v4 handles this automatically with gateway option and no longer supports the executor option. More details here.

@kirrg001
Copy link
Contributor

Do we know why apollo-server-express is not on our support page? We do list Apollo Subgraph and Apollo Federation.

@aryamohanan
Copy link
Contributor Author

Do we know why apollo-server-express is not on our support page? We do list Apollo Subgraph and Apollo Federation.

It's likely that it's mainly a helper library for integrating Apollo Server with Express, and not a core part of the architecture itself. Since we list Apollo Subgraph and Apollo Federation, which are the primary components used in our setup, apollo-server-express might have been considered too implementation-specific to include. This is what I think or it was intentionally omitted.

With the migration to Apollo Server v4—apollo no longer depends directly on Express or any specific HTTP framework. Instead, it introduces a core package—@apollo/server . I think it would make sense to update the support page to include @apollo/server and also currencies.json.

@kirrg001
Copy link
Contributor

I think it would make sense to update the support page to include @apollo/server and also currencies.json.

Agree

@@ -75,6 +75,7 @@
},
"devDependencies": {
"@apollo/gateway": "^2.10.1",
"@apollo/server": "^4.12.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting this here.
I still find usages in the code base for "apollo-server-express".

Copy link
Contributor

@kirrg001 kirrg001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💁‍♀️

@kirrg001
Copy link
Contributor

chore: replaced apollo-server-express with @apollo/server in tests #1675

feat: added support for @apollo/server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants