Since upgrading from apollo-server-express 2.4.2 to 2.4.8 I have two typing issues with the ApolloServer config used in the constructor:
1.) I can't use the "formatError" from the apollo-erros package (version1.9.0) anymore. I get this error:
Type聽'(error:聽any,聽returnNull?:聽boolean)聽=>聽ErrorInfo'聽is聽not聽assignable聽to聽type聽'(error:聽GraphQLError)聽=>聽GraphQLFormattedError'. 聽聽Type聽'ErrorInfo'聽is聽not聽assignable聽to聽type聽'GraphQLFormattedError'. 聽聽聽聽Property聽'locations'聽is聽optional聽in聽type聽'ErrorInfo'聽but聽required聽in聽type聽'GraphQLFormattedError'.
2.) I can't access the "connection" parameter anymore from the context creation function (it returns an "ExpressContext"). It's not a recognized parameter anymore.
But in the docs it's still the propesed way to create context for subscriptions: https://www.apollographql.com/docs/apollo-server/features/subscriptions.html#Context-with-Subscriptions
I have to stick with version 2.4.2 until this problem is resolved.
Thanks for any help.
Any chance that issue will be addressed? Thanks!
@abernix
Hi!
Can you please review my pullrequest at https://github.com/apollographql/apollo-server/pull/2959 concerning this issue? It's just a changed typing.
Thx!
Looks like you've reported two separate problems in one issue. In the future, it's best to separate those out, particularly since the PR you opened to fix them only fixes one of the two!
That said, could you please provide a small, runnable reproduction (even if it crashes) which demonstrates this. I haven't run into this problem yet, but I'm worried that adding an additional non-required connection property to this interface could be a breaking change for some. That way we can confirm the problem you're reporting is fixed.
Thanks!
@abernix You are right separating would be better, sorry for that :). I think we can forget about the formatErrors problem anyway, since apollo-errors package seems deprecated.
Concerning the pull request:
You can take the example from the docs:
https://www.apollographql.com/docs/apollo-server/features/subscriptions.html#Context-with-Subscriptions
const server = new ApolloServer({
schema,
context: async ({ req, connection }) => {
if (connection) {
// check connection for metadata
return connection.context;
} else {
// check from req
const token = req.headers.authorization || "";
return { token };
}
},
});
The current typings won't allow that because they don't know the connection parameter. It's not an error (in javascript it works fine), but the typescript transpiler won't let you pass.
any update on this? I tried to add the fix from the PR
export interface ExpressContext {
req: express.Request;
res: express.Response;
connection?: ExecutionParams;
}
idk where ExecutionParams was coming from and it doesn't exist
Should have been fixed by https://github.com/apollographql/apollo-server/pull/2959!
Most helpful comment
any update on this? I tried to add the fix from the PR
idk where ExecutionParams was coming from and it doesn't exist