Skip to content

Commit 5bf1412

Browse files
committed
#134: Removed usages & references to JCenter
1 parent c6ede0a commit 5bf1412

File tree

7 files changed

+116
-47
lines changed

7 files changed

+116
-47
lines changed

build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ plugins {
1414

1515
allprojects {
1616
repositories {
17-
jcenter()
1817
mavenCentral()
1918
}
2019
}

docs/content/Installation/index.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ title: Getting Started
33
weight: 1
44
---
55

6-
[![Bintray](https://api.bintray.com/packages/apurebase/apurebase/kgraphql/images/download.svg)](https://bintray.com/apurebase/apurebase/kgraphql)
6+
[![Maven Central](https://img.shields.io/maven-central/v/com.apurebase/kgraphql.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.apurebase%22%20AND%20a:%22kgraphql%22)
77

8-
KGraphQL is pushed to bintray repository and also linked to JCenter. It requires kotlin compiler version 1.3.x and require kotlin runtime of the same version as a dependency.
8+
KGraphQL is pushed to MavenCentral repository. It requires kotlin compiler version 1.4.x and require kotlin runtime of the same version as a dependency.
99

1010
=== "Kotlin Gradle Script"
11-
Add Bintray JCenter repository:
11+
Add Maven Central repository:
1212

1313
```kotlin
1414
repositories {
15-
jcenter()
15+
mavenCentral()
1616
}
1717
```
1818

@@ -24,11 +24,11 @@ KGraphQL is pushed to bintray repository and also linked to JCenter. It requires
2424

2525

2626
=== "Gradle"
27-
Add Bintray JCenter repository:
27+
Add Maven Central repository:
2828

2929
```groovy
3030
repositories {
31-
jcenter()
31+
mavenCentral()
3232
}
3333
```
3434

@@ -40,14 +40,14 @@ KGraphQL is pushed to bintray repository and also linked to JCenter. It requires
4040

4141

4242
=== "Maven"
43-
Add Bintray JCenter repository to section:
43+
Add Maven Central repository to section:
4444

4545
```xml
4646
<repositories>
47-
<repository>
48-
<id>jcenter</id>
49-
<url>https://jcenter.bintray.com/</url>
50-
</repository>
47+
<repository>
48+
<id>central</id>
49+
<url>https://repo1.maven.org/maven2</url>
50+
</repository>
5151
</repositories>
5252
```
5353

gradle.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# KGraphQL version
2-
version=0.17.5
2+
version=0.17.6
33

44
# Dependencies
55
coroutine_version=1.3.9
66
jackson_version=2.12.2
77
caffeine_version=3.0.0
88
serialization_version=1.0.0-RC
9-
kDataLoader_version=0.1.1
9+
kDataLoader_version=0.3.0
1010
ktor_version=1.5.2
1111

1212
# Test-Dependencies
@@ -26,6 +26,6 @@ jacoco_version=0.8.5
2626

2727
# Example Dependencies
2828
logback_version=1.2.1
29-
exposed_version=0.21.1
29+
exposed_version=0.30.2
3030
h2_version=1.4.200
3131
hikari_version=4.0.3

kgraphql-ktor/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ dependencies {
3131

3232
testImplementation("org.junit.jupiter:junit-jupiter-api:$junit_version")
3333
testImplementation("org.amshove.kluent:kluent:$kluent_version")
34-
testImplementation("me.lazmaid.kraph:kraph:0.6.1")
3534
testImplementation("io.ktor:ktor-server-test-host:$ktor_version")
3635
testImplementation("io.ktor:ktor-auth:$ktor_version")
3736
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junit_version")
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.apurebase.kgraphql
2+
3+
import kotlinx.serialization.json.*
4+
5+
// MARK: Using this is a temporary solution as JCenter is closed down.
6+
// We should either create our own GraphQL client or find some other active library to do this for us.
7+
8+
9+
fun graphqlQuery(block: Kraph.() -> Unit): Kraph {
10+
return Kraph("query").apply(block)
11+
}
12+
fun graphqlMutation(block: Kraph.() -> Unit): Kraph {
13+
return Kraph("mutation").apply(block)
14+
}
15+
16+
class Kraph(
17+
private val type: String,
18+
private val variables: MutableList<Kraph.Variable> = mutableListOf(),
19+
private val root: Boolean = true,
20+
): List<Kraph.Variable> by variables {
21+
22+
private val fields = mutableListOf<Kraph>()
23+
24+
fun field(name: String) = fields.add(Kraph(name, variables, false))
25+
fun field(name: String, block: Kraph.() -> Unit) = fields.add(Kraph(name, variables, false).apply(block))
26+
27+
data class Variable(
28+
val name: String,
29+
val typeName: String,
30+
val value: JsonElement,
31+
)
32+
33+
fun variable(name: String, typeName: String, block: JsonObjectBuilder.() -> Unit) = variables.add(
34+
Variable(name, typeName, buildJsonObject(block))
35+
)
36+
fun variable(name: String, typeName: String, value: String) = variables.add(
37+
Variable(name, typeName, JsonPrimitive(value))
38+
)
39+
fun variable(name: String, typeName: String, value: Int) = variables.add(
40+
Variable(name, typeName, JsonPrimitive(value))
41+
)
42+
43+
private fun print(): String = buildString {
44+
append("$type ")
45+
if (variables.isNotEmpty() && root) {
46+
append("MyQuery(${variables.joinToString(",") { "\$${it.name}: ${it.typeName}" }})")
47+
}
48+
if (fields.isNotEmpty()) {
49+
appendLine("{")
50+
fields.map { appendLine(it.print()) }
51+
appendLine("}")
52+
} else appendLine()
53+
}
54+
55+
fun build(): String = buildString {
56+
append("{")
57+
append("\"query\": \"${print()}\"")
58+
59+
if (variables.isNotEmpty()) {
60+
append(",")
61+
append("\"variables\": {")
62+
variables.map {
63+
append("\"${it.name}\": ${it.value}")
64+
}
65+
append("}")
66+
}
67+
append("}")
68+
}
69+
}

kgraphql-ktor/src/test/kotlin/com/apurebase/kgraphql/KtorFeatureTest.kt

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.apurebase.kgraphql
22

33
import io.ktor.application.*
44
import io.ktor.auth.*
5-
import io.ktor.util.*
5+
import kotlinx.serialization.json.*
66
import org.amshove.kluent.shouldBeEqualTo
77
import org.junit.jupiter.api.Test
88

@@ -18,10 +18,8 @@ class KtorFeatureTest : KtorTest() {
1818
}
1919
}
2020

21-
server {
22-
query {
23-
field("hello")
24-
}
21+
server("query") {
22+
field("hello")
2523
} shouldBeEqualTo "{\"data\":{\"hello\":\"World!\"}}"
2624

2725
}
@@ -34,10 +32,8 @@ class KtorFeatureTest : KtorTest() {
3432
}
3533
}
3634

37-
server {
38-
mutation {
39-
field("hello")
40-
}
35+
server("mutation") {
36+
field("hello")
4137
} shouldBeEqualTo "{\"data\":{\"hello\":\"World! mutation\"}}"
4238

4339
}
@@ -69,19 +65,15 @@ class KtorFeatureTest : KtorTest() {
6965
}
7066
}
7167

72-
server {
73-
query {
74-
fieldObject("actor") {
75-
field("name(addStuff: true)")
76-
}
68+
server("query") {
69+
field("actor") {
70+
field("name(addStuff: true)")
7771
}
7872
} shouldBeEqualTo "{\"data\":{\"actor\":{\"name\":\"${georgeName}STUFF\"}}}"
7973

80-
server {
81-
query {
82-
fieldObject("actor") {
83-
field("nickname")
84-
}
74+
server("query") {
75+
field("actor") {
76+
field("nickname")
8577
}
8678
} shouldBeEqualTo "{\"data\":{\"actor\":{\"nickname\":\"Hodor and $georgeName\"}}}"
8779
}
@@ -100,14 +92,21 @@ class KtorFeatureTest : KtorTest() {
10092
query("test") { resolver { input: InputTwo -> "success: $input" } }
10193
}
10294

103-
val variables = """
104-
{"one":{"enum":"M1","id":"M1"},"quantity":3434,"tokens":["23","34","21","434"]}
105-
""".trimIndent()
95+
server("query") {
96+
field("test(input: \$two)")
10697

107-
server {
108-
query {
109-
field("test(input: \$two)")
110-
variable("two", "InputTwo!", variables)
98+
variable("two", "InputTwo!") {
99+
putJsonObject("one") {
100+
put("enum", "M1")
101+
put("id", "M1")
102+
}
103+
put("quantity", 3434)
104+
putJsonArray("tokens") {
105+
add("23")
106+
add("34")
107+
add("21")
108+
add("434")
109+
}
111110
}
112111
} shouldBeEqualTo "{\"data\":{\"test\":\"success: InputTwo(one=InputOne(enum=M1, id=M1), quantity=3434, tokens=[23, 34, 21, 434])\"}}"
113112
}

kgraphql-ktor/src/test/kotlin/com/apurebase/kgraphql/KtorTest.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ import io.ktor.application.*
55
import io.ktor.auth.*
66
import io.ktor.http.*
77
import io.ktor.server.testing.*
8-
import io.ktor.util.*
9-
import me.lazmaid.kraph.Kraph
8+
109

1110
open class KtorTest {
1211

13-
fun withServer(ctxBuilder: ContextBuilder.(ApplicationCall) -> Unit = {}, block: SchemaBuilder.() -> Unit): (Kraph.() -> Unit) -> String {
14-
return {
12+
fun withServer(ctxBuilder: ContextBuilder.(ApplicationCall) -> Unit = {}, block: SchemaBuilder.() -> Unit): (String, Kraph.() -> Unit) -> String {
13+
return { type, kraph ->
1514
withTestApplication({
1615
install(Authentication) {
1716
basic {
@@ -33,7 +32,11 @@ open class KtorTest {
3332
uri = "graphql"
3433
method = HttpMethod.Post
3534
addHeader(HttpHeaders.ContentType, "application/json;charset=UTF-8")
36-
setBody(Kraph { it(this) }.toRequestString())
35+
setBody(when(type.toLowerCase().trim()) {
36+
"query" -> graphqlQuery(kraph).build()
37+
"mutation" -> graphqlMutation(kraph).build()
38+
else -> throw TODO("$type is not a valid graphql operation type")
39+
}.also(::println))
3740
}.response.content!!
3841
}
3942
}

0 commit comments

Comments
 (0)