-
Notifications
You must be signed in to change notification settings - Fork 113
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
Apollo 4 support #2270
Comments
Example code: const application = createApplication({
modules: [echoModule]
});
const server = new ApolloServer(
{
schema: application.createSchemaForApollo()
}); To elaborate on a specific problem I bumped into: The Apollo Server 4 migration instructions suggest that It's not enough to work by itself though and the Apollo Server type definitions forbid passing more than |
Then it should work like; const application = createApplication({
modules: [echoModule]
});
new ApolloServer({
gateway: {
async load() {
return { executor: application.createApolloExecutor() };
},
onSchemaLoadOrUpdate() {
return () => {};
},
async stop() {},
},
}); |
I agree - that's what I expected to work, but it didn't in practice. Here's my minimal example - hopefully it's reproducible enough! |
Could you try the following code; const server = new ApolloServer({
// schema: application.createSchemaForApollo() // graphql-modules has marked this deprecated, but works with Apollo Server 4.
// Recommended approach is to use gateway:
gateway: {
async load() {
return { executor: application.createApolloExecutor() };
},
onSchemaLoadOrUpdate(callback) {
callback({ apiSchema: application.schema } as any);
return () => {};
},
async stop() {},
},
}); |
This does work, thanks - I try to write Typescript as strict as possible so it's not 100% ideal to have Without the
but I guess it's more of a question for Apollo and what that field is supposed to do / whether the typing should be as strict. |
@ardatan I had to drill into the source code to get understand that Gateway Interface. Thanks for that. |
It seems like there is still an issue, the apollo-server error functions do not like something about the gateway config setup. Here is my code: const server = new ApolloServer({
// See this issue for more info on this solution: https://github.com/Urigo/graphql-modules/issues/2270
// schema: application.createSchemaForApollo() // graphql-modules has marked this deprecated, but works with Apollo Server 4.
// Recommended approach is to use gateway:
gateway: {
async load() {
return { executor: moduleApp.createApolloExecutor() }
},
onSchemaLoadOrUpdate(callback) {
const apiSchema = { apiSchema: moduleApp.schema } as any
callback(apiSchema)
return () => {}
},
async stop() {}
},
formatError: (formattedError: GraphQLFormattedError, error: any) => {
console.log('FORMATTED ERROR -----> ', formattedError)
console.log('ERROR -----> ', error)
return formattedError
}
})
await server.start()
app.use(`${basePath}/graphql`, expressMiddleware(server)) It never seems to make it to the formatError function before blowing up when an error occurs. With the above setup you can simply query for a field that does not exist to generate the below errors... I receive the following errors:
Followed by:
any ideas? |
We would love to accept a PR to fix that, thank you! |
This works for Queries and Mutations. But I'm still getting this error when trying subscriptions
any help with implementing subscriptions with this gateway implementation. |
Is your feature request related to a problem? Please describe.
Hi guys, is there any plan to support the latest apollo server version 4?
tried this morning to have things working with @apollo/server 4.0.1 and graphql-modules 2.1.0 with no luck
The text was updated successfully, but these errors were encountered: