@skimia/modules
v1.0.0-alpha.22
Published
Use this lib in same way using `@graphql-modules/core` (name is required !)
Downloads
8
Readme
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) => bool
special module optionconfigValidator
returns true => ok, any other value => invalid configif no
configRequired = true
&& no config passed => no validation!!postConfigHandler(originalConf + async) => ({})
same aspreConfigHandler
but 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