Skip to content
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

Typescript 4.7 support #4381

Closed
trevor-scheer opened this issue Apr 11, 2022 · 3 comments
Closed

Typescript 4.7 support #4381

trevor-scheer opened this issue Apr 11, 2022 · 3 comments

Comments

@trevor-scheer
Copy link
Contributor

Typescript 4.7 is still in beta but we'd like to start experimenting with it. graphql-tools currently doesn't build with the 4.7.0-beta version of typescript. There are presumably fixes that can be made now which will be forward compatible without actually updating the TS version here.

This PR looks like the cause of the majority of the issues when trying to build this repo using:
microsoft/TypeScript#48366

If we understand correctly, it seems like generics that don't have an extends <object type> which are passed into a function that have a generic which extends said object type is the root of the typescript errors that are popping up.

I'll open a PR with the failures and one of the fixes that I assume to be correct.

glasser added a commit to apollographql/apollo-server that referenced this issue Apr 11, 2022
Two things got a bit mixed together here.

One is that we want the Disabled plugins to all be defined directly in
plugin/index.ts, so that loading ApolloServerPluginInlineTraceDisabled
does not spend time loading the protobuf library.

The other thing is that we started thinking a bit more carefully about
plugin context generics. We wrote some tests to make sure that you can
use an `ApolloServerPlugin<BaseContext>` (ie, a plugin that doesn't need
any particular fields on the context) with any `ApolloServer`, but not
vice versa. As part of getting this to work, we added another
`__forceTContextToBeContravariant`. We also noticed that it made more
sense for BaseContext to be `{}` ("an object with no particular fields")
rather than `Record<string, any>` ("an object where you can do anything
with any of its fields").

We investigated whether the new contravariance annotation coming in the
next two months in TS 4.7
(microsoft/TypeScript#48240) would allow us to
get rid of the `__forceTContextToBeContravariant` hack and the answer is
yes! However, trying `4.7.0-beta` failed for two other reasons. One is
that microsoft/TypeScript#48366 required us to
add some missing `extends` clauses, which we are doing now in this PR.
The other is that `graphql-tools` needs some fixes to work with TS4.7
which we hope they can do soon
(ardatan/graphql-tools#4381).
@trevor-scheer
Copy link
Contributor Author

Fixed via #4382

@ardatan
Copy link
Owner

ardatan commented Apr 13, 2022

Thanks again for the PR <3 @trevor-scheer

@trevor-scheer
Copy link
Contributor Author

@ardatan you bet, thanks for the quick turnaround!

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

No branches or pull requests

2 participants