Switch ApolloServerBase.schema from private access to protected access. #1610
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I am proposing this change after a scenario I came across. I essentially wanted to build my class that extends
ApolloServer
, and mimic the built-in support for graphql-middleware that graphql-yoga implements.My first implementation of that was done quickly in pure JS for Node (so, no TS) to explore the concept. In that case, of course, you can access anything in an object, so it was easy to do things like:
However, when I decided I wanted to refine this and make it a package, I switched to TypeScript.
So I had my class extending
ApolloServer
and my config extendingConfig
.And that's when I found out that I couldn't access
this.schema
to apply thegraphql-middlewares
after invoking the constructor of the superclass.Whilst I could work around that by building an executable schema that I then apply the middlewares to before passing it to the
ApolloServer
constructor, that defeats the whole point of extending the base class, because I will have to duplicate a good portion of code inApolloServerBase
around the setting up of the executable schema.I think it's fine for
schema
to be protected, and it will open up more possibilities for the subclasses.TODO: