question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expose generic type system for plugins

See original GitHub issue

Is 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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8

github_iconTop GitHub Comments

1reaction
ajotaoscommented, Apr 20, 2021

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.

0reactions
dotansimhacommented, Jul 12, 2021

Available in @envelop/core@0.4.0

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found