Skip to content

Commit

Permalink
Add GraphQL Footer Log in Dev UI
Browse files Browse the repository at this point in the history
Signed-off-by: Phillip Kruger <phillip.kruger@gmail.com>
  • Loading branch information
phillip-kruger committed Sep 24, 2024
1 parent 2723368 commit c33b896
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<smallrye-health.version>4.1.0</smallrye-health.version>
<smallrye-metrics.version>4.0.0</smallrye-metrics.version>
<smallrye-open-api.version>3.12.0</smallrye-open-api.version>
<smallrye-graphql.version>2.10.0</smallrye-graphql.version>
<smallrye-graphql.version>2.10.1-SNAPSHOT</smallrye-graphql.version>
<smallrye-fault-tolerance.version>6.4.0</smallrye-fault-tolerance.version>
<smallrye-jwt.version>4.6.0</smallrye-jwt.version>
<smallrye-context-propagation.version>2.1.2</smallrye-context-propagation.version>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.quarkus.smallrye.graphql.deployment;

import java.util.concurrent.SubmissionPublisher;

import io.quarkus.builder.item.SimpleBuildItem;
import io.quarkus.runtime.RuntimeValue;

/**
* Used to create the publisher for the graphql trafic log in dev ui
*/
public final class GraphQLDevUILogBuildItem extends SimpleBuildItem {
private final RuntimeValue<SubmissionPublisher<String>> publisher;

public GraphQLDevUILogBuildItem(RuntimeValue<SubmissionPublisher<String>> publisher) {
this.publisher = publisher;
}

public RuntimeValue<SubmissionPublisher<String>> getPublisher() {
return this.publisher;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.Optional;
import java.util.Scanner;
import java.util.Set;
import java.util.concurrent.SubmissionPublisher;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -36,6 +37,7 @@
import io.quarkus.deployment.Capabilities;
import io.quarkus.deployment.Capability;
import io.quarkus.deployment.Feature;
import io.quarkus.deployment.IsDevelopment;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.Consume;
Expand All @@ -56,6 +58,7 @@
import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem;
import io.quarkus.deployment.metrics.MetricsCapabilityBuildItem;
import io.quarkus.devui.spi.buildtime.FooterLogBuildItem;
import io.quarkus.maven.dependency.GACT;
import io.quarkus.runtime.LaunchMode;
import io.quarkus.runtime.RuntimeValue;
Expand Down Expand Up @@ -329,6 +332,16 @@ void buildFinalIndex(
smallRyeGraphQLFinalIndexProducer.produce(new SmallRyeGraphQLFinalIndexBuildItem(overridableIndex));
}

@BuildStep(onlyIf = IsDevelopment.class)
@Record(ExecutionTime.STATIC_INIT)
void createDevUILog(BuildProducer<FooterLogBuildItem> footerLogProducer,
SmallRyeGraphQLRecorder recorder,
BuildProducer<GraphQLDevUILogBuildItem> graphQLDevUILogProducer) {
RuntimeValue<SubmissionPublisher<String>> publisher = recorder.createTraficLogPublisher();
footerLogProducer.produce(new FooterLogBuildItem("GraphQL", publisher));
graphQLDevUILogProducer.produce(new GraphQLDevUILogBuildItem(publisher));
}

@Record(ExecutionTime.STATIC_INIT)
@BuildStep
void buildExecutionService(
Expand All @@ -339,14 +352,20 @@ void buildExecutionService(
SmallRyeGraphQLFinalIndexBuildItem graphQLFinalIndexBuildItem,
BeanContainerBuildItem beanContainer,
BuildProducer<SystemPropertyBuildItem> systemPropertyProducer,
SmallRyeGraphQLConfig graphQLConfig) {
SmallRyeGraphQLConfig graphQLConfig,
Optional<GraphQLDevUILogBuildItem> graphQLDevUILogBuildItem) {

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

RuntimeValue<Boolean> initialized = recorder.createExecutionService(beanContainer.getValue(), schema, graphQLConfig);
Optional publisher = Optional.empty();
if (graphQLDevUILogBuildItem.isPresent()) {
publisher = Optional.of(graphQLDevUILogBuildItem.get().getPublisher());
}
RuntimeValue<Boolean> initialized = recorder.createExecutionService(beanContainer.getValue(), schema, graphQLConfig,
publisher);
graphQLInitializedProducer.produce(new SmallRyeGraphQLInitializedBuildItem(initialized));

// Make sure the complex object from the application can work in native mode
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.quarkus.smallrye.graphql.runtime;

import java.util.List;
import java.util.Optional;
import java.util.concurrent.SubmissionPublisher;
import java.util.function.Consumer;

import graphql.schema.GraphQLSchema;
Expand All @@ -26,13 +28,21 @@
@Recorder
public class SmallRyeGraphQLRecorder {

public RuntimeValue<SubmissionPublisher<String>> createTraficLogPublisher() {
return new RuntimeValue<>(new SubmissionPublisher<>());
}

public RuntimeValue<Boolean> createExecutionService(BeanContainer beanContainer,
Schema schema,
SmallRyeGraphQLConfig graphQLConfig) {
SmallRyeGraphQLConfig graphQLConfig,
Optional<RuntimeValue<SubmissionPublisher<String>>> publisher) {
GraphQLProducer graphQLProducer = beanContainer.beanInstance(GraphQLProducer.class);
if (graphQLConfig.extraScalars.isPresent()) {
registerExtraScalars(graphQLConfig.extraScalars.get());
}
if (publisher.isPresent()) {
graphQLProducer.setTraficPublisher(publisher.get().getValue());
}
GraphQLSchema graphQLSchema = graphQLProducer.initialize(schema);
return new RuntimeValue<>(graphQLSchema != null);
}
Expand Down

0 comments on commit c33b896

Please sign in to comment.