All Projects → pgutkowski → Kgraphql

pgutkowski / Kgraphql

Licence: mit
Pure Kotlin GraphQL implementation

Programming Languages

kotlin
9241 projects

Labels

Projects that are alternatives of or similar to Kgraphql

Chat App Flutter
It's a fully functioning chat app built using flutter. With both one on one chats and group chats
Stars: ✭ 277 (-3.48%)
Mutual labels:  graphql
Graphql Erlang
GraphQL implementation in Erlang.
Stars: ✭ 284 (-1.05%)
Mutual labels:  graphql
Babel Plugin Import Graphql
Enables import syntax for .graphql and .gql files
Stars: ✭ 284 (-1.05%)
Mutual labels:  graphql
Gqless
a GraphQL client without queries
Stars: ✭ 3,569 (+1143.55%)
Mutual labels:  graphql
Poc Graphql
Research on GraphQL from an AppSec point of view.
Stars: ✭ 282 (-1.74%)
Mutual labels:  graphql
Morpheus Graphql
Haskell GraphQL Api, Client and Tools
Stars: ✭ 285 (-0.7%)
Mutual labels:  graphql
Graphql Flex
🎣A flexible GraphQL IDE by @TipeIO built in @VueJS
Stars: ✭ 277 (-3.48%)
Mutual labels:  graphql
Insomnia
The open-source, cross-platform API client for GraphQL, REST, and gRPC.
Stars: ✭ 18,969 (+6509.41%)
Mutual labels:  graphql
Apollo Elements
🚀🌛 Use the Launch Platform 👩‍🚀👨‍🚀
Stars: ✭ 278 (-3.14%)
Mutual labels:  graphql
Sgqlc
Simple GraphQL Client
Stars: ✭ 286 (-0.35%)
Mutual labels:  graphql
Apollo Ios
📱  A strongly-typed, caching GraphQL client for iOS, written in Swift.
Stars: ✭ 3,192 (+1012.2%)
Mutual labels:  graphql
Graphql Clj
A Clojure library that provides GraphQL implementation.
Stars: ✭ 281 (-2.09%)
Mutual labels:  graphql
Ng Notadd
In-middle background front-end solution based on angular material 基于Angular Material的中后台前端解决方案
Stars: ✭ 287 (+0%)
Mutual labels:  graphql
Boilerplay
Using the latest technology in the Scala ecosystem, Boilerplay is a reactive web application built on Play Framework, ScalaJS, Silhouette, Sangria/GraphQL, and PostgreSQL. It provides a good starting point for whatever you want to build.
Stars: ✭ 279 (-2.79%)
Mutual labels:  graphql
Dgraph
Native GraphQL Database with graph backend
Stars: ✭ 17,127 (+5867.6%)
Mutual labels:  graphql
Graphik
Graphik is a Backend as a Service implemented as an identity-aware document & graph database with support for gRPC and graphQL
Stars: ✭ 277 (-3.48%)
Mutual labels:  graphql
Wp Graphiql
GraphiQL IDE, fine tuned for use with WPGraphQL
Stars: ✭ 284 (-1.05%)
Mutual labels:  graphql
Graphql Let
A layer to start/scale the use of GraphQL code generator.
Stars: ✭ 282 (-1.74%)
Mutual labels:  graphql
Apollo Client
🚀  A fully-featured, production ready caching GraphQL client for every UI framework and GraphQL server.
Stars: ✭ 17,070 (+5847.74%)
Mutual labels:  graphql
Ssr Sample
A minimum sample of Server-Side-Rendering, Single-Page-Application and Progressive Web App
Stars: ✭ 285 (-0.7%)
Mutual labels:  graphql

KGraphQL

Build Status codebeat badge Coverage Status Download Awesome Kotlin Badge

Disclaimer

I am no longer able to maintain this project. Please go to https://github.com/aPureBase/KGraphQL, where KGraphQL is still developed.

KGraphQL is Kotlin implementation of GraphQL. It provides rich DSL to setup GraphQL schema.

Introduction

As example, let's partially reproduce part of Star Wars schema from official GraphQL tutorial. First, we need to define our domain model, by plain kotlin classes:

enum class Episode {
    NEWHOPE, EMPIRE, JEDI
}

interface Character {
    val id : String
    val name : String?
    val friends: List<Character>
    val appearsIn: Set<Episode>
}

data class Human (
        override val id: String,
        override val name: String?,
        override val friends: List<Character>,
        override val appearsIn: Set<Episode>,
        val homePlanet: String,
        val height: Double
) : Character

data class Droid (
        override val id: String,
        override val name: String?,
        override val friends: List<Character>,
        override val appearsIn: Set<Episode>,
        val primaryFunction : String
) : Character

Next, we define our data

val luke = Human("2000", "Luke Skywalker", emptyList(), Episode.values().toSet(), "Tatooine", 1.72)

val r2d2 = Droid("2001", "R2-D2", emptyList(), Episode.values().toSet(), "Astromech")

Then, we can create schema:

//KGraphQL#schema { } is entry point to create KGraphQL schema
val schema = KGraphQL.schema {

        //configure method allows you customize schema behaviour
        configure {
            useDefaultPrettyPrinter = true
        }

        //create query "hero" which returns instance of Character
        query("hero") {
            resolver {episode: Episode -> when(episode){
                Episode.NEWHOPE, Episode.JEDI -> r2d2
                Episode.EMPIRE -> luke
            }}
        }
    
        //create query "heroes" which returns list of luke and r2d2
        query("heroes") {
            resolver{ -> listOf(luke, r2d2)}
        }

        //kotlin classes need to be registered with "type" method 
        //to be included in created schema type system
        //class Character is automatically included, 
        //as it is return type of both created queries  
        type<Droid>()
        type<Human>()
        enum<Episode>()
    }

Now, we can query our schema:

//query for hero from episode JEDI and take id, name for any Character, and primaryFunction for Droid or height for Human
schema.execute("{hero(episode: JEDI){
                    id
                    name 
                    ... on Droid{primaryFunction} 
                    ... on Human{height}
                    }
                }")

Returns:

{
  "data" : {
    "hero" : {
      "id" : "2001",
      "name" : "R2-D2",
      "primaryFunction" : "Astromech"
    }
  }
}

Query for all heroes:

//query for all heroes and take id, name for any Character, and primaryFunction for Droid or height for Human
schema.execute("{heroes {
                    id 
                    name 
                    ... on Droid{primaryFunction} 
                    ... on Human{height}
                    }
                }")

Returns:

{
  "data" : {
    "heroes" : [ {
      "id" : "2000",
      "name" : "Luke Skywalker",
      "height" : 1.72
    }, {
      "id" : "2001",
      "name" : "R2-D2",
      "primaryFunction" : "Astromech"
    } ]
  }
}

As stated by GraphQL specification, client receives only what is requested. No more, no less.

Detailed documentation can be found in wiki. For more examples, see KGraphQL demo application: KGraphQL-NBA2012

Building

To build KGraphQL you only need to have JDK8 installed. invoke

./gradlew build

To perform local build.

Versioning

The versioning is following Semantic Versioning

Links

Specification : http://facebook.github.io/graphql/

License

KGraphQL is Open Source software released under the MIT license

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].