Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Provide a plugin's graph #110

Open
2 tasks done
metcoder95 opened this issue Mar 31, 2024 · 1 comment
Open
2 tasks done

feat: Provide a plugin's graph #110

metcoder95 opened this issue Mar 31, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@metcoder95
Copy link

metcoder95 commented Mar 31, 2024

Prerequisites

  • I have written a descriptive issue title
  • 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: fastify/help#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: fastify/fastify#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": {}
        }
      }
    }
  }
}
*/
@Eomm
Copy link
Owner

Eomm commented Jul 12, 2024

We could improve the actual layout by adding some references for sure. The data should be there!

@Eomm Eomm added the enhancement New feature or request label Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants