Skip to content

feat: allow priority override when multiple SchemaGeneratorHooksProviders are registered#2173

Open
gaurav0107 wants to merge 1 commit into
ExpediaGroup:masterfrom
gaurav0107:fix/2150-generatesdl-to-handle-multiple-schemagen
Open

feat: allow priority override when multiple SchemaGeneratorHooksProviders are registered#2173
gaurav0107 wants to merge 1 commit into
ExpediaGroup:masterfrom
gaurav0107:fix/2150-generatesdl-to-handle-multiple-schemagen

Conversation

@gaurav0107
Copy link
Copy Markdown
Contributor

📝 Description

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 preserved for existing users:

  • Zero providers still warn and fall back to NoopSchemaGeneratorHooks.
  • Exactly one provider still wins unchanged.
  • Multiple providers at the same priority still fail fast. The error message keeps the legacy "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 SchemaGeneratorHooksProvider which must override a transitively-imported one can now override priority() to return a positive value instead of telling consumers to exclude the upstream library.

Scope.

  • SPI: adds a default method to SchemaGeneratorHooksProvider (source- and binary-compatible).
  • Call sites: replaces the inline when block in GenerateSDL.kt and GenerateGraalVmMetadata.kt with a small package-local selectHooksProvider(providers, logger) helper in each module.
  • Tests: adds unit tests for the new selection helper in both modules (single-provider passthrough, highest-priority wins, same-priority tie throws with descriptive message).

A shared extraction into graphql-kotlin-hooks-provider felt 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

…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
@gaurav0107 gaurav0107 marked this pull request as ready for review May 14, 2026 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

generateSDL to handle multiple SchemaGeneratorHooksProviders found on the classpath

1 participant