Skip to content

Commit

Permalink
Merge pull request #10890 from phillip-kruger/graphql-config-update
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi authored Jul 23, 2020
2 parents 4018e6e + b3d1cf6 commit 89b900f
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 36 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions docs/src/main/asciidoc/microprofile-graphql.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,17 @@ 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,
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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.");
}
Expand Down Expand Up @@ -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<RoutingContext> 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
Expand Down Expand Up @@ -425,9 +426,9 @@ void registerGraphQLUiServletExtension(
}

Handler<RoutingContext> 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));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public class SmallRyeHealthConfig {
String groupPath;

/**
* Config group for all UI related options.
* Configuration properties for UI
* UI configuration
*/
@ConfigItem
@ConfigDocSection
Expand Down

0 comments on commit 89b900f

Please sign in to comment.