Skip to content

Commit

Permalink
Merge pull request #18999 from phillip-kruger/smallrye-graphql-1.3.0
Browse files Browse the repository at this point in the history
Upgrade to Smallrye GraphQL 1.3.0
  • Loading branch information
phillip-kruger authored Jul 26, 2021
2 parents cfccbb9 + a74f6a8 commit b43d144
Show file tree
Hide file tree
Showing 17 changed files with 274 additions and 112 deletions.
7 changes: 1 addition & 6 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<smallrye-health.version>3.1.1</smallrye-health.version>
<smallrye-metrics.version>3.0.1</smallrye-metrics.version>
<smallrye-open-api.version>2.1.8</smallrye-open-api.version>
<smallrye-graphql.version>1.2.8</smallrye-graphql.version>
<smallrye-graphql.version>1.3.0</smallrye-graphql.version>
<smallrye-opentracing.version>2.0.1</smallrye-opentracing.version>
<smallrye-fault-tolerance.version>5.2.1</smallrye-fault-tolerance.version>
<smallrye-jwt.version>3.2.1</smallrye-jwt.version>
Expand Down Expand Up @@ -3397,11 +3397,6 @@
<artifactId>smallrye-graphql-client-implementation</artifactId>
<version>${smallrye-graphql.version}</version>
</dependency>
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-graphql-client-implementation-jaxrs</artifactId>
<version>${smallrye-graphql.version}</version>
</dependency>
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-graphql-client-implementation-vertx</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,9 @@ void initializeConfigMergerBean(BeanContainerBuildItem containerBuildItem,
recorder.initializeConfigurationMergerBean();
}

