Typesafe client: Custom User-Agent
I would need to solve having a custom agent from Quarkus and outside Quarkus. --> Inputs are welcomed for both cases.
I looked only at the plain-java (outside quarkus) case for now:
Based on the input in the documentation, I thought I just need custom headers: https://smallrye.io/smallrye-graphql/latest/typesafe-client-headers/
Like this:
WorkitemClientApi gqlApi = TypesafeGraphQLClientBuilder.newBuilder()
.endpoint("http://localhost:8888/api/graphql")
.header("user-agent", "My Custom User Agent")
.header("Authorization", "Bearer " + gitlabToken)
.allowUnexpectedResponseFields(true)
.build(WorkitemClientApi.class);
return gqlApi;
Request intercepted with mitmproxy:
mitmweb -p 8888 --mode reverse:https://**********/
Second approach, instead of using the API TypesafeGraphQLClientBuilder, it seems that the VertxTypesafeGraphQLClientBuilder allows setting options
There is the HttpClientOptions, but this also have a sub-class WebClientOptions where the UserAgent seems to be managed.
WorkitemClientApi gqlApi = new VertxTypesafeGraphQLClientBuilder()
.options(new WebClientOptions().setUserAgent("My Custom User Agent"))
.endpoint("http://localhost:8888/api/graphql")
.header("user-agent", "My Custom User Agent")
.header("Authorization", "Bearer " + gitlabToken)
.allowUnexpectedResponseFields(true)
.build(WorkitemClientApi.class);
return gqlApi;
But this get lost in initClients() here:
https://github.com/smallrye/smallrye-graphql/blob/f3899bbd9bdacf7b585983bc4906ff856a2b86f6/client/implementation-vertx/src/main/java/io/smallrye/graphql/client/vertx/typesafe/VertxTypesafeGraphQLClientBuilder.java#L218-L227
Since on line 220, the Vertx api accept the WebClientOptions (it is a child class of HttpClientOptions) but it is transforming back to HttpClientOptions so the custom user agent setting is lost.
https://github.com/eclipse-vertx/vert.x/blob/4.5.14/src/main/java/io/vertx/core/http/impl/HttpClientBase.java#L58
My current work-around is:
Vertx vertx = VertxManager.get();
WebClientOptions options = new WebClientOptions().setUserAgent("My Custom User Agent");
var httpClient = vertx.createHttpClient(options);
var client = WebClient.wrap(httpClient, options);
WorkitemClientApi gqlApi = new VertxTypesafeGraphQLClientBuilder()
.options(options)
.client(client)
.endpoint("http://localhost:8888/api/graphql")
.header("Authorization", "Bearer " + gitlabToken)
.allowUnexpectedResponseFields(true)
.build(WorkitemClientApi.class);
return gqlApi;
But I think it should be somehow easier to solve.
The same approach seems to work with Quarkus as well. I was afraid the Vertx stuff would work differently.
For the dynamic client:
Vertx vertx = VertxManager.get();
WebClientOptions options = new WebClientOptions().setUserAgent("My Custom User Agent");
var httpClient = vertx.createHttpClient(options);
var client = WebClient.wrap(httpClient, options);
DynamicGraphQLClient gqlApi = new VertxDynamicGraphQLClientBuilder()
.webClient(client)
.endpoint("http://localhost:8888/api/graphql")
.header("Authorization", "Bearer " + gitlabToken)
.build();
return gqlApi;
Right, we will need to add a new config property on the smallrye side and a piece of integration for it on the Quarkus side. Shouldn't be too hard, the main problem is the fact that it will need an update in two repositories. If you want to try doing it, feel free; I can have a look at some point, but my schedule right now is full of holidays and conferences...
If you want to try doing it, feel free…
I am not sure to understand what needs to be extended to make available. Add a userAgent(String value) method in the TypesafeGraphQLClientBuilder and DynamicGraphQLClientBuilder interfaces? Similar to other methods:
https://github.com/smallrye/smallrye-graphql/blob/c4b87e3f8321a65bf01596e0d41444b5f4247320/client/api/src/main/java/io/smallrye/graphql/client/typesafe/api/TypesafeGraphQLClientBuilder.java#L40-L43
Or what is the approach?
Ah, yes, disregard my note about "a new config property on the smallrye side", we don't actually use any such config properties for clients, so just allowing to pass the agent to the builders will be enough on the smallrye side, just like you said. Quarkus could optionally have a config property for it, but I can take care of that later.