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

GraphQL: New config option to make the schema unavailable #19169

Merged
merged 1 commit into from
Aug 2, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ public class SmallRyeGraphQLConfig {
@ConfigItem(defaultValue = "false")
boolean printDataFetcherException;

/**
* Make the schema available over HTTP.
*/
@ConfigItem(defaultValue = "true")
boolean schemaAvailable;

/**
* Include the Scalar definitions in the schema.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ void buildSchemaEndpoint(
SmallRyeGraphQLRecorder recorder,
SmallRyeGraphQLConfig graphQLConfig) {

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

routeProducer.produce(httpRootPathBuildItem.routeBuilder()
.nestedRoute(graphQLConfig.rootPath, SCHEMA_PATH)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package io.quarkus.smallrye.graphql.deployment;

import java.util.HashMap;
import java.util.Map;

import org.jboss.logging.Logger;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;
import io.restassured.RestAssured;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;

/**
* Test when schema is not available
*/
public class GraphQLSchemaUnavailableTest extends AbstractGraphQLTest {

private static final Logger LOG = Logger.getLogger(GraphQLSchemaUnavailableTest.class);

@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.addClasses(TestResource.class, TestPojo.class, TestRandom.class, TestGenericsPojo.class,
BusinessException.class)
.addAsResource(new StringAsset(getPropertyAsString(configuration())), "application.properties")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"));

@Test
public void testSchema() {
RequestSpecification request = RestAssured.given();
request.accept(MEDIATYPE_TEXT);
request.contentType(MEDIATYPE_TEXT);
Response response = request.get("/graphql/schema.graphql");

Assertions.assertEquals(404, response.statusCode());
}

private static Map<String, String> configuration() {
Map<String, String> m = new HashMap<>();
m.put("quarkus.smallrye-graphql.schema-available", "false");
return m;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public Handler<RoutingContext> subscriptionHandler(BeanContainer beanContainer,
CDI.current().select(CurrentVertxRequest.class).get());
}

public Handler<RoutingContext> schemaHandler(RuntimeValue<Boolean> initialized) {
if (initialized.getValue()) {
public Handler<RoutingContext> schemaHandler(RuntimeValue<Boolean> initialized, boolean schemaAvailable) {
if (initialized.getValue() && schemaAvailable) {
return new SmallRyeGraphQLSchemaHandler();
} else {
return new SmallRyeGraphQLNoEndpointHandler();
Expand Down