Skip to content

generateSDL to handle multiple SchemaGeneratorHooksProviders found on the classpath #2150

@adambriny

Description

@adambriny

Is your feature request related to a problem? Please describe.

  • graphql-kotlin-sdl-generator uses ServiceLoader to find SchemaGeneratorHooksProvider, but only allows a single match.
  • Multiple SchemaGeneratorHooksProvider configured on the classpath (in META-INF/services/) makes the plugin throw an exception, no questions asked. The plugin does not provide a way set precedence for multiple matches.
  • If any library on the classpath (built on top of graphql-kotlin) defines SchemaGeneratorHooksProvider service, users have no choice but to exclude that library (or make an ugly workaround with the shade plugin) if they want to redefine it.

Describe the solution you'd like
To be able to set a clear precedence when multiple SchemaGeneratorHooksProviders are defined. I would propose a solution similar to the @Primary and @Order annotations of the Spring Framework. The library can define it's own annotations or can consider to support the javax.annotation.Priority as well.

Example implementation:

ServiceLoader.load(SchemaGeneratorHooksProvider::class.java)
    .maxByOrNull { it::class.findAnnotation<Priority>()?.value ?: 0 }

Describe alternatives you've considered
As an alternative, we could play around with the ClassLoader mechanism, maybe to prefer definitions from the current project over the ones coming from the libraries. I haven't looked into the feasibility of this idea, however.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions