You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In previous versions of Apollo, the ApolloServerPlugin did not extend anything. In the latest version the ApolloServerPlugin now extends AnyFunctionMap. This now requires any object that is being used as a plugin to be structured in a way that it only contains the required functions. Creating say a Typescript Class and passing an instance of the class as a plugin is now unsupported without workarounds.
My Plugin can be a Typescript Class with any variable such as a string or object
Actual Behavior
The type definition of ApolloServerPlugin requires each field to be a function or undefined.
Error if you try and use a class for a Plugin:
Type 'ApolloLogPlugin' is not assignable to type 'ApolloServerPlugin<Record<string, any>>'.
Index signature is missing in type 'ApolloLogPlugin'.
Sandbox
I made a quick sandbox, this is the class we have, but its a lot more complicated in our repo, as we are instantiating a common logger and passing it around a few ways. So this exact example isn't super important, other than to see that it fails without the type definition override.
(Note: I'm too familiar with code sandbox, and how to make it hot-reload with typescript. If you change any code, you might need to hit Restart Server in the sidebar)
Workaround
Add the following code to the top of the class to override the index definition from AnyFunctionMap
[key: string]: any;
See the commented line in loggerPlugin.ts in the sandbox for where this goes
The text was updated successfully, but these errors were encountered:
Sorry about that! Early in the v2.18 development process I was using ApolloServerPlugin with the Dispatcher class that requires this declaration but I stopped doing that. I'll get a v2.18.1 out ASAP that drops that extends declaration. Wish I had done this before release — it's the only reason that __internal_plugin_id__ is a function!
This `extends` declaration was added during the development of v2.18.0 for
reasons that turned out to be unnecessary. The declaration makes some
valid plugin implementation no longer type-check, so I'm removing it.
Fixes#4585.
haha, sounds good mate! No worries on it, that was a massive upgrade it looks like, with splitting things out and such. It happens =) I'm glad to hear it wasn't intentional, as we would have some re-thinking to do if it was.
Description
In previous versions of Apollo, the ApolloServerPlugin did not extend anything. In the latest version the ApolloServerPlugin now extends AnyFunctionMap. This now requires any object that is being used as a plugin to be structured in a way that it only contains the required functions. Creating say a Typescript Class and passing an instance of the class as a plugin is now unsupported without workarounds.
Package: apollo-server-plugin-base
Version: 0.10.0 (Latest as of September 2020)
PR that caused this: #4453
Change Diff: https://github.com/apollographql/apollo-server/pull/4453/files#diff-0f0cc848fe2c6442424f2ea0559f35ec
Expected Behavior
My Plugin can be a Typescript Class with
any
variable such as a string or objectActual Behavior
The type definition of ApolloServerPlugin requires each field to be a function or undefined.
Error if you try and use a class for a Plugin:
Sandbox
I made a quick sandbox, this is the class we have, but its a lot more complicated in our repo, as we are instantiating a common logger and passing it around a few ways. So this exact example isn't super important, other than to see that it fails without the type definition override.
https://codesandbox.io/s/crazy-wind-ee0m1
(Note: I'm too familiar with code sandbox, and how to make it hot-reload with typescript. If you change any code, you might need to hit Restart Server in the sidebar)
Workaround
Add the following code to the top of the class to override the index definition from AnyFunctionMap
See the commented line in loggerPlugin.ts in the sandbox for where this goes
The text was updated successfully, but these errors were encountered: