Skip to content

Commit c296f2c

Browse files
committed
Add JavaClient to run the graphql query
1 parent 6c33523 commit c296f2c

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

graphql-queries/JavaClient.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
///usr/bin/env jbang "$0" "$@" ; exit $?
2+
3+
//DEPS io.smallrye:smallrye-graphql-client-implementation-vertx:2.10.0
4+
//DEPS org.eclipse:yasson:2.0.4
5+
6+
//JAVA 17
7+
8+
import java.nio.file.Files;
9+
import java.nio.file.Paths;
10+
11+
import io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient;
12+
import io.smallrye.graphql.client.Response;
13+
import io.smallrye.graphql.client.vertx.dynamic.VertxDynamicGraphQLClientBuilder;
14+
15+
import io.vertx.core.Vertx;
16+
17+
class JavaClient {
18+
public static void main(String... args) throws Exception {
19+
String query = Files.readString(Paths.get("work-items.query.graphql"));
20+
Vertx vertx = Vertx.vertx();
21+
DynamicGraphQLClient client = new VertxDynamicGraphQLClientBuilder()
22+
.url("https://gitlab.com/api/graphql")
23+
.vertx(vertx)
24+
.build();
25+
try {
26+
Response response = client.executeSync(query);
27+
System.out.println(response);
28+
} finally {
29+
client.close();
30+
vertx.close();
31+
}
32+
}
33+
}

graphql-queries/README.adoc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
== GraphQL queries
2+
3+
This folder contains some test GraphQL queries for gitlab.com
4+
5+
The queries can be exectued directly online: https://gitlab.com/-/graphql-explorer
6+
7+
GitLab GraphQL API: https://docs.gitlab.com/ee/api/graphql/
8+
9+
=== Run with java
10+
11+
The script `JavaClient.java` contains the necessary code to run the `work-items.query.graphql` with a java client.
12+
13+
Just run `jbang JavaClient.java` to run the query and see the results.

0 commit comments

Comments
 (0)