diff --git a/docs/src/main/asciidoc/images/graphql-ui-screenshot01.png b/docs/src/main/asciidoc/images/graphql-ui-screenshot01.png new file mode 100644 index 0000000000000..6b8731dde8196 Binary files /dev/null and b/docs/src/main/asciidoc/images/graphql-ui-screenshot01.png differ diff --git a/docs/src/main/asciidoc/microprofile-graphql.adoc b/docs/src/main/asciidoc/microprofile-graphql.adoc index bb7cf629bc014..eb474468bf858 100644 --- a/docs/src/main/asciidoc/microprofile-graphql.adoc +++ b/docs/src/main/asciidoc/microprofile-graphql.adoc @@ -369,6 +369,8 @@ The server will return the complete schema of the GraphQL API. == GraphiQL UI +NOTE: Experimental - not included in the MicroProfile specification + GraphiQL UI is a great tool permitting easy interaction with your GraphQL APIs. The Quarkus `smallrye-graphql` extension ships with `GraphiQL` and enables it by default in `dev` and `test` modes, @@ -376,6 +378,8 @@ but it can also be explicitly configured for `production` mode as well. GraphiQL can be accessed from http://localhost:8080/graphql-ui/ . +image:graphql-ui-screenshot01.png[alt=GraphQL UI] + == Query the GraphQL API Now visit the GraphiQL page that has been deployed in `dev` mode. diff --git a/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLConfig.java b/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLConfig.java index 936a63175d220..ab5e72ade0e55 100644 --- a/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLConfig.java +++ b/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLConfig.java @@ -1,5 +1,6 @@ package io.quarkus.smallrye.graphql.deployment; +import io.quarkus.runtime.annotations.ConfigDocSection; import io.quarkus.runtime.annotations.ConfigItem; import io.quarkus.runtime.annotations.ConfigRoot; @@ -13,29 +14,16 @@ public class SmallRyeGraphQLConfig { String rootPath; /** - * The path where GraphQL UI is available. - * The value `/` is not allowed as it blocks the application from serving anything else. - */ - @ConfigItem(defaultValue = "/graphql-ui") - String rootPathUi; - - /** - * Always include the UI. By default this will only be included in dev and test. - * Setting this to true will also include the UI in Prod - */ - @ConfigItem(defaultValue = "false") - boolean alwaysIncludeUi; - - /** - * If GraphQL UI should be enabled. By default, GraphQL UI is enabled. + * Enable metrics */ - @ConfigItem(defaultValue = "true") - boolean enableUi; + @ConfigItem(name = "metrics.enabled", defaultValue = "false") + boolean metricsEnabled; /** - * Enable metrics + * UI configuration */ - @ConfigItem(name = "metrics.enabled", defaultValue = "false") - public boolean metricsEnabled; + @ConfigItem + @ConfigDocSection + SmallRyeGraphQLUIConfig ui; } diff --git a/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLProcessor.java b/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLProcessor.java index 5450eff63d8c5..12588bef28071 100644 --- a/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLProcessor.java +++ b/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLProcessor.java @@ -3,6 +3,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.io.UncheckedIOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; @@ -337,10 +338,10 @@ void registerGraphQLUiServletExtension( HttpRootPathBuildItem httpRootPath, CurateOutcomeBuildItem curateOutcomeBuildItem) throws Exception { - if (!quarkusConfig.enableUi) { + if (!quarkusConfig.ui.enable) { return; } - if ("/".equals(quarkusConfig.rootPathUi)) { + if ("/".equals(quarkusConfig.ui.rootPath)) { throw new ConfigurationError( "quarkus.smallrye-graphql.root-path-ui was set to \"/\", this is not allowed as it blocks the application from serving anything else."); } @@ -373,16 +374,16 @@ void registerGraphQLUiServletExtension( cached.cachedDirectory = tempDir.toAbsolutePath().toString(); cached.cachedGraphQLPath = graphQLPath; } catch (IOException e) { - throw new RuntimeException(e); + throw new UncheckedIOException(e); } } Handler handler = recorder.uiHandler(cached.cachedDirectory, - httpRootPath.adjustPath(quarkusConfig.rootPathUi)); - routeProducer.produce(new RouteBuildItem(quarkusConfig.rootPathUi, handler)); - routeProducer.produce(new RouteBuildItem(quarkusConfig.rootPathUi + "/*", handler)); + httpRootPath.adjustPath(quarkusConfig.ui.rootPath)); + routeProducer.produce(new RouteBuildItem(quarkusConfig.ui.rootPath, handler)); + routeProducer.produce(new RouteBuildItem(quarkusConfig.ui.rootPath + "/*", handler)); notFoundPageDisplayableEndpointProducer - .produce(new NotFoundPageDisplayableEndpointBuildItem(quarkusConfig.rootPathUi + "/")); - } else if (quarkusConfig.alwaysIncludeUi) { + .produce(new NotFoundPageDisplayableEndpointBuildItem(quarkusConfig.ui.rootPath + "/")); + } else if (quarkusConfig.ui.alwaysInclude) { AppArtifact artifact = getGraphQLUiArtifact(curateOutcomeBuildItem); //we are including in a production artifact //just stick the files in the generated output @@ -425,9 +426,9 @@ void registerGraphQLUiServletExtension( } Handler handler = recorder - .uiHandler(GRAPHQL_UI_FINAL_DESTINATION, httpRootPath.adjustPath(quarkusConfig.rootPathUi)); - routeProducer.produce(new RouteBuildItem(quarkusConfig.rootPathUi, handler)); - routeProducer.produce(new RouteBuildItem(quarkusConfig.rootPathUi + "/*", handler)); + .uiHandler(GRAPHQL_UI_FINAL_DESTINATION, httpRootPath.adjustPath(quarkusConfig.ui.rootPath)); + routeProducer.produce(new RouteBuildItem(quarkusConfig.ui.rootPath, handler)); + routeProducer.produce(new RouteBuildItem(quarkusConfig.ui.rootPath + "/*", handler)); } } diff --git a/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLUIConfig.java b/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLUIConfig.java new file mode 100644 index 0000000000000..7b2b8a5994226 --- /dev/null +++ b/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLUIConfig.java @@ -0,0 +1,28 @@ +package io.quarkus.smallrye.graphql.deployment; + +import io.quarkus.runtime.annotations.ConfigGroup; +import io.quarkus.runtime.annotations.ConfigItem; + +@ConfigGroup +public class SmallRyeGraphQLUIConfig { + + /** + * The path where GraphQL UI is available. + * The value `/` is not allowed as it blocks the application from serving anything else. + */ + @ConfigItem(defaultValue = "/graphql-ui") + String rootPath; + + /** + * Always include the UI. By default this will only be included in dev and test. + * Setting this to true will also include the UI in Prod + */ + @ConfigItem(defaultValue = "false") + boolean alwaysInclude; + + /** + * If GraphQL UI should be enabled. By default, GraphQL UI is enabled. + */ + @ConfigItem(defaultValue = "true") + boolean enable; +} diff --git a/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/ui/CustomConfigTest.java b/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/ui/CustomConfigTest.java index 68c04b2123041..c841dc1122d1f 100644 --- a/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/ui/CustomConfigTest.java +++ b/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/ui/CustomConfigTest.java @@ -16,7 +16,7 @@ public class CustomConfigTest { @RegisterExtension static final QuarkusUnitTest config = new QuarkusUnitTest() .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) - .addAsResource(new StringAsset("quarkus.smallrye-graphql.root-path-ui=/custom"), "application.properties")); + .addAsResource(new StringAsset("quarkus.smallrye-graphql.ui.root-path=/custom"), "application.properties")); @Test public void shouldUseCustomConfig() { diff --git a/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/ui/DisabledTest.java b/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/ui/DisabledTest.java index 14e4e900fefb5..099c90086ed72 100644 --- a/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/ui/DisabledTest.java +++ b/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/ui/DisabledTest.java @@ -14,7 +14,7 @@ public class DisabledTest { @RegisterExtension static final QuarkusUnitTest config = new QuarkusUnitTest() .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) - .addAsResource(new StringAsset("quarkus.smallrye-graphql.enable-ui=false"), "application.properties")); + .addAsResource(new StringAsset("quarkus.smallrye-graphql.ui.enable=false"), "application.properties")); @Test public void shouldUseDefaultConfig() { diff --git a/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/ui/ErroneousConfigTest.java b/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/ui/ErroneousConfigTest.java index 630e9b0bdf46b..78eca1f2eed3a 100644 --- a/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/ui/ErroneousConfigTest.java +++ b/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/ui/ErroneousConfigTest.java @@ -16,7 +16,7 @@ public class ErroneousConfigTest { static final QuarkusUnitTest config = new QuarkusUnitTest() .setExpectedException(ConfigurationError.class) .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) - .addAsResource(new StringAsset("quarkus.smallrye-graphql.root-path-ui=/\n"), "application.properties")); + .addAsResource(new StringAsset("quarkus.smallrye-graphql.ui.root-path=/\n"), "application.properties")); @Test public void shouldNotStartApplicationIfUIPathIsASlash() { diff --git a/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthConfig.java b/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthConfig.java index 8d365e7c38b10..08104bf8c73bd 100644 --- a/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthConfig.java +++ b/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthConfig.java @@ -32,8 +32,7 @@ public class SmallRyeHealthConfig { String groupPath; /** - * Config group for all UI related options. - * Configuration properties for UI + * UI configuration */ @ConfigItem @ConfigDocSection