Expose generic type system for plugins
See original GitHub issueIs your feature request related to a problem? Please describe.
Currently, when creating the envelop with typescript there are some plugins that have no type information other than unknown, but they do return a Plugin<DefaultContext>
meaning they do have some extensibility potential.
By pain point is using useExtendedSchema
which has a function signature of (unknown) => unknown
so when I pass my typed function, it says it’s not compatible.
Describe the solution you’d like Expose type generics to extend the plugin and that they match the context type coming from envelop.
envelop<Context extends DefaultContext = DefaultContext>(options: {
plugins: Plugin<Context>[];
}) => Envelop<Context>;
useSchema<Context extends DefaultContext = DefaultContext>(schema: GraphQLSchema) => Plugin<Context>;
useExtendSchema<Context extends DefaultContext = DefaultContext, PrevContext extends DefaultContext = DefaultContext>(createContext: (PrevContext) => Context) => Plugin<Context>;
// It could even go like this, since the previous context is something the entire envelop will receive at some point
envelop<
Context extends DefaultContext = DefaultContext,
PrevContext extends DefaultContext = DefaultContext
>(options: {
plugins: Plugin<Context, PrevContext>[];
}) => Envelop<Context, PrevContext>;
useSchema<Context extends DefaultContext = DefaultContext, PrevContext extends DefaultContext = DefaultContext>(schema: GraphQLSchema) => Plugin<Context, PrevContext>;
useExtendSchema<Context extends DefaultContext = DefaultContext, PrevContext extends DefaultContext = DefaultContext>(createContext: (PrevContext) => PromiseLike<Context>) => Plugin<Context, PrevContext>;
// This could even help type
const {
parse,
validate,
contextFactory,
execute,
schema
} = getEnveloped();
contextFactory // (PrevContext) => PromiseLike<Context>
Describe alternatives you’ve considered
Using as
to cast the types but it’s not a very nice solution.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:8
Top Results From Across the Web
Generics Plugin System — Dioptra 0.0.0 documentation
Creating a new dispatch method for a generic is done by writing a Python function and adding a function decorator. Each generic exposes...
Read more >How to Build A Plugin System with TypeScript
Like the generic in the PluginTemplate class, this represents the object to be exposed to the plugins. Active plugins will be stored in...
Read more >How to expose a custom generic type as a string in Swagger ...
How can I avoid this and expose my type as a string? First solution attempted: using MapType. I tried to use MapType ;...
Read more >Build a Plugin System With Node.js - Fusebit
This generic type represents the plugin contract. Our example will describe the authorized actions that each plugin can perform. loadPlugin<T> ...
Read more >Implementing a generic/dynamic custom property system in ...
You're making a type system on top of the existing type system. ... each property the plugin exposes several accessors of different types ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Here for example, https://github.com/dotansimha/envelop/blob/5f27ea0439e3460e6d2b7da54b7995bdbd1f8761/packages/core/src/plugins/use-extend-context.ts#L5
That was the plugin that originally made me realize there was no exposed context type.
Available in
@envelop/core@0.4.0