-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make AS/ASP invariant in TContext; move logger/cache to server in plu…
…gins (#6668) This change does two things, which we originally thought were kind of connected but maybe aren't. First, we switch the implementation of contravariance from a hacky `__forceTContextToBeContravariant` field to the new TS 4.7 variance annotations. But in fact, instead of making it contravariant, we make it invariant: `ApolloServer<X>` can only be assigned to `ApolloServer<Y>` when X and Y are the same. This is because: - An `ApolloServer<{foo: number}>` is not a `ApolloServer<{}>`, because you can invoke `executeOperation` on the latter with an empty context object, which would confuse the former (this is the contravariance we already had). - An `ApolloServer<{}>` is not a `ApolloServer<{foo: number}>`, because you can invoke `addPlugin` on the latter with a plugin whose methods expect to be called with a `contextValue` with `{foo: number}` on it, which isn't the case for the former. Considering the second condition is why this is now invariant (`in out`). We're not quite sure why TS couldn't figure this out for us, but it can't. Second, we add `server: ApolloServer` to various plugin hook arguments (`GraphQLRequestContext` and `GraphQLServerContext`). This makes `logger` and `cache` on `GraphQLRequestContext` somewhat redundant, so we make those fields into public readonly fields on `ApolloServer` and remove them from the plugin hook arguments. (We thought this was related to the other part because adding `server` appeared to require invariance instead of contravariance, but it turns out that we needed invariance anyway due to `addPlugin`.) Note that this means that anyone consuming our `.d.ts` files must be on TS4.7. Before v4.0.0 we'll probably fix that; see #6423. Fixes #6264. Fixes #6082.
- Loading branch information
Showing
13 changed files
with
121 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.