fastify-overview
fastify-overview copied to clipboard
feat: Provide a plugin's graph
Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the feature has not already been requested
🚀 Feature Proposal
Have the opportunity of visualize the plugins of a fastify application in a form of a graph to understand relationships and dependencies between plugins.
Motivation
From: https://github.com/fastify/help/issues/1018
Is there any way to specify which onClose (or preClose) hooks from each plugin should be executed before the others? I have some plugins that rely on other main plugins in order to execute correctly their onClose hooks.
E.G.: Some plugins need the database plugin in order to perform some cleaning operations on the database before closing the server. If the database plugin gets torn down before the plugin, the database client results disconnected.
Transferred from: https://github.com/fastify/fastify/issues/5375
Example
const fastify = require('fastify');
const dbPlugin = require('./my-db-plugin');
const otherPlugin = require('./my-other-plugin');
// my-db-plugin.js
async function plugin(instance, opts) {
fastify.decorate('database', mydbdriver);
fastify.addHook('onClose', async (app) => {
console.log('second');
// Let's say that my-other-plugin requires
// the database plugin to execute some cleanup work, whatever this could be
await app.database.close();
});
}
module.exports = fp(plugin, { name: ['database']});
// my-other-plugin.js
async function plugin(instance, opts) {
fastify.addHook('onClose', async (app) => {
console.log('first');
// Let's say that my-other-plugin requires
// the database plugin to execute some cleanup work, whatever this could be
await app.database.cleanup();
});
}
module.exports = fp(plugin, { name: 'other', dependencies: ['database']});
// index.js
// ... all the bootup process
await fastify.ready();
console.log(fastify.overview());
/** Just an illustrative example
{
"plugins": {
"my-other-plugin": {
"depends": {
"my-db-plugin": {
"depends": {}
}
}
}
}
}
*/
We could improve the actual layout by adding some references for sure. The data should be there!