Type error in config of ApolloServer. 'resolvers' should accept an array of resolvers #1775
Labels
🌹 has-reproduction
❤ Has a reproduction in Glitch, CodeSandbox or Git repository.
🧬 typings
Relates to TypeScript changes or improvements.
I believe that there is a bug with the type definitions of the "config" interface passed to "ApolloServer".
According to the type definitions of the config interface, the field "resolvers" must be of type "IResolvers". However, an array of resolvers can also be passed, and the server will simply stitch all of the resolvers in the array.
When using JavaScript, this is not a problem since by default there is no type checking. However, when using TypeScript, we will get an error complaining about type miss-match and we won't be able to compile. A quick fix for this bug is to add
// @ts-ignore
.Intended outcome
I want to be able to use an array of resolvers when creating an ApolloServer instance with TypeScript.
Actual outcome
ApolloServer does not accept an array of resolvers. As a result, TypeScript will complain about this and will not compile. More information and an error message can be found below.
How to reproduce the issue
Simply pass an array of resolvers when creating an instance of ApolloServer when using TypeScript. See code example below for more details.
Code Example
The above code will work perfectly fine because we ignore the type checking of the config. However, if we remove
// @ts-ignore
, the application will no longer compile, and we will get the following error:Potential Solution
First, in types.ts we change the following line
resolvers?: IResolvers;
becomes:
resolvers?: IResolvers | Array<IResolvers>;
Second, in ApolloServer.ts we change the following line
if (resolvers && !resolvers.Upload) {
becomes:
if (resolvers && !(resolvers instanceof Array) && !resolvers.Upload) {
The text was updated successfully, but these errors were encountered: