-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Move TContext generic from requestDidStart method to ApolloServerPlugin Interface #3525
Conversation
@jdmoody: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/ |
7b7b996
to
e91029b
Compare
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.
Thanks for looking at this! Without re-creating a running example myself, I believe I understand why this is necessary (And while I'm almost certain that providing |
@abernix, as far as I can tell, there's no way to pass in a type argument to an Interface method when implementing that Interface. I think the type argument can only be passed in when calling
I initially tried something like this:
But this just defines a new generic called |
Yeah, this checks out on my end as a fix for something that's currently in a broken state. I recall running into a similar issue. Minimal reproduction @abernix: |
I've also encountered this problem about not being able to provide custom Context type to the plugin hook. This change also allows to use inline plugins: plugins: [
{
requestDidStart(requestContext: GraphQLRequestContext<Context>) {
return {
willSendResponse() {
console.log(requestContext.context.requestId);
},
};
},
},
], |
Bumping this for Monday, cc @abernix. |
It's worth noting that what @MichalLytek provided above does work and doesn't sacrifice any type safety from what I can tell — since Furthermore, if we couple this change to this declaration for
|
Co-Authored-By: Jesse Rosenberger <[email protected]>
Thanks again, @jdmoody! |
when to release the latest version? @abernix @trevor-scheer |
When using an ApolloServerPlugin with a different context, I get the following TypeScript error:
I believe this is due to annotating the
requestDidStart
context argument with a different context (in an attempt to get type-safety for the function):After this change, I'll be able to set the context on the plugin, instead:
If there's another way to accomplish this, please let me know! Thanks!