MichalLytek / MichalLytek/type-graphql
Scoping middlewares
- Dominant language
- TypeScript
- Stars
- 8.1k
- Forks
- 672
- PR merge metrics
- No merged PRs in 30d
Description
Right now there are to ways to register a middleware:
- `@UseMiddleware` above the resolver method
- `globalMiddlewares` in `buildSchema`
In case of `@UseMiddleware` decorator, it should be possible to place in on the whole class to avoid manually placing on every method.
In case of global middlewares, it should be possible to register a global middleware that will be run:
- only once (e.g. dataloaders initialization)
- only in resolvers (query/mutation/subscription)
- only on advanced field resolvers (resolver's class method)
- only on simple field resolvers (getters, inline methods and simple fields)
and any combination of this possible options.
I have to investigate if the `@Middleware` decorator for class-based and `.scope` static property for function-based solution will be better than a detailed config object in `buildSchema`
In case of subscriptions, It should be also possible to choose if the middleware should be run only on subscribing, only on resolving the payload, or both.
This should also affect the `@Authorized` decorator which will be overwritten by a resolver's `@Authorized`, not concatenated like middlewares.
Contributor guide
Assessment
This issue has not been assessed yet.