From 233996e0a3d5d8c605eebf63670ded9755fda95e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3gvan=20Olsen?= Date: Fri, 27 Nov 2020 17:32:18 +0000 Subject: [PATCH 1/2] Added KGraphQL to the code list --- .../java-kotlin-android/server/kgraphql.md | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/content/code/language-support/java-kotlin-android/server/kgraphql.md diff --git a/src/content/code/language-support/java-kotlin-android/server/kgraphql.md b/src/content/code/language-support/java-kotlin-android/server/kgraphql.md new file mode 100644 index 0000000000..ffdbb546ad --- /dev/null +++ b/src/content/code/language-support/java-kotlin-android/server/kgraphql.md @@ -0,0 +1,61 @@ +--- +name: KGraphQL +description: KGraphQL is a Kotlin implementation of GraphQL. It provides a rich DSL to set up the GraphQL schema. +url: https://kgraphql.io/ +github: aPureBase/KGraphQL +--- + +Here's a simple example on how to create a simple schema based on a kotlin data class plus a property resolver that gets applied onto your class. + +```kotlin +data class Article(val id: Int, val text: String) + +fun main() { + val schema = KGraphQL.schema { + query("article") { + resolver { id: Int?, text: String -> + Article(id ?: -1, text) + } + } + type
{ + property("fullText") { + resolver { article: Article -> + "${article.id}: ${article.text}" + } + } + } + } + + schema.execute(""" + { + article(id: 5, text: "Hello World") { + id + fullText + } + } + """).let(::println) +} +``` + +KGraphQL is using coroutines behind the scenes to provide great asynchronous performance. + +See [KGraphQL docs](https://kgraphql.io/Installation/) for more in depth usage. + +## Ktor Plugin + +KGraphQL has a Ktor plugin which gives you a fully functional GraphQL server with a single [install](https://ktor.io/docs/zfeatures.html) function call. Example below shows how to set up a GraphQL server within Ktor and it will give you a [GraphQL Playground](https://github.com/graphql/graphql-playground) out of the box by entering `localhost:8080/graphql`. + +```kotlin +fun Application.module() { + install(GraphQL) { + playground = true + schema { + query("hello") { + resolver { -> "World!" } + } + } + } +} +``` + +You can follow the [Ktor tutorial](https://kgraphql.io/Tutorials/ktor/) to set up a KGraphQL server with ktor from scratch up. From 731208a652e24ece2b17f7fddcef0d327219dd2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3gvan=20Olsen?= Date: Fri, 27 Nov 2020 17:56:03 +0000 Subject: [PATCH 2/2] Update kgraphql.md --- .../language-support/java-kotlin-android/server/kgraphql.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/code/language-support/java-kotlin-android/server/kgraphql.md b/src/content/code/language-support/java-kotlin-android/server/kgraphql.md index ffdbb546ad..bd73f061f1 100644 --- a/src/content/code/language-support/java-kotlin-android/server/kgraphql.md +++ b/src/content/code/language-support/java-kotlin-android/server/kgraphql.md @@ -5,7 +5,7 @@ url: https://kgraphql.io/ github: aPureBase/KGraphQL --- -Here's a simple example on how to create a simple schema based on a kotlin data class plus a property resolver that gets applied onto your class. +Here's an example on how to create a simple schema based on a kotlin data class plus a property resolver that gets applied onto your class. ```kotlin data class Article(val id: Int, val text: String)