@BuildStep
ServiceProviderBuildItem overrideErrorMessageProvider() {
return ServiceProviderBuildItem.allProvidersFromClassPath("io.smallrye.graphql.client.ErrorMessageProvider");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.quarkus.smallrye.graphql.client.deployment;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import javax.enterprise.inject.Instance;
import javax.inject.Inject;

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

import io.quarkus.test.QuarkusUnitTest;
import io.smallrye.graphql.client.GraphQLClient;
import io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient;

public class DynamicGraphQLClientMissingUrlTest {

@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"));

@Inject
@GraphQLClient("invalid")
Instance<DynamicGraphQLClient> client;

/**
* Check that when URL is not defined for a dynamic client, the thrown error message suggests the
* `quarkus.*` config property rather than the SmallRye property (`CLIENT_NAME/mp-graphql/url`). This
* is achieved by using `io.quarkus.smallrye.graphql.client.runtime.QuarkifiedErrorMessageProvider`.
*/
@Test
public void checkErrorMessage() {
try {
client.get();
fail("Injection of a dynamic client must fail because no URL is defined");
} catch (RuntimeException e) {
assertTrue(e.getMessage().contains("quarkus.smallrye-graphql-client.invalid.url"));
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.quarkus.smallrye.graphql.client.deployment;

import static org.junit.jupiter.api.Assertions.*;

import javax.enterprise.inject.Instance;
import javax.inject.Inject;

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

import io.quarkus.smallrye.graphql.client.deployment.model.Person;
import io.quarkus.smallrye.graphql.client.deployment.model.TestingGraphQLApi;
import io.quarkus.smallrye.graphql.client.deployment.model.TestingGraphQLClientApi;
import io.quarkus.test.QuarkusUnitTest;

public class TypesafeGraphQLClientMissingUrlTest {

@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.addClasses(TestingGraphQLApi.class, TestingGraphQLClientApi.class, Person.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"));

@Inject
Instance<TestingGraphQLClientApi> client;

/**
* Check that when URL is not defined for a typesafe client, the thrown error message suggests the
* `quarkus.*` config property rather than the SmallRye property (`CLIENT_NAME/mp-graphql/url`). This
* is achieved by using `io.quarkus.smallrye.graphql.client.runtime.QuarkifiedErrorMessageProvider`.
*/
@Test
public void checkErrorMessage() {
try {
client.get();
fail("Injection of a typesafe client must fail because no URL is defined");
} catch (RuntimeException e) {
assertTrue(e.getMessage().contains("quarkus.smallrye-graphql-client.typesafeclient.url"));
}
}

}
4 changes: 0 additions & 4 deletions extensions/smallrye-graphql-client/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
<artifactId>quarkus-jsonb</artifactId>
</dependency>

<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-graphql-client-implementation-jaxrs</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-graphql-client-implementation-vertx</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.quarkus.smallrye.graphql.client.runtime;

import io.smallrye.graphql.client.ErrorMessageProvider;

/**
* Provides Quarkus-specific versions of error messages for SmallRye GraphQL. The reason being, for example,
* the ability to suggest a quarkus.* configuration property when it's more appropriate than suggesting
* the basic /mp-graphql property understood directly by SmallRye.
*/
public class QuarkifiedErrorMessageProvider implements ErrorMessageProvider {

@Override
public RuntimeException urlMissingErrorForNamedClient(String name) {
return new RuntimeException("URL not configured for client. Please define the property " +
"quarkus.smallrye-graphql-client." + name + ".url or pass it to your client builder dynamically");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.quarkus.smallrye.graphql.client.runtime.QuarkifiedErrorMessageProvider
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.graphql.schema.helper.TypeAutoNameStrategy;
import io.smallrye.graphql.spi.config.LogPayloadOption;

@ConfigRoot(name = "smallrye-graphql")
public class SmallRyeGraphQLConfig {
Expand Down Expand Up @@ -89,6 +90,54 @@ public class SmallRyeGraphQLConfig {
@ConfigItem
Optional<String> defaultErrorMessage;

/**
* Print the data fetcher exception to the log file.
*/
@ConfigItem(defaultValue = "false")
boolean printDataFetcherException;

/**
* Include the Scalar definitions in the schema.
*/
@ConfigItem(defaultValue = "false")
boolean schemaIncludeScalars;

/**
* Include the schema internal definition in the schema.
*/
@ConfigItem(defaultValue = "false")
boolean schemaIncludeSchemaDefinition;

/**
* Include Directives in the schema.
*/
@ConfigItem(defaultValue = "false")
boolean schemaIncludeDirectives;

/**
* Include Introspection Types in the schema.
*/
@ConfigItem(defaultValue = "false")
boolean schemaIncludeIntrospectionTypes;

/**
* Log the payload (and optionally variables) to System out.
*/
@ConfigItem(defaultValue = "off")
LogPayloadOption logPayload;

/**
* Set the Field visibility.
*/
@ConfigItem(defaultValue = "default")
String fieldVisibility;

/**
* Exceptions that should be unwrapped (class names).
*/
@ConfigItem
Optional<List<String>> unwrapExceptions;

/**
* SmallRye GraphQL UI configuration
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package io.quarkus.smallrye.graphql.deployment;

import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import io.smallrye.config.ConfigSourceInterceptorContext;
import io.smallrye.config.RelocateConfigSourceInterceptor;
import io.smallrye.graphql.cdi.config.ConfigKey;

/**
* Maps config from MicroProfile and SmallRye to Quarkus
*/
public class SmallRyeGraphQLConfigMapping extends RelocateConfigSourceInterceptor {
private static final Map<String, String> RELOCATIONS = relocations();

public SmallRyeGraphQLConfigMapping() {
super(RELOCATIONS);
}

@Override
public Iterator<String> iterateNames(final ConfigSourceInterceptorContext context) {
final Set<String> names = new HashSet<>();
final Iterator<String> namesIterator = context.iterateNames();
while (namesIterator.hasNext()) {
final String name = namesIterator.next();
names.add(name);
final String mappedName = RELOCATIONS.get(name);
if (mappedName != null) {
names.add(mappedName);
}
}
return names.iterator();
}

private static Map<String, String> relocations() {
Map<String, String> relocations = new HashMap<>();
mapKey(relocations, ConfigKey.ALLOW_GET, QUARKUS_HTTP_GET_ENABLED);
mapKey(relocations, ConfigKey.ALLOW_POST_WITH_QUERY_PARAMETERS, QUARKUS_HTTP_POST_QUERYPARAMETERS_ENABLED);
mapKey(relocations, ConfigKey.ERROR_EXTENSION_FIELDS, QUARKUS_ERROR_EXTENSION_FIELDS);
mapKey(relocations, ConfigKey.DEFAULT_ERROR_MESSAGE, QUARKUS_DEFAULT_ERROR_MESSAGE);
mapKey(relocations, ConfigKey.PRINT_DATAFETCHER_EXCEPTION, QUARKUS_PRINT_DATAFETCHER_EXCEPTION);
mapKey(relocations, ConfigKey.SCHEMA_INCLUDE_SCALARS, QUARKUS_SCHEMA_INCLUDE_SCALARS);
mapKey(relocations, ConfigKey.SCHEMA_INCLUDE_DEFINITION, QUARKUS_SCHEMA_INCLUDE_DEFINITION);
mapKey(relocations, ConfigKey.SCHEMA_INCLUDE_DIRECTIVES, QUARKUS_SCHEMA_INCLUDE_DIRECTIVES);
mapKey(relocations, ConfigKey.SCHEMA_INCLUDE_INTROSPECTION_TYPES, QUARKUS_SCHEMA_INCLUDE_INTROSPECTION_TYPES);
mapKey(relocations, ConfigKey.LOG_PAYLOAD, QUARKUS_LOG_PAYLOAD);
mapKey(relocations, ConfigKey.FIELD_VISIBILITY, QUARKUS_FIELD_VISIBILITY);
mapKey(relocations, ConfigKey.UNWRAP_EXCEPTIONS, QUARKUS_UNWRAP_EXCEPTIONS);
mapKey(relocations, SHOW_ERROR_MESSAGE, QUARKUS_SHOW_ERROR_MESSAGE);
mapKey(relocations, HIDE_ERROR_MESSAGE, QUARKUS_HIDE_ERROR_MESSAGE);
return Collections.unmodifiableMap(relocations);
}

private static void mapKey(Map<String, String> map, String quarkusKey, String otherKey) {
map.put(quarkusKey, otherKey);
map.put(otherKey, quarkusKey);
}

private static final String SHOW_ERROR_MESSAGE = "mp.graphql.showErrorMessage";
private static final String HIDE_ERROR_MESSAGE = "mp.graphql.hideErrorMessage";
private static final String QUARKUS_ERROR_EXTENSION_FIELDS = "quarkus.smallrye-graphql.error-extension-fields";
private static final String QUARKUS_DEFAULT_ERROR_MESSAGE = "quarkus.smallrye-graphql.default-error-message";
private static final String QUARKUS_SHOW_ERROR_MESSAGE = "quarkus.smallrye-graphql.show-runtime-exception-message";
private static final String QUARKUS_HIDE_ERROR_MESSAGE = "quarkus.smallrye-graphql.hide-checked-exception-message";
private static final String QUARKUS_HTTP_GET_ENABLED = "quarkus.smallrye-graphql.http.get.enabled";
private static final String QUARKUS_HTTP_POST_QUERYPARAMETERS_ENABLED = "quarkus.smallrye-graphql.http.post.queryparameters.enabled";
private static final String QUARKUS_PRINT_DATAFETCHER_EXCEPTION = "quarkus.smallrye-graphql.print-data-fetcher-exception";
private static final String QUARKUS_SCHEMA_INCLUDE_SCALARS = "quarkus.smallrye-graphql.schema-include-scalars";
private static final String QUARKUS_SCHEMA_INCLUDE_DEFINITION = "quarkus.smallrye-graphql.schema-include-schema-definition";
private static final String QUARKUS_SCHEMA_INCLUDE_DIRECTIVES = "quarkus.smallrye-graphql.schema-include-directives";
private static final String QUARKUS_SCHEMA_INCLUDE_INTROSPECTION_TYPES = "quarkus.smallrye-graphql.schema-include-introspection-types";
private static final String QUARKUS_LOG_PAYLOAD = "quarkus.smallrye-graphql.log-payload";
private static final String QUARKUS_FIELD_VISIBILITY = "quarkus.smallrye-graphql.field-visibility";
private static final String QUARKUS_UNWRAP_EXCEPTIONS = "quarkus.smallrye-graphql.unwrap-exceptions";

}
Loading

0 comments on commit b43d144

Please sign in to comment.