1.0.0-alpha.22 • Published 6 years ago
@skimia/modules v1.0.0-alpha.22
GraphQL Modules with hooks !
Use this lib in same way using @graphql-modules/core (name is required !)
Hooks
const { GraphQLModule, hookWeight, HookProviderID } = require('@skimia/modules')
module.exports = new GraphQLModule({
name: 'MyModule',
hooks: {
http: [
// default no weight
(ctx, next) => {
ctx.injector.get('TOKEN')
// do anything
},
// weight 1000
hookWeight((ctx, next) => {
ctx.injector.get(HookProviderID) // get hook provider
// do anything
}, 1000),
],
},
})You can define infinite hook keys, http is used to configure an middleware based http app (koa, express,...), in same key hooks a sorted with ther weight ( without, assume 0 weight), Higher weight First
when using this lib on our module
- it add an import that handles the HookProvider (in order to be accessible from our module)
- add a provider to init HookProvider with module hooks
Config
async(originalConf) => ({})special config keyasync, function called during init of module in order to resolve asynchronously configurations (for module user)it enable for module user lazy config loading
preConfigHandler(originalConf + async) => ({})special module optionpreConfigHandler(on Module) do the same on module side (for module developer)can be used for injecting default values
(originalConf + async + configHandler) => boolspecial module optionconfigValidatorreturns true => ok, any other value => invalid configif no
configRequired = true&& no config passed => no validation!!postConfigHandler(originalConf + async) => ({})same aspreConfigHandlerbut after validationcan be used for doing treatment on config after validated
Utilities
- DI
injectable(options, class): @Injectable decorator functional equivalentinject(serviceID, class): @Inject decorator functional equivalentinjectConfig(moduleName, class): @Inject decorator with ModuleConfig functional equivalentmoduleConfig(moduleName): ModuleConfig config equivalent (module config injection token)
- Hooks
hookWeight(fn, weight): set the weight of hookhookFirst(fn): set the weight of hook => Number.POSITIVE_INFINITYhookLast(fn): set the weight of hook => Number.NEGATIVE_INFINITY
1.0.0-alpha.22
6 years ago
1.0.0-alpha.18
6 years ago
1.0.0-alpha.17
6 years ago
1.0.0-alpha.16
6 years ago
1.0.0-alpha.15
6 years ago
1.0.0-alpha.14
6 years ago
1.0.0-alpha.13
6 years ago
1.0.0-alpha.12
6 years ago
1.0.0-alpha.11
6 years ago
1.0.0-alpha.10
6 years ago
1.0.0-alpha.9
6 years ago
1.0.0-alpha.8
6 years ago
1.0.0-alpha.7
6 years ago
1.0.0-alpha.6
6 years ago