Graphql Builder
GraphQL query builder for Java
Installation
Maven
<dependency>
<groupId>com.qwlabs</groupId>
<artifactId>graphql-builder</artifactId>
<version>0.2.15</version>
<type>pom</type>
</dependency>
Gradle
implementation 'com.qwlabs:graphql-builder:0.2.15'
Usage
query
Gql gql=Gql.query("contents")
.fields(GqlField.of("nodes").fields("id","content","createdAt"),
GqlField.of("totalCount"),
GqlField.of("pageInfo").fields("limit","offset"));
query {contents{nodes{id content createdAt} totalCount pageInfo{limit offset}}}
- gql.buildPrettifySegment()
query {
contents {
nodes {
id
content
createdAt
}
totalCount
pageInfo {
limit
offset
}
}
}
{"query":"query {contents{nodes{id content createdAt} totalCount pageInfo{limit offset}}}", "variables": null}
{
"query":"query {
contents {
nodes {
id
content
createdAt
}
totalCount
pageInfo {
limit
offset
}
}
}",
"variables": null
}
mutation
Gql gql = Gql.mutation("createContents")
.variables(GqlVariable.of("input", GqlVariables.of(
GqlVariable.of("content", "111")
)))
.fields(GqlFields.of("id", "content", "createdAt"));
mutation {createContents(input:{content:"111"}){id content createdAt}}
- gql.buildPrettifySegment()
mutation {
createContents(input:{content:"111"}) {
id
content
createdAt
}
}
{"query":"mutation {createContents(input:{content:\"111\"}){id content createdAt}}", "variables": null}
{
"query":"mutation {
createContents(input:{content:\"111\"}) {
id
content
createdAt
}
}",
"variables": null
}