feat: allow priority override when multiple SchemaGeneratorHooksProviders are registered#2173
Open
gaurav0107 wants to merge 1 commit into
Conversation
…ders are registered
Adds a backward-compatible `priority()` default method to the
`SchemaGeneratorHooksProvider` SPI (returns `0` by default) and teaches
both `generateSDL` and `generateGraalVmReflectMetadata` to pick the
provider with the strictly highest priority when more than one provider
is discovered through `ServiceLoader`.
Behaviour is preserved for existing users:
* zero providers still warn and fall back to `NoopSchemaGeneratorHooks`
* exactly one provider still wins unchanged
* multiple providers at the same (default) priority still fail fast,
keeping the legacy error prefix but now listing the tied class names
and priority so the conflict can be diagnosed.
Library authors that ship a provider which must override a transitively
imported one can now opt in by returning a positive value from
`priority()` instead of resorting to shade-plugin workarounds.
Closes ExpediaGroup#2150
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Description
Adds a backward-compatible
priority()default method to theSchemaGeneratorHooksProviderSPI (returns0by default) and teaches bothgenerateSDLandgenerateGraalVmReflectMetadatato pick the provider with the strictly highest priority when more than one provider is discovered throughServiceLoader.Behaviour preserved for existing users:
NoopSchemaGeneratorHooks."Cannot generate SDL as multiple SchemaGeneratorHooksProviders were found on the classpath"prefix but now also lists the tied class names and their priority so the conflict can be diagnosed without shade-plugin hacks.Opt-in path for library authors. A library that ships a
SchemaGeneratorHooksProviderwhich must override a transitively-imported one can now overridepriority()to return a positive value instead of telling consumers to exclude the upstream library.Scope.
SchemaGeneratorHooksProvider(source- and binary-compatible).whenblock inGenerateSDL.ktandGenerateGraalVmMetadata.ktwith a small package-localselectHooksProvider(providers, logger)helper in each module.A shared extraction into
graphql-kotlin-hooks-providerfelt out of scope for this change — both helpers are tiny and duplicating them keeps the SPI module dependency-free on SLF4J. Happy to hoist them if maintainers prefer.🔗 Related Issues
Closes #2150