Skip to content

feat(core): define module registry and lifecycle hooks #27

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

Open
wants to merge 1 commit into
base: topic/kaialang-eng-1063-open-core-module-system-v1
Choose a base branch
from

Conversation

kaialang
Copy link

@kaialang kaialang commented May 12, 2025

Motivation and Context

This PR implements wundergraph#1063. The PR includes:

  • RegisterMyModule API and implementation
  • Hooks interfaces
  • Module initialization and hook registration

Checklist

  • I have discussed my proposed changes in an issue and have received approval to proceed.
  • I have followed the coding standards of the project.
  • Tests or benchmarks have been added or updated.
  • Documentation has been updated on https://github.com/wundergraph/cosmo-docs.
  • I have read the Contributors Guide.

Copy link

Router image scan failed

❌ Security vulnerabilities found in image:

ghcr.io/wundergraph/cosmo/router:sha-5b3c89b653c578fc6c27f6b33f0145cdcfa30742

Please check the security vulnerabilities found in the PR.

If you believe this is a false positive, please add the vulnerability to the .trivyignore file and re-run the scan.

Comment on lines +119 to +135
func (c *coreModules) initMyModules(ctx context.Context, modules []MyModuleInfo) error {
hookRegistry := newHookRegistry()

for _, info := range modules {
moduleInstance := info.New()

hookRegistry.AddApplicationLifecycle(moduleInstance)
hookRegistry.AddGraphQLServerLifecycle(moduleInstance)
hookRegistry.AddRouterLifecycle(moduleInstance)
hookRegistry.AddSubgraphLifecycle(moduleInstance)
hookRegistry.AddOperationLifecycle(moduleInstance)
}

c.hookRegistry = hookRegistry

return nil
}
Copy link

@yuzoonc1 yuzoonc1 May 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that all of my modules will be registered to all lifecycles? doesn't this mean that these modules will run on all hooks and there is no flexibility if I want to register my module on specific hook? Maybe MyModuleInfo should have a field that represents a list of hooks that you want this module to be registered and run on.

Let me know if I am not understanding things correctly.

for _, m := range r.modules {
modules = append(modules, m)
}
return sortMyModules(modules)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess is that this will be called from each hook to get the list of modules to run?

I wonder if we can have a data structure that keeps lifecycle/hook to modules mapping (or update moduleRegistry to have that mapping), and sort the module order on register time so that we don't have to sort on hook runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants