Skip to content

Commit e94e736

Browse files
committed
Introduce support for custom context type for resolvers
1 parent 613bbeb commit e94e736

35 files changed

+306
-103
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
build
22
.gradle
3-
.idea
3+
.idea
4+
/out

README.MD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![Build Status](https://travis-ci.org/pgutkowski/KGraphQL.svg?branch=master)](https://travis-ci.org/pgutkowski/KGraphQL)
44
[![codebeat badge](https://codebeat.co/badges/b26d3c87-7cd1-4358-93cd-45d395669bdc)](https://codebeat.co/projects/github-com-pgutkowski-kgraphql-master)
55
[![Coverage Status](https://coveralls.io/repos/github/pgutkowski/KGraphQL/badge.svg?branch=master)](https://coveralls.io/github/pgutkowski/KGraphQL?branch=master)
6-
[ ![Download](https://api.bintray.com/packages/pgutkowski/Maven/KGraphQL/images/download.svg) ](https://bintray.com/pgutkowski/Maven/KGraphQL/_latestVersion)
6+
[![Download](https://api.bintray.com/packages/pgutkowski/Maven/KGraphQL/images/download.svg) ](https://bintray.com/pgutkowski/Maven/KGraphQL/_latestVersion)
77
[![Awesome Kotlin Badge](https://kotlin.link/awesome-kotlin.svg)](https://github.com/KotlinBy/awesome-kotlin)
88

99
KGraphQL is [Kotlin](https://kotlinlang.org/) implementation of [GraphQL](http://graphql.org/). It provides rich DSL to setup GraphQL schema.

build.gradle

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ group 'com.github.pgutkowski'
22
version '0.2.3'
33

44
buildscript {
5-
ext.kotlin_version = '1.1.3'
5+
ext.kotlin_version = '1.1.4'
66

77
repositories {
88
mavenCentral()
@@ -30,9 +30,6 @@ apply plugin: "com.jfrog.bintray"
3030

3131
repositories {
3232
mavenCentral()
33-
maven {
34-
url "http://dl.bintray.com/kotlin/kotlin-eap-1.1"
35-
}
3633
jcenter()
3734
}
3835

src/jmh/kotlin/com/github/pgutkowski/kgraphql/BenchmarkSchema.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ object BenchmarkSchema {
2121

2222
val threeResolver : ()-> ModelThree = { ModelThree("", ones.map { ModelTwo(it, it.quantity..10) }) }
2323

24-
fun create(block : SchemaBuilder.()-> Unit): Schema = KGraphQL.schema {
24+
fun create(block : SchemaBuilder<Unit>.()-> Unit): Schema<Unit> = KGraphQL.schema {
2525
block()
2626
query("one"){
2727
resolver(oneResolver)

src/jmh/kotlin/com/github/pgutkowski/kgraphql/ParallelExecutionBenchmark.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import java.util.concurrent.TimeUnit
2222
@Fork(value = 5)
2323
open class ParallelExecutionBenchmark {
2424

25-
var schema : Schema = KGraphQL.schema { }
25+
var schema : Schema<Unit> = KGraphQL.schema { }
2626

2727
@Setup
2828
fun setup(){

src/jmh/kotlin/com/github/pgutkowski/kgraphql/RequestCachingBenchmark.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ open class RequestCachingBenchmark {
2323
@Param("true", "false")
2424
var caching = true
2525

26-
lateinit var schema : Schema
26+
lateinit var schema : Schema<Unit>
2727

2828
@Setup
2929
fun setup(){

src/jmh/kotlin/com/github/pgutkowski/kgraphql/SimpleExecutionOverheadBenchmark.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ open class SimpleExecutionOverheadBenchmark {
2828
@Param("true", "false")
2929
var withKGraphQL = true
3030

31-
lateinit var schema : Schema
31+
lateinit var schema : Schema<Unit>
3232

3333
lateinit var objectMapper : ObjectMapper
3434

src/main/kotlin/com/github/pgutkowski/kgraphql/KGraphQL.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@ package com.github.pgutkowski.kgraphql
22

33
import com.github.pgutkowski.kgraphql.schema.Schema
44
import com.github.pgutkowski.kgraphql.schema.dsl.SchemaBuilder
5+
import kotlin.reflect.KClass
56

67

78
class KGraphQL {
89
companion object {
9-
fun schema(init : SchemaBuilder.() -> Unit) : Schema {
10-
return SchemaBuilder(init).build()
10+
fun schema(init : SchemaBuilder<Unit>.() -> Unit) = schema(Unit::class, init)
11+
12+
/**
13+
* accepts instance of [KClass], instead of reified generic to avoid method signature clash
14+
*/
15+
fun <Context : Any> schema(contextClass: KClass<Context>, init : SchemaBuilder<Context>.() -> Unit) : Schema<Context> {
16+
return SchemaBuilder(init).build(contextClass)
1117
}
1218
}
1319
}

src/main/kotlin/com/github/pgutkowski/kgraphql/request/Variables.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import kotlin.reflect.KType
1010

1111
@Suppress("UNCHECKED_CAST")
1212
data class Variables(
13-
private val typeDefinitionProvider: LookupSchema,
13+
private val typeDefinitionProvider: LookupSchema<*>,
1414
private val variablesJson: VariablesJson,
1515
private val variables: List<OperationVariable>?
1616
) {

src/main/kotlin/com/github/pgutkowski/kgraphql/request/VariablesJson.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import kotlin.reflect.jvm.jvmErasure
1414
/**
1515
* Represents already parsed variables json
1616
*/
17-
interface VariablesJson{
17+
interface VariablesJson {
1818

1919
fun <T : Any>get(kClass: KClass<T>, kType: KType, key : String) : T?
2020

0 commit comments

Comments
 (0)