From c7f0b18ef9c8a8d1d1c2f67e0585fb4ec8f56681 Mon Sep 17 00:00:00 2001 From: Phillip Kruger Date: Mon, 26 Jul 2021 15:01:24 +0200 Subject: [PATCH 1/3] Upgrade SmallRye GraphQL to 1.3.0 Signed-off-by:Phillip Kruger --- bom/application/pom.xml | 2 +- .../deployment/SmallRyeGraphQLConfig.java | 49 ++++++++++++ .../SmallRyeGraphQLConfigMapping.java | 80 +++++++++++++++++++ .../deployment/SmallRyeGraphQLProcessor.java | 45 +++++------ ...io.smallrye.config.ConfigSourceInterceptor | 1 + .../deployment/GraphQLConfigMappingTest.java | 2 +- .../runtime/SmallRyeGraphQLConfigMapping.java | 59 -------------- .../runtime/SmallRyeGraphQLRecorder.java | 7 +- .../runtime/SmallRyeGraphQLSchemaHandler.java | 7 +- .../SmallRyeGraphQLSubscriptionHandler.java | 10 +-- ...io.smallrye.config.ConfigSourceInterceptor | 1 - 11 files changed, 160 insertions(+), 103 deletions(-) create mode 100644 extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLConfigMapping.java create mode 100644 extensions/smallrye-graphql/deployment/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceInterceptor delete mode 100644 extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLConfigMapping.java delete mode 100644 extensions/smallrye-graphql/runtime/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceInterceptor diff --git a/bom/application/pom.xml b/bom/application/pom.xml index a2801854fbb97..76288dd053c9c 100644 --- a/bom/application/pom.xml +++ b/bom/application/pom.xml @@ -46,7 +46,7 @@ 3.1.1 3.0.1 2.1.8 - 1.2.8 + 1.3.0 2.0.1 5.2.1 3.2.1 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 578cde7242bfb..b0ea61a69c6ab 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 @@ -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 { @@ -89,6 +90,54 @@ public class SmallRyeGraphQLConfig { @ConfigItem Optional 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> unwrapExceptions; + /** * SmallRye GraphQL UI configuration */ diff --git a/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLConfigMapping.java b/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLConfigMapping.java new file mode 100644 index 0000000000000..5b90af7a70817 --- /dev/null +++ b/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLConfigMapping.java @@ -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 RELOCATIONS = relocations(); + + public SmallRyeGraphQLConfigMapping() { + super(RELOCATIONS); + } + + @Override + public Iterator iterateNames(final ConfigSourceInterceptorContext context) { + final Set names = new HashSet<>(); + final Iterator 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 relocations() { + Map 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 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"; + +} 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 72538c75f0fbf..2d24a73be2118 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 @@ -57,7 +57,7 @@ import io.quarkus.vertx.http.deployment.RouteBuildItem; import io.quarkus.vertx.http.deployment.devmode.NotFoundPageDisplayableEndpointBuildItem; import io.smallrye.graphql.cdi.config.ConfigKey; -import io.smallrye.graphql.cdi.config.GraphQLConfig; +import io.smallrye.graphql.cdi.config.MicroProfileConfig; import io.smallrye.graphql.cdi.producer.GraphQLProducer; import io.smallrye.graphql.cdi.producer.SmallRyeContextAccessorProxy; import io.smallrye.graphql.schema.Annotations; @@ -133,7 +133,6 @@ void additionalBeanDefiningAnnotation(BuildProducer additionalBeanProducer) { additionalBeanProducer.produce(AdditionalBeanBuildItem.builder() - .addBeanClass(GraphQLConfig.class) .addBeanClass(GraphQLProducer.class) .addBeanClass(SmallRyeContextAccessorProxy.class) .setUnremovable().build()); @@ -151,6 +150,13 @@ void registerNativeImageResources(BuildProducer servic // Eventing Service (We use the one from the CDI Module) serviceProvider.produce(ServiceProviderBuildItem.allProvidersFromClassPath(EventingService.class.getName())); + + // Use MicroProfile Config (We use the one from the CDI Module) + serviceProvider.produce(ServiceProviderBuildItem.allProvidersFromClassPath(MicroProfileConfig.class.getName())); + + // Config mapping between SmallRye / MP and Quarkus + serviceProvider + .produce(ServiceProviderBuildItem.allProvidersFromClassPath(SmallRyeGraphQLConfigMapping.class.getName())); } @Record(ExecutionTime.STATIC_INIT) @@ -235,9 +241,8 @@ void buildExecutionEndpoint( .build()); // Queries and Mutations - boolean allowGet = getBooleanConfigValue(graphQLConfig.httpGetEnabled, ConfigKey.ALLOW_GET, false); - boolean allowQueryParametersOnPost = getBooleanConfigValue(graphQLConfig.httpPostQueryParametersEnabled, - ConfigKey.ALLOW_POST_WITH_QUERY_PARAMETERS, false); + boolean allowGet = getBooleanConfigValue(ConfigKey.ALLOW_GET, false); + boolean allowQueryParametersOnPost = getBooleanConfigValue(ConfigKey.ALLOW_POST_WITH_QUERY_PARAMETERS, false); Handler executionHandler = recorder.executionHandler(graphQLInitializedBuildItem.getInitialized(), allowGet, allowQueryParametersOnPost); routeProducer.produce(httpRootPathBuildItem.routeBuilder() @@ -250,9 +255,8 @@ void buildExecutionEndpoint( } - private boolean getBooleanConfigValue(Optional quarkusConfig, String smallryeKey, boolean defaultValue) { - return quarkusConfig - .orElse(ConfigProvider.getConfig().getOptionalValue(smallryeKey, boolean.class).orElse(defaultValue)); + private boolean getBooleanConfigValue(String smallryeKey, boolean defaultValue) { + return ConfigProvider.getConfig().getOptionalValue(smallryeKey, boolean.class).orElse(defaultValue); } private String[] getSchemaJavaClasses(Schema schema) { @@ -371,8 +375,7 @@ void activateMetrics(Capabilities capabilities, BuildProducer systemProperties, BuildProducer unremovableBeans) { - boolean activate = shouldActivateService(capabilities, - graphQLConfig.metricsEnabled, + boolean activate = shouldActivateService(graphQLConfig.metricsEnabled, metricsCapability.isPresent(), "quarkus-smallrye-metrics", "metrics", @@ -393,8 +396,8 @@ void activateTracing(Capabilities capabilities, SmallRyeGraphQLConfig graphQLConfig, BuildProducer systemProperties) { - boolean activate = shouldActivateService(capabilities, - graphQLConfig.tracingEnabled, + boolean activate = shouldActivateService(graphQLConfig.tracingEnabled, + capabilities.isPresent(Capability.OPENTRACING), "quarkus-smallrye-opentracing", Capability.OPENTRACING, "quarkus.smallrye-graphql.tracing.enabled", @@ -411,8 +414,8 @@ void activateValidation(Capabilities capabilities, SmallRyeGraphQLConfig graphQLConfig, BuildProducer systemProperties) { - boolean activate = shouldActivateService(capabilities, - graphQLConfig.validationEnabled, + boolean activate = shouldActivateService(graphQLConfig.validationEnabled, + capabilities.isPresent(Capability.HIBERNATE_VALIDATOR), "quarkus-hibernate-validator", Capability.HIBERNATE_VALIDATOR, "quarkus.smallrye-graphql.validation.enabled", @@ -433,19 +436,7 @@ void activateEventing(SmallRyeGraphQLConfig graphQLConfig, BuildProducer serviceEnabled, - String linkedExtensionName, - String linkedCapability, - String configKey, - boolean activateByDefaultIfCapabilityIsPresent) { - - return shouldActivateService(capabilities, serviceEnabled, capabilities.isPresent(linkedCapability), - linkedExtensionName, linkedCapability, configKey, activateByDefaultIfCapabilityIsPresent); - } - - private boolean shouldActivateService(Capabilities capabilities, - Optional serviceEnabled, + private boolean shouldActivateService(Optional serviceEnabled, boolean linkedCapabilityIsPresent, String linkedExtensionName, String linkedCapabilityName, diff --git a/extensions/smallrye-graphql/deployment/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceInterceptor b/extensions/smallrye-graphql/deployment/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceInterceptor new file mode 100644 index 0000000000000..d0436a2893b7f --- /dev/null +++ b/extensions/smallrye-graphql/deployment/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceInterceptor @@ -0,0 +1 @@ +io.quarkus.smallrye.graphql.deployment.SmallRyeGraphQLConfigMapping diff --git a/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/GraphQLConfigMappingTest.java b/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/GraphQLConfigMappingTest.java index caf3273b56cb9..fd96774f5b4d9 100644 --- a/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/GraphQLConfigMappingTest.java +++ b/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/GraphQLConfigMappingTest.java @@ -80,7 +80,7 @@ public void testSystemError() { private static Map configuration() { Map m = new HashMap<>(); m.put("quarkus.smallrye-graphql.error-extension-fields", - "exception, classification, code, description, validationErrorType, queryPath"); + "exception,classification,code,description,validationErrorType,queryPath"); m.put("quarkus.smallrye-graphql.default-error-message", "O gats, daar is 'n probleem !"); m.put("quarkus.smallrye-graphql.events.enabled", "true"); diff --git a/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLConfigMapping.java b/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLConfigMapping.java deleted file mode 100644 index 3d5bcd50e70de..0000000000000 --- a/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLConfigMapping.java +++ /dev/null @@ -1,59 +0,0 @@ -package io.quarkus.smallrye.graphql.runtime; - -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.ConfigValue; -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 RELOCATIONS = relocations(); - - public SmallRyeGraphQLConfigMapping() { - super(RELOCATIONS); - } - - @Override - public Iterator iterateNames(final ConfigSourceInterceptorContext context) { - final Set names = new HashSet<>(); - final Iterator 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(); - } - - @Override - public Iterator iterateValues(final ConfigSourceInterceptorContext context) { - return context.iterateValues(); - } - - private static Map relocations() { - Map relocations = new HashMap<>(); - mapKey(relocations, ConfigKey.ERROR_EXTENSION_FIELDS, "quarkus.smallrye-graphql.error-extension-fields"); - mapKey(relocations, ConfigKey.DEFAULT_ERROR_MESSAGE, "quarkus.smallrye-graphql.default-error-message"); - mapKey(relocations, "mp.graphql.showErrorMessage", "quarkus.smallrye-graphql.show-runtime-exception-message"); - mapKey(relocations, "mp.graphql.hideErrorMessage", "quarkus.smallrye-graphql.hide-checked-exception-message"); - return Collections.unmodifiableMap(relocations); - } - - private static void mapKey(Map map, String quarkusKey, String otherKey) { - map.put(quarkusKey, otherKey); - map.put(otherKey, quarkusKey); - } - -} diff --git a/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLRecorder.java b/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLRecorder.java index 2f8f4a37adb5a..6ffea9b7bab75 100644 --- a/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLRecorder.java +++ b/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLRecorder.java @@ -13,7 +13,6 @@ import io.quarkus.security.identity.CurrentIdentityAssociation; import io.quarkus.smallrye.graphql.runtime.spi.QuarkusClassloadingService; import io.quarkus.vertx.http.runtime.CurrentVertxRequest; -import io.smallrye.graphql.cdi.config.GraphQLConfig; import io.smallrye.graphql.cdi.producer.GraphQLProducer; import io.smallrye.graphql.schema.model.Schema; import io.vertx.core.Handler; @@ -25,8 +24,7 @@ public class SmallRyeGraphQLRecorder { public RuntimeValue createExecutionService(BeanContainer beanContainer, Schema schema) { GraphQLProducer graphQLProducer = beanContainer.instance(GraphQLProducer.class); - GraphQLConfig graphQLConfig = beanContainer.instance(GraphQLConfig.class); - GraphQLSchema graphQLSchema = graphQLProducer.initialize(schema, graphQLConfig); + GraphQLSchema graphQLSchema = graphQLProducer.initialize(schema); return new RuntimeValue<>(graphQLSchema != null); } @@ -41,8 +39,7 @@ public Handler executionHandler(RuntimeValue initialize } public Handler subscriptionHandler(BeanContainer beanContainer, RuntimeValue initialized) { - GraphQLConfig config = beanContainer.instance(GraphQLConfig.class); - return new SmallRyeGraphQLSubscriptionHandler(config, getCurrentIdentityAssociation(), + return new SmallRyeGraphQLSubscriptionHandler(getCurrentIdentityAssociation(), CDI.current().select(CurrentVertxRequest.class).get()); } diff --git a/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLSchemaHandler.java b/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLSchemaHandler.java index 656150c562bd8..d9af98e75d81b 100644 --- a/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLSchemaHandler.java +++ b/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLSchemaHandler.java @@ -19,13 +19,18 @@ public class SmallRyeGraphQLSchemaHandler implements Handler { private static final String ALLOWED_METHODS = "GET, OPTIONS"; private static final String CONTENT_TYPE = "text/plain; charset=UTF-8"; + private final SchemaPrinter schemaPrinter; + + public SmallRyeGraphQLSchemaHandler() { + this.schemaPrinter = new SchemaPrinter(); + } + @Override public void handle(RoutingContext event) { HttpServerRequest request = event.request(); HttpServerResponse response = event.response(); GraphQLSchema graphQLSchema = CDI.current().select(GraphQLSchema.class).get(); - SchemaPrinter schemaPrinter = CDI.current().select(SchemaPrinter.class).get(); String schemaString = schemaPrinter.print(graphQLSchema); diff --git a/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLSubscriptionHandler.java b/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLSubscriptionHandler.java index 8f52d325ba862..f3197091e8467 100644 --- a/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLSubscriptionHandler.java +++ b/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLSubscriptionHandler.java @@ -13,9 +13,7 @@ import graphql.ExecutionResult; import io.quarkus.security.identity.CurrentIdentityAssociation; import io.quarkus.vertx.http.runtime.CurrentVertxRequest; -import io.smallrye.graphql.bootstrap.Config; import io.smallrye.graphql.execution.ExecutionResponse; -import io.smallrye.graphql.execution.error.ExecutionErrorsService; import io.smallrye.mutiny.helpers.Subscriptions; import io.vertx.core.AsyncResult; import io.vertx.core.Handler; @@ -28,15 +26,11 @@ */ public class SmallRyeGraphQLSubscriptionHandler extends SmallRyeGraphQLAbstractHandler { private static final Logger log = Logger.getLogger(SmallRyeGraphQLSubscriptionHandler.class); - private final ExecutionErrorsService executionErrorsService; - private final Config config; private final ConcurrentHashMap> subscriptionRefs = new ConcurrentHashMap<>(); - public SmallRyeGraphQLSubscriptionHandler(Config config, CurrentIdentityAssociation currentIdentityAssociation, + public SmallRyeGraphQLSubscriptionHandler(CurrentIdentityAssociation currentIdentityAssociation, CurrentVertxRequest currentVertxRequest) { super(currentIdentityAssociation, currentVertxRequest); - this.config = config; - this.executionErrorsService = new ExecutionErrorsService(config); } @Override @@ -172,7 +166,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(ExecutionResult executionResult) { if (serverWebSocket != null && !serverWebSocket.isClosed()) { - ExecutionResponse executionResponse = new ExecutionResponse(executionResult, config); + ExecutionResponse executionResponse = new ExecutionResponse(executionResult); serverWebSocket.writeTextMessage(executionResponse.getExecutionResultAsString()); Subscription s = subscriptionRefs.get(textHandlerId).get(); s.request(1); diff --git a/extensions/smallrye-graphql/runtime/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceInterceptor b/extensions/smallrye-graphql/runtime/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceInterceptor deleted file mode 100644 index 8474e48c5d856..0000000000000 --- a/extensions/smallrye-graphql/runtime/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceInterceptor +++ /dev/null @@ -1 +0,0 @@ -io.quarkus.smallrye.graphql.runtime.SmallRyeGraphQLConfigMapping From 8a9f1eb122e9fa6c712dd4261ab2e31de83edc8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Marti=C5=A1ka?= Date: Tue, 13 Jul 2021 09:02:52 +0200 Subject: [PATCH 2/3] Supply a custom ErrorMessageProvider for SmallRye GraphQL Client --- .../SmallRyeGraphQLClientProcessor.java | 5 +++ .../DynamicGraphQLClientMissingUrlTest.java | 45 +++++++++++++++++++ .../TypesafeGraphQLClientMissingUrlTest.java | 45 +++++++++++++++++++ .../QuarkifiedErrorMessageProvider.java | 18 ++++++++ ...allrye.graphql.client.ErrorMessageProvider | 1 + 5 files changed, 114 insertions(+) create mode 100644 extensions/smallrye-graphql-client/deployment/src/test/java/io/quarkus/smallrye/graphql/client/deployment/DynamicGraphQLClientMissingUrlTest.java create mode 100644 extensions/smallrye-graphql-client/deployment/src/test/java/io/quarkus/smallrye/graphql/client/deployment/TypesafeGraphQLClientMissingUrlTest.java create mode 100644 extensions/smallrye-graphql-client/runtime/src/main/java/io/quarkus/smallrye/graphql/client/runtime/QuarkifiedErrorMessageProvider.java create mode 100644 extensions/smallrye-graphql-client/runtime/src/main/resources/META-INF/services/io.smallrye.graphql.client.ErrorMessageProvider diff --git a/extensions/smallrye-graphql-client/deployment/src/main/java/io/quarkus/smallrye/graphql/client/deployment/SmallRyeGraphQLClientProcessor.java b/extensions/smallrye-graphql-client/deployment/src/main/java/io/quarkus/smallrye/graphql/client/deployment/SmallRyeGraphQLClientProcessor.java index 1fe495e2d5913..7ea55fb335b6c 100644 --- a/extensions/smallrye-graphql-client/deployment/src/main/java/io/quarkus/smallrye/graphql/client/deployment/SmallRyeGraphQLClientProcessor.java +++ b/extensions/smallrye-graphql-client/deployment/src/main/java/io/quarkus/smallrye/graphql/client/deployment/SmallRyeGraphQLClientProcessor.java @@ -178,4 +178,9 @@ void initializeConfigMergerBean(BeanContainerBuildItem containerBuildItem, recorder.initializeConfigurationMergerBean(); } + @BuildStep + ServiceProviderBuildItem overrideErrorMessageProvider() { + return ServiceProviderBuildItem.allProvidersFromClassPath("io.smallrye.graphql.client.ErrorMessageProvider"); + } + } diff --git a/extensions/smallrye-graphql-client/deployment/src/test/java/io/quarkus/smallrye/graphql/client/deployment/DynamicGraphQLClientMissingUrlTest.java b/extensions/smallrye-graphql-client/deployment/src/test/java/io/quarkus/smallrye/graphql/client/deployment/DynamicGraphQLClientMissingUrlTest.java new file mode 100644 index 0000000000000..84de853cba812 --- /dev/null +++ b/extensions/smallrye-graphql-client/deployment/src/test/java/io/quarkus/smallrye/graphql/client/deployment/DynamicGraphQLClientMissingUrlTest.java @@ -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 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")); + } + } + +} diff --git a/extensions/smallrye-graphql-client/deployment/src/test/java/io/quarkus/smallrye/graphql/client/deployment/TypesafeGraphQLClientMissingUrlTest.java b/extensions/smallrye-graphql-client/deployment/src/test/java/io/quarkus/smallrye/graphql/client/deployment/TypesafeGraphQLClientMissingUrlTest.java new file mode 100644 index 0000000000000..8e24356637fdc --- /dev/null +++ b/extensions/smallrye-graphql-client/deployment/src/test/java/io/quarkus/smallrye/graphql/client/deployment/TypesafeGraphQLClientMissingUrlTest.java @@ -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 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")); + } + } + +} diff --git a/extensions/smallrye-graphql-client/runtime/src/main/java/io/quarkus/smallrye/graphql/client/runtime/QuarkifiedErrorMessageProvider.java b/extensions/smallrye-graphql-client/runtime/src/main/java/io/quarkus/smallrye/graphql/client/runtime/QuarkifiedErrorMessageProvider.java new file mode 100644 index 0000000000000..5ff27722af158 --- /dev/null +++ b/extensions/smallrye-graphql-client/runtime/src/main/java/io/quarkus/smallrye/graphql/client/runtime/QuarkifiedErrorMessageProvider.java @@ -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"); + } + +} diff --git a/extensions/smallrye-graphql-client/runtime/src/main/resources/META-INF/services/io.smallrye.graphql.client.ErrorMessageProvider b/extensions/smallrye-graphql-client/runtime/src/main/resources/META-INF/services/io.smallrye.graphql.client.ErrorMessageProvider new file mode 100644 index 0000000000000..9de304dcc4c73 --- /dev/null +++ b/extensions/smallrye-graphql-client/runtime/src/main/resources/META-INF/services/io.smallrye.graphql.client.ErrorMessageProvider @@ -0,0 +1 @@ +io.quarkus.smallrye.graphql.client.runtime.QuarkifiedErrorMessageProvider \ No newline at end of file From a74f6a81de3098d0c2be2d6b0860c0f07ed62dd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Marti=C5=A1ka?= Date: Thu, 15 Jul 2021 08:35:31 +0200 Subject: [PATCH 3/3] Remove smallrye-graphql-client-implementation-jaxrs dependency as it does not exist anymore --- bom/application/pom.xml | 5 ----- extensions/smallrye-graphql-client/runtime/pom.xml | 4 ---- 2 files changed, 9 deletions(-) diff --git a/bom/application/pom.xml b/bom/application/pom.xml index 76288dd053c9c..25e294a756f56 100644 --- a/bom/application/pom.xml +++ b/bom/application/pom.xml @@ -3397,11 +3397,6 @@ smallrye-graphql-client-implementation ${smallrye-graphql.version} - - io.smallrye - smallrye-graphql-client-implementation-jaxrs - ${smallrye-graphql.version} - io.smallrye smallrye-graphql-client-implementation-vertx diff --git a/extensions/smallrye-graphql-client/runtime/pom.xml b/extensions/smallrye-graphql-client/runtime/pom.xml index 04e196d88c1fa..b0d06078c8d5d 100644 --- a/extensions/smallrye-graphql-client/runtime/pom.xml +++ b/extensions/smallrye-graphql-client/runtime/pom.xml @@ -27,10 +27,6 @@ quarkus-jsonb - - io.smallrye - smallrye-graphql-client-implementation-jaxrs - io.smallrye smallrye-graphql-client-implementation-vertx