Skip to content

Instantly share code, notes, and snippets.

@sherl0cks
Last active June 10, 2020 07:41
Show Gist options
  • Save sherl0cks/2798af5960ff21395998e3386dd35045 to your computer and use it in GitHub Desktop.
Save sherl0cks/2798af5960ff21395998e3386dd35045 to your computer and use it in GitHub Desktop.
Getting Smallrye Graphql Client 1.0.3 Working with Quarkus 1.5.0.Final in Native Image
[
"com.acme.myapp.MyCoolGraphQlApi"
]
package com.acme.myapp;
import io.quarkus.runtime.annotations.RegisterForReflection
@RegisterForReflection(
targets = [
io.smallrye.graphql.client.typesafe.api.GraphQlClientApi::class,
io.smallrye.graphql.client.typesafe.api.GraphQlClientBuilder::class,
io.smallrye.graphql.client.typesafe.api.GraphQlClientHeader::class,
io.smallrye.graphql.client.typesafe.impl.GraphQlClientBuilderImpl::class,
io.smallrye.graphql.client.typesafe.impl.reflection.ConstructionInfo::class,
io.smallrye.graphql.client.typesafe.impl.reflection.FieldInfo::class,
io.smallrye.graphql.client.typesafe.impl.reflection.MethodInfo::class,
io.smallrye.graphql.client.typesafe.impl.reflection.ParameterInfo::class,
io.smallrye.graphql.client.typesafe.impl.reflection.TypeInfo::class,
javax.json.Json::class,
javax.json.JsonBuilderFactory::class,
javax.json.JsonObject::class,
javax.json.JsonObjectBuilder::class,
javax.json.JsonReaderFactory::class,
javax.json.JsonValue::class
]
)
class GraalReflectionConfig {}
package com.acme.myapp
import io.quarkus.runtime.annotations.RegisterForReflection
import io.smallrye.graphql.client.typesafe.api.GraphQlClientApi
import io.smallrye.graphql.client.typesafe.api.GraphQlClientBuilder
import io.smallrye.graphql.client.typesafe.api.GraphQlClientHeader
import javax.enterprise.context.ApplicationScoped
import javax.enterprise.inject.Produces
@GraphQlClientApi(endpoint = "https://api.something.com/graphql")
interface MyCoolGraphQlApi {
fun queryName(request: List<RequestItem>): Response
}
// Do not forget this annotation!
@RegisterForReflection
data class RequestItem(var x: Double, var y: Double)
/*
I did not spend time trying to get Annotation Scanning working so I'm using this simple CDI producer.
*/
@ApplicationScoped
class MyCoolGraphQlApiProducer {
@Produces
fun myCoolGraphQlApiClient(): MyCoolGraphQlApi = GraphQlClientBuilder
.newBuilder()
.header(GraphQlClientHeader("Authorization", "Bearer tokenDetails"))
.build(MyCoolGraphQlApi::class.java)
}
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bom</artifactId>
<version>1.5.0.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-parent</artifactId>
<version>18</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-graphql-client</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>jakarta.json</artifactId>
</dependency>
</dependencies>
{
"resources": [
{
"pattern": "META-INF/services/javax.enterprise.inject.spi.Extension"
},
{
"pattern": "META-INF/services/io.smallrye.graphql.client.typesafe.api.GraphQlClientBuilder"
}
]
}
@phillip-kruger
Copy link

Yea, at this point our smallrye client just use rest client as a transport protocol. We still need to do some work there.

@sherl0cks
Copy link
Author

From end users perspective, transport really doesn’t matter so long as the transitive dependencies “just work.” In this case they did not, although I must admit that is one of the more confusing issues I’ve hit in graal native.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment