Skip to content

Commit

Permalink
Auto-discover extensions (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
joostfarla authored Mar 15, 2024
1 parent b04a609 commit 0755ac2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package nl.geostandaarden.imx.orchestrate.ext.spatial;

import com.google.auto.service.AutoService;
import java.util.Set;
import nl.geostandaarden.imx.orchestrate.ext.spatial.geometry.GeometryTypeFactory;
import nl.geostandaarden.imx.orchestrate.model.OrchestrateExtension;
import nl.geostandaarden.imx.orchestrate.model.types.ValueTypeFactory;

@AutoService(OrchestrateExtension.class)
public final class SpatialExtension implements OrchestrateExtension {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
import nl.geostandaarden.imx.orchestrate.engine.OrchestrateEngine;
import nl.geostandaarden.imx.orchestrate.engine.source.Source;
import nl.geostandaarden.imx.orchestrate.engine.source.SourceType;
import nl.geostandaarden.imx.orchestrate.ext.spatial.SpatialExtension;
import nl.geostandaarden.imx.orchestrate.gateway.schema.SchemaFactory;
import nl.geostandaarden.imx.orchestrate.model.ComponentRegistry;
import nl.geostandaarden.imx.orchestrate.model.Model;
import nl.geostandaarden.imx.orchestrate.model.OrchestrateExtension;
import nl.geostandaarden.imx.orchestrate.model.loader.ModelLoader;
import nl.geostandaarden.imx.orchestrate.model.loader.ModelLoaderRegistry;
import nl.geostandaarden.imx.orchestrate.model.types.ValueTypeFactory;
Expand All @@ -41,7 +41,7 @@ public class GatewayConfiguration {

@Bean
public GraphQlSource graphQlSource() throws IOException {
var extensions = Set.of(new SpatialExtension());
var extensions = resolveExtensions();

var componentRegistry = new ComponentRegistry();
extensions.forEach(extension -> extension.registerComponents(componentRegistry));
Expand Down Expand Up @@ -84,6 +84,13 @@ public GraphQLSchema schema() {
};
}

private Set<OrchestrateExtension> resolveExtensions() {
return ServiceLoader.load(OrchestrateExtension.class)
.stream()
.map(ServiceLoader.Provider::get)
.collect(toUnmodifiableSet());
}

private Set<ModelLoader> resolveModelLoaders() {
return ServiceLoader.load(ModelLoader.class)
.stream()
Expand Down

0 comments on commit 0755ac2

Please sign in to comment.