Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/zaibacu/java-graphql-client

A client library to access GraphQL APIs
https://github.com/zaibacu/java-graphql-client

client graphql graphql-client java

Last synced: about 2 months ago
JSON representation

A client library to access GraphQL APIs

Awesome Lists containing this project

README

        

# Java GraphQL Client

Interact with GraphQL API via Java. Nothing more, nothing less.

# Quickstart

## Install

Maven:
```xml

com.github.zaibacu
java-graphql-client
1.2-SNAPSHOT

```

## Usage

### Query

```java
public class Example{
public List fetchProducts(){
GraphqlClient client = GraphqlClient
.builder()
.withUrl("http://localhost:8000/graphql")
.build();

List products = client
.query("products")
.withParameter("category", "shoes")
.withParameter("priceRange", "cheap")
.execute("products", Product.class);

return products;
}
}
```

Where `Product` is:

```java
public class Product implements Serializable{
public String name;
public double price;
public String category;
public String priceRange;
}
```

### Mutation

```java
public class Example {
public void addProduct(Product product){
GraphqlClient client = GraphqlClient
.builder()
.withUrl("http://localhost:8000/graphql")
.build();
client
.mutate("addProduct")
.withParameter("name", "test")
.withParameter("price", 42.0)
.withParameter("category", "shoes")
.withParameter("priceRange", "cheap")
.execute("products");

}
}
```