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