-
Notifications
You must be signed in to change notification settings - Fork 7
GraphQL client guide
Two GraphQL client types are supported - dynamic and typesafe. The dynamic client is available since feature pack version 1.3. Both client types can be used either in-vm (inside a WildFly instance), or as a standalone (plain Java SE) process.
Your project sources need to depend on the client API module only. The dependency should be provided
because at runtime, the necessary libraries will be taken from WildFly modules, as explained in the following chapter.
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-graphql-client-api</artifactId>
<scope>provided</scope>
</dependency>
There are several modules related to GraphQL clients contained in this feature pack:
-
io.smallrye.graphql.client.vertx
- The implementations of GraphQL clients using Vert.x HTTP client for the underlying transport. This module contains the io.smallrye:smallrye-graphql-client-implementation-vertx Maven artifact. -
io.smallrye.graphql.client.api
- The public-facing API classes that are needed to work with GraphQL clients. Both the implementation modules depend on this, so it will be dragged in automatically. This module contains the io.smallrye:smallrye-graphql-client-api Maven artifact. -
io.smallrye.graphql.client.common
- The common bits for all client implementations. This module is not meant to be used as public API. This module contains the io.smallrye:smallrye-graphql-client Maven artifact.
NOTE: Until feature pack version 1.3, there were two implementation modules - io.smallrye.graphql.client.jaxrs
(which only contains the typesafe client) and io.smallrye.graphql.client.vertx
, which only contains the dynamic client. Since 1.4+, they were both merged into io.smallrye.graphql.client.vertx
, and there is no JAX-RS module anymore.
If you want to use an in-VM GraphQL client (running inside a WildFly instance), then your deployment jar should depend on io.smallrye.graphql.client.vertx
. In both cases, you also need to import services from the module. So, an example line to add to your deployment's META-INF/MANIFEST.MF
:
Dependencies: io.smallrye.graphql.client.vertx services
This will highly depend on how you package your application, but generally, compared to the In-VM approach, you will also need to include the client implementation module on your application's runtime classpath.
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-graphql-client-implementation-vertx</artifactId>
</dependency>
Code examples for using the client can be found within the feature pack's tests:
- Dynamic client inside WildFly: https://github.com/wildfly-extras/wildfly-graphql-feature-pack/blob/main/testsuite/client-vertx/src/test/java/org/wildfly/extras/graphql/test/client/vertx/dynamic/DynamicClientInsideVMTestCase.java
- Dynamic client standalone: https://github.com/wildfly-extras/wildfly-graphql-feature-pack/blob/main/testsuite/client-vertx/src/test/java/org/wildfly/extras/graphql/test/client/vertx/dynamic/DynamicClientOutsideVMTestCase.java
- Typesafe client inside WildFly: https://github.com/wildfly-extras/wildfly-graphql-feature-pack/blob/main/quickstart/src/test/java/org/wildfly/extras/quickstart/microprofile/graphql/test/TypesafeGraphQLClientTestCase.java
- Typesafe client standalone: https://github.com/wildfly-extras/wildfly-graphql-feature-pack/blob/main/testsuite/client-vertx/src/test/java/org/wildfly/extras/graphql/test/client/vertx/typesafe/TypesafeClientOutsideVMTestCase.java
NOTE: In the 'outside VM' scenarios, if there is no CDI container, named configured client instances won't work. You'll need to use the programmatic builder classes only.