-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
202 additions
and
42 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
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
68 changes: 68 additions & 0 deletions
68
...java/io/quarkus/smallrye/graphql/client/runtime/GraphQLClientConfigurationMergerBean.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,68 @@ | ||
package io.quarkus.smallrye.graphql.client.runtime; | ||
|
||
import java.util.Map; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
|
||
import io.smallrye.graphql.client.GraphQLClientConfiguration; | ||
import io.smallrye.graphql.client.GraphQLClientsConfiguration; | ||
|
||
/** | ||
* On startup, this beans takes Quarkus-specific configuration of GraphQL clients (quarkus.* properties) | ||
* and merges this configuration with the configuration parsed by SmallRye GraphQL itself (CLIENT/mp-graphql/* properties) | ||
* | ||
* The resulting merged configuration resides in the application-scoped `io.smallrye.graphql.client.GraphQLClientConfiguration` | ||
* | ||
* Quarkus configuration overrides SmallRye configuration where applicable. | ||
*/ | ||
@Singleton | ||
public class GraphQLClientConfigurationMergerBean { | ||
|
||
@Inject | ||
GraphQLClientsConfiguration upstreamConfiguration; | ||
|
||
@Inject | ||
GraphQLClientsConfig quarkusConfiguration; | ||
|
||
@Inject | ||
GraphQLClientSupport support; | ||
|
||
@PostConstruct | ||
void enhanceGraphQLConfiguration() { | ||
for (Map.Entry<String, GraphQLClientConfig> client : quarkusConfiguration.clients.entrySet()) { | ||
// the raw config key provided in the config, this might be a short class name, | ||
// so translate that into the fully qualified name if applicable | ||
String rawConfigKey = client.getKey(); | ||
Map<String, String> shortNamesToQualifiedNamesMapping = support.getShortNamesToQualifiedNamesMapping(); | ||
String configKey = shortNamesToQualifiedNamesMapping != null && | ||
shortNamesToQualifiedNamesMapping.containsKey(rawConfigKey) | ||
? shortNamesToQualifiedNamesMapping.get(rawConfigKey) | ||
: rawConfigKey; | ||
|
||
GraphQLClientConfig quarkusConfig = client.getValue(); | ||
// if SmallRye configuration does not contain this client, simply use it | ||
if (!upstreamConfiguration.getClients().containsKey(configKey)) { | ||
GraphQLClientConfiguration transformed = new GraphQLClientConfiguration(); | ||
transformed.setHeaders(quarkusConfig.headers); | ||
transformed.setUrl(quarkusConfig.url); | ||
upstreamConfiguration.getClients().put(configKey, transformed); | ||
} else { | ||
// if SmallRye configuration already contains this client, override it with the Quarkus configuration | ||
GraphQLClientConfiguration upstreamConfig = upstreamConfiguration.getClients().get(configKey); | ||
if (quarkusConfig.url != null) { | ||
upstreamConfig.setUrl(quarkusConfig.url); | ||
} | ||
// merge the headers | ||
if (quarkusConfig.headers != null) { | ||
upstreamConfig.getHeaders().putAll(quarkusConfig.headers); | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
public void nothing() { | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...untime/src/main/java/io/quarkus/smallrye/graphql/client/runtime/GraphQLClientSupport.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,24 @@ | ||
package io.quarkus.smallrye.graphql.client.runtime; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Items from build time needed to make available at runtime. | ||
*/ | ||
public class GraphQLClientSupport { | ||
|
||
/** | ||
* Allows the optional usage of short class names in GraphQL client configuration rather than | ||
* fully qualified names. The configuration merger bean will take it into account | ||
* when merging Quarkus configuration with SmallRye-side configuration. | ||
*/ | ||
private Map<String, String> shortNamesToQualifiedNamesMapping; | ||
|
||
public Map<String, String> getShortNamesToQualifiedNamesMapping() { | ||
return shortNamesToQualifiedNamesMapping; | ||
} | ||
|
||
public void setShortNamesToQualifiedNamesMapping(Map<String, String> shortNamesToQualifiedNamesMapping) { | ||
this.shortNamesToQualifiedNamesMapping = shortNamesToQualifiedNamesMapping; | ||
} | ||
} |
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