Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/prestongarno/kotlinq
Kotlin DSL for GraphQL
https://github.com/prestongarno/kotlinq
graphql graphql-schema java kotlin
Last synced: 28 days ago
JSON representation
Kotlin DSL for GraphQL
- Host: GitHub
- URL: https://github.com/prestongarno/kotlinq
- Owner: prestongarno
- License: other
- Created: 2017-07-28T20:52:26.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-06-18T05:18:36.000Z (over 6 years ago)
- Last Synced: 2024-10-01T08:41:38.323Z (about 1 month ago)
- Topics: graphql, graphql-schema, java, kotlin
- Language: Kotlin
- Homepage: http://kotlinq.org
- Size: 5.68 MB
- Stars: 29
- Watchers: 4
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Contributing: docs/contributing.md
- License: LICENSE.txt
- Code of conduct: code_of_conduct.md
Awesome Lists containing this project
- awesome-ccamel - prestongarno/kotlinq - Kotlin DSL for GraphQL (Kotlin)
README
***a Kotlin GraphQL client for composable, reusable GraphQL queries***
-----------------------------[![Download](https://api.bintray.com/packages/prestongarno/kotlinq/kotlinq-core/images/download.svg)](https://bintray.com/com/prestongarno/kotlinq/kotlinq-core/_latestVersion)
[![Build Status](https://travis-ci.org/prestongarno/kotlinq.svg?branch=master)](https://travis-ci.org/prestongarno/kotlinq)## Query DSL (new with version 0.4.0)
Version 0.4.0 supports [**ad-hoc, type-hinted**](https://github.com/prestongarno/kotlinq/blob/query-dsl/query-dsl/src/main/kotlin/org/kotlinq/dsl/extensions/FreePropertyExtensionScope.kt) but natively expressed queries and mutations!
A powerful feature is the ability to **compose** and **reuse** graphql queries easily.
## GraphQL Star Wars example
Define a "Human" type fragment:
```
fun humanDef() = fragment("Human") {
"name"(string)
"nicknames" listOf !string
}
```Define a "Droid" type fragment:
```
fun droidDef() = fragment("Droid") {
"modelNumber"(string)
"owner" on humanDef()
}
```Now, define a query for Star Wars characters:
```
fun charactersQuery(fragments: List) = query {
"characters"("first" to 10)..listOf {
on..fragments
}
}
```Query characters from Star Wars that are humans:
```
val query = charactersQuery(listOf(humanDef())
println(query.toGraphQl(pretty = true))
```prints:
```
{
characters(first: 100) {
__typename
... on Human {
name
nicknames
}
}
}
```But if you want to query both humans and droids, to do so it's as simple as:
```
val query = charactersQuery(listOf(humanDef(), droidDef()))
println(query.toGraphQl(pretty = true))
```which results in:
```
{
characters(first: 100) {
__typename
... on Human {
name
nicknames
}
... on Droid {
modelNumber
maker {
name
nicknames
}
}
}
}
```