Skip to content
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

Use @ConfigMapping in SmallRye extensions #45757

Merged
merged 5 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions extensions/smallrye-graphql/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-AlegacyConfigRoot=true</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,9 @@ void buildExecutionService(
Optional<GraphQLDevUILogBuildItem> graphQLDevUILogBuildItem) {

activateFederation(graphQLConfig, systemPropertyProducer, graphQLFinalIndexBuildItem);
graphQLConfig.extraScalars.ifPresent(this::registerExtraScalarsInSchema);
graphQLConfig.extraScalars().ifPresent(this::registerExtraScalarsInSchema);
Schema schema = SchemaBuilder.build(graphQLFinalIndexBuildItem.getFinalIndex(),
Converters.getImplicitConverter(TypeAutoNameStrategy.class).convert(graphQLConfig.autoNameStrategy));
Converters.getImplicitConverter(TypeAutoNameStrategy.class).convert(graphQLConfig.autoNameStrategy()));

Optional publisher = Optional.empty();
if (graphQLDevUILogBuildItem.isPresent()) {
Expand Down Expand Up @@ -402,10 +402,10 @@ void buildSchemaEndpoint(
SmallRyeGraphQLConfig graphQLConfig) {

Handler<RoutingContext> schemaHandler = recorder.schemaHandler(graphQLInitializedBuildItem.getInitialized(),
graphQLConfig.schemaAvailable);
graphQLConfig.schemaAvailable());

routeProducer.produce(httpRootPathBuildItem.routeBuilder()
.nestedRoute(graphQLConfig.rootPath, SCHEMA_PATH)
.nestedRoute(graphQLConfig.rootPath(), SCHEMA_PATH)
.handler(schemaHandler)
.displayOnNotFoundPage("MicroProfile GraphQL Schema")
.build());
Expand Down Expand Up @@ -449,12 +449,12 @@ void buildExecutionEndpoint(
runBlocking);

HttpRootPathBuildItem.Builder subscriptionsBuilder = httpRootPathBuildItem.routeBuilder()
.orderedRoute(graphQLConfig.rootPath, GRAPHQL_WEBSOCKET_HANDLER_ORDER)
.orderedRoute(graphQLConfig.rootPath(), GRAPHQL_WEBSOCKET_HANDLER_ORDER)
.handler(graphqlOverWebsocketHandler);
routeProducer.produce(subscriptionsBuilder.build());

// WebSocket subprotocols
graphQLConfig.websocketSubprotocols.ifPresentOrElse(subprotocols -> {
graphQLConfig.websocketSubprotocols().ifPresentOrElse(subprotocols -> {
for (String subprotocol : subprotocols) {
if (!SUPPORTED_WEBSOCKET_SUBPROTOCOLS.contains(subprotocol)) {
throw new IllegalArgumentException("Unknown websocket subprotocol: " + subprotocol);
Expand All @@ -479,7 +479,7 @@ void buildExecutionEndpoint(
allowGet, allowQueryParametersOnPost, runBlocking, allowCompression);

HttpRootPathBuildItem.Builder requestBuilder = httpRootPathBuildItem.routeBuilder()
.routeFunction(graphQLConfig.rootPath, recorder.routeFunction(bodyHandlerBuildItem.getHandler()))
.routeFunction(graphQLConfig.rootPath(), recorder.routeFunction(bodyHandlerBuildItem.getHandler()))
.handler(executionHandler)
.routeConfigKey("quarkus.smallrye-graphql.root-path")
.displayOnNotFoundPage("MicroProfile GraphQL Endpoint");
Expand Down Expand Up @@ -516,8 +516,8 @@ private Set<String> getAdapterClasses(IndexView index, DotName adapterClass) {
}

private boolean shouldRunBlockingRoute(SmallRyeGraphQLConfig graphQLConfig) {
if (graphQLConfig.nonBlockingEnabled.isPresent()) {
return !graphQLConfig.nonBlockingEnabled.get();
if (graphQLConfig.nonBlockingEnabled().isPresent()) {
return !graphQLConfig.nonBlockingEnabled().get();
}
return false;
}
Expand Down Expand Up @@ -647,13 +647,13 @@ void printDataFetcherExceptionInDevMode(SmallRyeGraphQLConfig graphQLConfig,
BuildProducer<SystemPropertyBuildItem> systemProperties) {

// User did not set this explicitly
if (!graphQLConfig.printDataFetcherException.isPresent()) {
if (!graphQLConfig.printDataFetcherException().isPresent()) {
if (launchMode.getLaunchMode().isDevOrTest()) {
systemProperties.produce(new SystemPropertyBuildItem(ConfigKey.PRINT_DATAFETCHER_EXCEPTION, TRUE));
}
} else {
systemProperties.produce(new SystemPropertyBuildItem(ConfigKey.PRINT_DATAFETCHER_EXCEPTION,
String.valueOf(graphQLConfig.printDataFetcherException.get())));
String.valueOf(graphQLConfig.printDataFetcherException().get())));
}
}
// Services Integrations
Expand All @@ -664,7 +664,7 @@ void activateMetrics(Capabilities capabilities,
SmallRyeGraphQLConfig graphQLConfig,
BuildProducer<SystemPropertyBuildItem> systemProperties, BuildProducer<ServiceProviderBuildItem> serviceProvider) {

if (graphQLConfig.metricsEnabled.orElse(false)
if (graphQLConfig.metricsEnabled().orElse(false)
|| Config.get().getConfigValue(ConfigKey.ENABLE_METRICS, boolean.class, false)) {
metricsCapability.ifPresentOrElse(capability -> {
if (capability.metricsSupported(MetricsFactory.MICROMETER)) {
Expand All @@ -689,7 +689,7 @@ void activateTracing(Capabilities capabilities,
BuildProducer<SystemPropertyBuildItem> systemProperties,
BuildProducer<UnremovableBeanBuildItem> unremovableBeans) {

boolean activate = shouldActivateService(graphQLConfig.tracingEnabled,
boolean activate = shouldActivateService(graphQLConfig.tracingEnabled(),
capabilities.isPresent(Capability.OPENTELEMETRY_TRACER),
"quarkus-opentelemetry",
Capability.OPENTELEMETRY_TRACER,
Expand All @@ -704,7 +704,7 @@ void activateTracing(Capabilities capabilities,

@BuildStep
void activateEventing(SmallRyeGraphQLConfig graphQLConfig, BuildProducer<SystemPropertyBuildItem> systemProperties) {
if (graphQLConfig.eventsEnabled) {
if (graphQLConfig.eventsEnabled()) {
systemProperties.produce(new SystemPropertyBuildItem(ConfigKey.ENABLE_EVENTS, TRUE));
} else {
systemProperties.produce(new SystemPropertyBuildItem(ConfigKey.ENABLE_EVENTS, FALSE));
Expand All @@ -714,8 +714,8 @@ void activateEventing(SmallRyeGraphQLConfig graphQLConfig, BuildProducer<SystemP
@BuildStep
void activateFederationBatchResolving(SmallRyeGraphQLConfig graphQLConfig,
BuildProducer<SystemPropertyBuildItem> systemProperties) {
if (graphQLConfig.federationBatchResolvingEnabled.isPresent()) {
String value = graphQLConfig.federationBatchResolvingEnabled.get().toString();
if (graphQLConfig.federationBatchResolvingEnabled().isPresent()) {
String value = graphQLConfig.federationBatchResolvingEnabled().get().toString();
systemProperties.produce(new SystemPropertyBuildItem(ConfigKey.ENABLE_FEDERATION_BATCH_RESOLVING, value));
System.setProperty(ConfigKey.ENABLE_FEDERATION_BATCH_RESOLVING, value);
}
Expand All @@ -737,8 +737,8 @@ void activateFederationBatchResolving(SmallRyeGraphQLConfig graphQLConfig,
void activateFederation(SmallRyeGraphQLConfig config,
BuildProducer<SystemPropertyBuildItem> systemProperties,
SmallRyeGraphQLFinalIndexBuildItem index) {
if (config.federationEnabled.isPresent()) {
String value = config.federationEnabled.get().toString();
if (config.federationEnabled().isPresent()) {
String value = config.federationEnabled().get().toString();
systemProperties.produce(new SystemPropertyBuildItem(ConfigKey.ENABLE_FEDERATION, value));
System.setProperty(ConfigKey.ENABLE_FEDERATION, value);
} else {
Expand Down Expand Up @@ -791,14 +791,14 @@ void getGraphqlUiFinalDestination(

if (shouldInclude(launchMode, graphQLConfig)) {

if ("/".equals(graphQLConfig.ui.rootPath)) {
if ("/".equals(graphQLConfig.ui().rootPath())) {
throw new ConfigurationException(
"quarkus.smallrye-graphql.root-path-ui was set to \"/\", this is not allowed as it blocks the application from serving anything else.",
Collections.singleton("quarkus.smallrye-graphql.root-path-ui"));
}

String graphQLPath = httpRootPath.resolvePath(graphQLConfig.rootPath);
String graphQLUiPath = nonApplicationRootPathBuildItem.resolvePath(graphQLConfig.ui.rootPath);
String graphQLPath = httpRootPath.resolvePath(graphQLConfig.rootPath());
String graphQLUiPath = nonApplicationRootPathBuildItem.resolvePath(graphQLConfig.ui().rootPath());
String devUiPath = nonApplicationRootPathBuildItem.resolvePath("dev");

webJarBuildProducer.produce(
Expand Down Expand Up @@ -847,21 +847,21 @@ void registerGraphQLUiHandler(
}

if (shouldInclude(launchMode, graphQLConfig)) {
String graphQLUiPath = nonApplicationRootPathBuildItem.resolvePath(graphQLConfig.ui.rootPath);
String graphQLUiPath = nonApplicationRootPathBuildItem.resolvePath(graphQLConfig.ui().rootPath());
smallRyeGraphQLBuildProducer
.produce(new SmallRyeGraphQLBuildItem(result.getFinalDestination(), graphQLUiPath));

Handler<RoutingContext> handler = recorder.uiHandler(result.getFinalDestination(),
graphQLUiPath, result.getWebRootConfigurations(), runtimeConfig, shutdownContext);
routeProducer.produce(nonApplicationRootPathBuildItem.routeBuilder()
.route(graphQLConfig.ui.rootPath)
.route(graphQLConfig.ui().rootPath())
.displayOnNotFoundPage("GraphQL UI")
.routeConfigKey("quarkus.smallrye-graphql.ui.root-path")
.handler(handler)
.build());

routeProducer.produce(nonApplicationRootPathBuildItem.routeBuilder()
.route(graphQLConfig.ui.rootPath + "*")
.route(graphQLConfig.ui().rootPath() + "*")
.handler(handler)
.build());

Expand Down Expand Up @@ -889,7 +889,7 @@ private String getLogoUrl(LaunchModeBuildItem launchMode, String devUIValue, Str
}

private static boolean shouldInclude(LaunchModeBuildItem launchMode, SmallRyeGraphQLConfig graphQLConfig) {
return launchMode.getLaunchMode().isDevOrTest() || graphQLConfig.ui.alwaysInclude;
return launchMode.getLaunchMode().isDevOrTest() || graphQLConfig.ui().alwaysInclude();
}

private String updateUrl(String original, String path, String lineStartsWith, String format) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ CardPageBuildItem createCard(NonApplicationRootPathBuildItem nonApplicationRootP
CardPageBuildItem cardPageBuildItem = new CardPageBuildItem();

// Generated GraphQL Schema
String schemaPath = "/" + graphQLConfig.rootPath + "/schema.graphql";
String schemaPath = "/" + graphQLConfig.rootPath() + "/schema.graphql";
PageBuilder schemaPage = Page.externalPageBuilder("GraphQL Schema")
.icon("font-awesome-solid:diagram-project")
.url(schemaPath, schemaPath);

// GraphiQL UI
String uiPath = nonApplicationRootPathBuildItem.resolvePath(graphQLConfig.ui.rootPath);
String uiPath = nonApplicationRootPathBuildItem.resolvePath(graphQLConfig.ui().rootPath());
PageBuilder uiPage = Page.externalPageBuilder("GraphQL UI")
.icon("font-awesome-solid:table-columns")
.url(uiPath + "/index.html?embed=true", uiPath);
Expand Down
3 changes: 0 additions & 3 deletions extensions/smallrye-graphql/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-AlegacyConfigRoot=true</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
Expand Down
Loading
Loading