Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/graphqly/vertx-graphql-client
An elegant implementation for code-first GraphQL clients
https://github.com/graphqly/vertx-graphql-client
code-first graphql graphql-reflector
Last synced: 26 days ago
JSON representation
An elegant implementation for code-first GraphQL clients
- Host: GitHub
- URL: https://github.com/graphqly/vertx-graphql-client
- Owner: graphqly
- License: apache-2.0
- Created: 2020-02-02T11:20:53.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-06-21T15:05:28.000Z (over 2 years ago)
- Last Synced: 2024-05-19T14:30:41.544Z (7 months ago)
- Topics: code-first, graphql, graphql-reflector
- Language: Java
- Size: 95.7 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-graphql-java - vertx-graphql-client - first GraphQL clients (Schema Libraries / Code First)
README
# vertx-graphql-client
*An elegant implementation for code-first GraphQL clients using graphql-reflector & vertx*
## Overview
This code-first implementation is a deadly simple GraphQL client
## Installation
Please add `vertx-graphql-client` to your Maven projects
```
io.github.graphqly
vertx-graphql-client
0.1.0```
## Usage
You can see demo code in [example](src/main/java/io/github/graphqly/client/example/App.java)
## Demo
### Prepare
This following demo code assumes that you're already had a GraphQL service as followed:
```graphql
input ManifestEchoRequest{
name: String
}type ManifestEchoResponse{
# The output message will be: "Hello " + request.name
message: String
}type Query {
manifestEcho(request: ManifestEchoRequest): ManifestEchoResponse
}
```Make sure it can be reached at: `http://localhost:4000/graphql`
### Integrate
It's easy to define our abstract class ManifestService
![](docs/images/code-structures.png)
You may see the similarities between our Java class and the GraphQL definition above.
The code:
```java
GraphqlClient client = GraphqlClient.newBuilder()
// Optionally set the endpoint
// Default: http://localhost:4000/graphql
.endpoint("http://localhost:4000/graphql")
// Optionally set keep-alive for our http connection
// Default: true
.keepAlive(true)
// Optionally set if we need to use SSL
// Default: false
.useSSL(false)
// Optionally set User-Agent string
// Default: graphqly/0.1.0
.userAgent("demo")
// Optionally set vertx instance
// Default: null (auto-created later)
.vertx(vertx)
.build();Future response =
client.callDefault(
ManifestService.class,
"manifestEcho",
ManifestEchoRequest.of("Andy"),
ManifestEchoResponse.class);response.setHandler(
ar -> {
if (ar.succeeded()) {
System.out.println(ar.result().message);
}
});
```## Demo
```bash
mvn compile
mvn exec:java -Dexec.mainClass="io.github.graphqly.client.example.App" -Dlog4j.configurationFile=log4j2.xml
```You may see following output:
```text
Hello Andy
```