{"id":13565827,"url":"https://github.com/pgutkowski/KGraphQL","last_synced_at":"2025-04-03T23:30:40.117Z","repository":{"id":74172753,"uuid":"92776991","full_name":"pgutkowski/KGraphQL","owner":"pgutkowski","description":"Pure Kotlin GraphQL implementation","archived":true,"fork":false,"pushed_at":"2019-05-17T06:42:09.000Z","size":604,"stargazers_count":286,"open_issues_count":26,"forks_count":82,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-11-04T19:42:18.021Z","etag":null,"topics":["graphql","kotlin"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pgutkowski.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-05-29T21:34:47.000Z","updated_at":"2024-09-27T19:15:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"3b0a8b2c-ca5a-4bd5-8e13-c35990673ca8","html_url":"https://github.com/pgutkowski/KGraphQL","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgutkowski%2FKGraphQL","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgutkowski%2FKGraphQL/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgutkowski%2FKGraphQL/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgutkowski%2FKGraphQL/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pgutkowski","download_url":"https://codeload.github.com/pgutkowski/KGraphQL/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247097590,"owners_count":20883121,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graphql","kotlin"],"created_at":"2024-08-01T13:01:56.156Z","updated_at":"2025-04-03T23:30:38.718Z","avatar_url":"https://github.com/pgutkowski.png","language":"Kotlin","funding_links":[],"categories":["Kotlin"],"sub_categories":[],"readme":"# KGraphQL\n\n[![Build Status](https://travis-ci.org/pgutkowski/KGraphQL.svg?branch=master)](https://travis-ci.org/pgutkowski/KGraphQL)\n[![codebeat badge](https://codebeat.co/badges/b26d3c87-7cd1-4358-93cd-45d395669bdc)](https://codebeat.co/projects/github-com-pgutkowski-kgraphql-master)\n[![Coverage Status](https://coveralls.io/repos/github/pgutkowski/KGraphQL/badge.svg?branch=master)](https://coveralls.io/github/pgutkowski/KGraphQL?branch=master)\n[![Download](https://api.bintray.com/packages/pgutkowski/Maven/KGraphQL/images/download.svg) ](https://bintray.com/pgutkowski/Maven/KGraphQL/_latestVersion)\n[![Awesome Kotlin Badge](https://kotlin.link/awesome-kotlin.svg)](https://github.com/KotlinBy/awesome-kotlin)\n\n# Disclaimer\n\nI am no longer able to maintain this project. Please go to https://github.com/aPureBase/KGraphQL, where KGraphQL is still developed.\n\nKGraphQL is [Kotlin](https://kotlinlang.org/) implementation of [GraphQL](http://graphql.org/). It provides rich DSL to setup GraphQL schema. \n\n## Introduction\n\nAs example, let's partially reproduce part of Star Wars schema from [official GraphQL tutorial](http://graphql.org/learn/queries/). First, we need to define our domain model, by plain kotlin classes: \n\n```kotlin\nenum class Episode {\n    NEWHOPE, EMPIRE, JEDI\n}\n\ninterface Character {\n    val id : String\n    val name : String?\n    val friends: List\u003cCharacter\u003e\n    val appearsIn: Set\u003cEpisode\u003e\n}\n\ndata class Human (\n        override val id: String,\n        override val name: String?,\n        override val friends: List\u003cCharacter\u003e,\n        override val appearsIn: Set\u003cEpisode\u003e,\n        val homePlanet: String,\n        val height: Double\n) : Character\n\ndata class Droid (\n        override val id: String,\n        override val name: String?,\n        override val friends: List\u003cCharacter\u003e,\n        override val appearsIn: Set\u003cEpisode\u003e,\n        val primaryFunction : String\n) : Character\n```\nNext, we define our data \n``` kotlin\nval luke = Human(\"2000\", \"Luke Skywalker\", emptyList(), Episode.values().toSet(), \"Tatooine\", 1.72)\n\nval r2d2 = Droid(\"2001\", \"R2-D2\", emptyList(), Episode.values().toSet(), \"Astromech\")\n```\n\nThen, we can create schema:\n\n``` kotlin\n//KGraphQL#schema { } is entry point to create KGraphQL schema\nval schema = KGraphQL.schema {\n\n        //configure method allows you customize schema behaviour\n        configure {\n            useDefaultPrettyPrinter = true\n        }\n\n        //create query \"hero\" which returns instance of Character\n        query(\"hero\") {\n            resolver {episode: Episode -\u003e when(episode){\n                Episode.NEWHOPE, Episode.JEDI -\u003e r2d2\n                Episode.EMPIRE -\u003e luke\n            }}\n        }\n    \n        //create query \"heroes\" which returns list of luke and r2d2\n        query(\"heroes\") {\n            resolver{ -\u003e listOf(luke, r2d2)}\n        }\n\n        //kotlin classes need to be registered with \"type\" method \n        //to be included in created schema type system\n        //class Character is automatically included, \n        //as it is return type of both created queries  \n        type\u003cDroid\u003e()\n        type\u003cHuman\u003e()\n        enum\u003cEpisode\u003e()\n    }\n```\nNow, we can query our schema:\n```kotlin\n//query for hero from episode JEDI and take id, name for any Character, and primaryFunction for Droid or height for Human\nschema.execute(\"{hero(episode: JEDI){\n                    id\n                    name \n                    ... on Droid{primaryFunction} \n                    ... on Human{height}\n                    }\n                }\")\n```\nReturns:\n```json\n{\n  \"data\" : {\n    \"hero\" : {\n      \"id\" : \"2001\",\n      \"name\" : \"R2-D2\",\n      \"primaryFunction\" : \"Astromech\"\n    }\n  }\n}\n```\nQuery for all heroes:\n```kotlin\n//query for all heroes and take id, name for any Character, and primaryFunction for Droid or height for Human\nschema.execute(\"{heroes {\n                    id \n                    name \n                    ... on Droid{primaryFunction} \n                    ... on Human{height}\n                    }\n                }\")\n```\nReturns:\n```json\n{\n  \"data\" : {\n    \"heroes\" : [ {\n      \"id\" : \"2000\",\n      \"name\" : \"Luke Skywalker\",\n      \"height\" : 1.72\n    }, {\n      \"id\" : \"2001\",\n      \"name\" : \"R2-D2\",\n      \"primaryFunction\" : \"Astromech\"\n    } ]\n  }\n}\n```\nAs stated by GraphQL specification, client receives only what is requested. No more, no less.\n\nDetailed documentation can be found in [wiki](https://github.com/pgutkowski/KGraphQL/wiki). For more examples, see KGraphQL demo application: [KGraphQL-NBA2012](https://github.com/pgutkowski/KGraphQL-NBA2012)\n\n## Building\n\nTo build KGraphQL you only need to have JDK8 installed. invoke\n\n``` bash\n./gradlew build\n```\nTo perform local build.\n\n## Versioning\n\nThe versioning is following [Semantic Versioning](http://semver.org/)\n\n## Links \n\nSpecification : http://facebook.github.io/graphql/\n\n## License\n\nKGraphQL is Open Source software released under the [MIT license](https://opensource.org/licenses/MIT)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpgutkowski%2FKGraphQL","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpgutkowski%2FKGraphQL","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpgutkowski%2FKGraphQL/lists"}