Skip to content

qwlabs/graphql-builder

Repository files navigation

Graphql Builder

Maven Central Commit License: GPL v3

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"));
  • 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
}

mutation

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
}