-
Notifications
You must be signed in to change notification settings - Fork 37
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
base: main
Are you sure you want to change the base?
Conversation
await server.start(); | ||
server.applyMiddleware({ app }); | ||
|
||
app.use('/graphql', cors(), expressMiddleware(server)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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 }); |
There was a problem hiding this comment.
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.
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. |
Agree |
@@ -75,6 +75,7 @@ | |||
}, | |||
"devDependencies": { | |||
"@apollo/gateway": "^2.10.1", | |||
"@apollo/server": "^4.12.0", |
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💁♀️
feat: added support for @apollo/server |
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
apollo-server-express
package.@apollo/server
,@apollo/server/express4
, andcors
.server.applyMiddleware({ app })
with: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