-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18999 from phillip-kruger/smallrye-graphql-1.3.0
Upgrade to Smallrye GraphQL 1.3.0
- Loading branch information
Showing
17 changed files
with
274 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...ava/io/quarkus/smallrye/graphql/client/deployment/DynamicGraphQLClientMissingUrlTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
...va/io/quarkus/smallrye/graphql/client/deployment/TypesafeGraphQLClientMissingUrlTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
.../main/java/io/quarkus/smallrye/graphql/client/runtime/QuarkifiedErrorMessageProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
...time/src/main/resources/META-INF/services/io.smallrye.graphql.client.ErrorMessageProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.quarkus.smallrye.graphql.client.runtime.QuarkifiedErrorMessageProvider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...nt/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLConfigMapping.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
|
||
} |
Oops, something went wrong.