Skip to content

Commit a9cd3e3

Browse files
authored
Merge pull request #3 from cufyorg/supremacy
Supremacy
2 parents 096e18a + 1aadf5d commit a9cd3e3

81 files changed

Lines changed: 7617 additions & 1758 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.idea
22
.gradle
3+
/out
34
**/build/
45
!src/**/build/
56

README.md

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
# Kaguya Shinomiya [![](https://jitpack.io/v/org.cufy/kaguya.svg)](https://jitpack.io/#org.cufy/kaguya)
1+
# Graphkt [![](https://jitpack.io/v/org.cufy/graphkt.svg)](https://jitpack.io/#org.cufy/graphkt)
22

33
A GraphQL library based on
44
[graphql-java](http://github.com/graphql-java/graphql-java)
55
with kotlin-friendly builders and ktor routing extensions.
66

7-
> Please, Don't touch my harem 😪
8-
97
### Install
108

119
The main way of installing this library is
@@ -20,7 +18,7 @@ repositories {
2018

2119
dependencies {
2220
// Replace TAG with the desired version
23-
implementation("org.cufy:kaguya:TAG")
21+
implementation("org.cufy:graphkt:TAG")
2422
}
2523
```
2624

@@ -33,52 +31,79 @@ data class Entity(
3331
val name: String
3432
)
3533

36-
val EntityObjectType = GraphQLObjectType<Entity> {
37-
name = "Entity"
38-
description = "Some entity."
34+
val EntityObjectType = GraphQLObjectType<Entity>("Entity") {
35+
description { "Some entity." }
3936

40-
field(Entity::name) {
41-
type = GraphQLString
42-
description = "The name of the entity."
37+
field(Entity::name, GraphQLStringType) {
38+
description { "The name of the entity." }
4339
}
4440

45-
field("nameWithCustomVar") {
46-
type = GraphQLNonNull(GraphQLString)
47-
description = "The name of the entity with the customVar in the context."
41+
field("nameWithCustomVar", GraphQLNullableType(GraphQLStringType)) {
42+
description { "The name of the entity with the customVar in the context." }
4843

4944
resolver {
50-
it.name + graphQlContext.get("myCustomVar")
45+
it.name + context["myCustomVar"]
5146
}
5247
}
5348
}
5449

50+
val EntitiesFlow = MutableSharedFlow<Entity>()
51+
5552
fun Application.configureGraphQL() {
53+
// you can choose any of these IDEs
54+
// graphiql()
55+
// sandbox()
56+
playground() // recommended
57+
5658
graphql {
57-
graphiql = true
59+
engine(GraphQLJava) {
60+
// engine-specific configuration
61+
}
5862

5963
context {
6064
put("myCustomVar", Math.random())
6165
}
6266

6367
schema {
6468
query {
65-
description = "The root query."
69+
description { "The root query." }
70+
71+
field("getEntityWithName", EntityObjectType) {
72+
description { "Get an entity instance." }
73+
74+
val nameArg = argument<String>("name", GraphQLStringType) {
75+
description { "The name of the entity." }
76+
}
6677

67-
field("getEntityWithName") {
68-
type = EntityObjectType
69-
description = "Get an entity instance."
78+
get { Entity(nameArg()) }
79+
}
80+
}
81+
mutation {
82+
description { "The root mutation" }
7083

71-
val nameArg = argument<String> {
72-
type = GraphQLString
73-
name = "name"
74-
description = "The name of the entity."
84+
field("pushEntity", EntityObjectType) {
85+
description { "Push an entity to subscribers" }
86+
87+
val nameArg = argument<String>("name", GraphQLStringType) {
88+
description { "The name of the entity." }
7589
}
7690

77-
resolver {
78-
Entity(nameArg())
91+
get {
92+
val entity = Entity(nameArg())
93+
EntitiesFlow.emit(entity)
94+
entity
7995
}
8096
}
8197
}
98+
subscription {
99+
description { "The root subscription" }
100+
101+
field("subscribeToEntities", EntityObjectType) {
102+
description { "Subscribe to pushed entities" }
103+
104+
getFlow { EntitiesFlow }
105+
}
106+
}
82107
}
83108
}
84109
}

build.gradle.kts

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,44 @@
11
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
22

33
plugins {
4-
kotlin("jvm") version "1.7.0"
5-
kotlin("plugin.serialization") version "1.7.0"
4+
kotlin("jvm") version kotlin_version
5+
kotlin("plugin.serialization") version kotlin_version
66
id("maven-publish")
77
}
88

99
group = "org.cufy"
10-
version = "1.1.0"
10+
version = "2.0.0"
1111

1212
repositories {
1313
mavenCentral()
14+
maven { url = uri("https://jitpack.io") }
1415
}
1516

1617
dependencies {
18+
implementation(project(":core"))
19+
implementation(project(":ktor"))
20+
implementation(project(":graphql-java"))
21+
1722
implementation(kotlin("stdlib"))
18-
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.3")
19-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.2")
2023

21-
implementation("io.ktor:ktor-server-core-jvm:2.0.2")
24+
implementation(Dependencies.Kotlin.serialization)
25+
implementation(Dependencies.Kotlin.coroutines_core)
26+
implementation(Dependencies.Kotlin.coroutines_reactive)
27+
implementation(Dependencies.Kotlin.reflect)
28+
29+
testImplementation(Dependencies.Ktor.server_core_jvm)
30+
testImplementation(Dependencies.Ktor.host_common_jvm)
31+
testImplementation(Dependencies.Ktor.netty_jvm)
32+
testImplementation(Dependencies.Ktor.call_logging_jvm)
33+
testImplementation(Dependencies.Ktor.content_negotiation_jvm)
34+
testImplementation(Dependencies.Ktor.serialization_kotlinx_json_jvm)
2235

23-
// implementation("com.expediagroup:graphql-kotlin-server:6.0.0-alpha.4")
24-
// implementation("com.expediagroup:graphql-kotlin-federation:6.0.0-alpha.4")
25-
// implementation("com.expediagroup:graphql-kotlin-dataloader:6.0.0-alpha.4")
26-
// implementation("com.expediagroup:graphql-kotlin-schema-generator:6.0.0-alpha.4")
36+
testImplementation(Dependencies.Logging.logback_core)
37+
testImplementation(Dependencies.Logging.logback_classic)
38+
testImplementation(Dependencies.Logging.self4j)
2739

28-
implementation("com.graphql-java:graphql-java:18.1")
29-
implementation("com.google.guava:guava:31.1-jre")
40+
testImplementation(Dependencies.rxjava)
41+
testImplementation(Dependencies.graphql_java)
3042

3143
testImplementation(kotlin("test"))
3244
}
@@ -44,7 +56,7 @@ afterEvaluate {
4456
publications {
4557
create<MavenPublication>("maven") {
4658
from(components["java"])
47-
artifactId = "kaguya"
59+
artifactId = "graphkt"
4860
}
4961
}
5062
}

buildSrc/.gitignore

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

buildSrc/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
plugins {
2+
`kotlin-dsl`
3+
}
4+
5+
repositories {
6+
mavenCentral()
7+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const val kotlin_version = "1.7.22"
2+
const val ktor_version = "2.0.2"
3+
4+
object Dependencies {
5+
object Kotlin {
6+
const val serialization = "org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1"
7+
const val coroutines_core = "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4"
8+
const val coroutines_reactive = "org.jetbrains.kotlinx:kotlinx-coroutines-reactive:1.6.4"
9+
const val reflect = "org.jetbrains.kotlin:kotlin-reflect:1.7.22"
10+
}
11+
12+
object Ktor {
13+
const val server_core_jvm = "io.ktor:ktor-server-core-jvm:$ktor_version"
14+
const val server_websockets = "io.ktor:ktor-server-websockets:$ktor_version"
15+
16+
const val serialization_kotlinx_json_jvm =
17+
"io.ktor:ktor-serialization-kotlinx-json-jvm:$ktor_version"
18+
19+
const val host_common_jvm = "io.ktor:ktor-server-host-common-jvm:$ktor_version"
20+
const val content_negotiation_jvm = "io.ktor:ktor-server-content-negotiation-jvm:$ktor_version"
21+
const val cors_jvm = "io.ktor:ktor-server-cors-jvm:$ktor_version"
22+
const val default_headers_jvm = "io.ktor:ktor-server-default-headers-jvm:$ktor_version"
23+
const val http_redirect_jvm = "io.ktor:ktor-server-http-redirect-jvm:$ktor_version"
24+
const val netty_jvm = "io.ktor:ktor-server-netty-jvm:$ktor_version"
25+
const val server_tests_jvm = "io.ktor:ktor-server-tests-jvm:$ktor_version"
26+
const val call_logging_jvm = "io.ktor:ktor-server-call-logging-jvm:$ktor_version"
27+
}
28+
29+
object Logging {
30+
const val logback_core = "ch.qos.logback:logback-core:1.2.11"
31+
const val logback_classic = "ch.qos.logback:logback-classic:1.2.11"
32+
const val self4j = "org.slf4j:slf4j-api:1.7.36"
33+
}
34+
35+
const val graphql_java = "com.graphql-java:graphql-java:18.1"
36+
const val rxjava = "io.reactivex.rxjava2:rxjava:2.1.5"
37+
}

core/.gitignore

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

core/build.gradle.kts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
plugins {
2+
kotlin("jvm") version kotlin_version
3+
kotlin("plugin.serialization") version kotlin_version
4+
id("maven-publish")
5+
}
6+
7+
repositories {
8+
mavenCentral()
9+
maven { url = uri("https://jitpack.io") }
10+
}
11+
12+
dependencies {
13+
implementation(kotlin("stdlib"))
14+
15+
implementation(Dependencies.Kotlin.serialization)
16+
implementation(Dependencies.Kotlin.coroutines_core)
17+
implementation(Dependencies.Kotlin.coroutines_reactive)
18+
implementation(Dependencies.Kotlin.reflect)
19+
20+
testImplementation(kotlin("test"))
21+
}
22+
23+
tasks.getByName<Test>("test") {
24+
useJUnitPlatform()
25+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2022 cufy.org
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.cufy.graphkt
17+
18+
/**
19+
* Marks the annotated component as internal.
20+
*
21+
* @since 2.0.0
22+
*/
23+
@RequiresOptIn(
24+
message = "This is an internal API and was not designed to be used directly",
25+
level = RequiresOptIn.Level.ERROR
26+
)
27+
annotation class InternalGraphktApi(
28+
/**
29+
* Optionally, the reason why the component was marked with this annotation.
30+
*/
31+
val reason: String = "This is an internal API and was not designed to be used directly"
32+
)
33+
34+
/**
35+
* Marks the annotated component as experimental.
36+
*
37+
* @since 2.0.0
38+
*/
39+
@RequiresOptIn(
40+
message = "This is an experimental API and might change at anytime",
41+
level = RequiresOptIn.Level.WARNING
42+
)
43+
annotation class ExperimentalGraphktApi(
44+
/**
45+
* Optionally, the reason why the component was marked with this annotation.
46+
*/
47+
val reason: String = "This is an experimental API and might change at anytime"
48+
)
49+
50+
/**
51+
* Marks the annotated component as advanced.
52+
*
53+
* Components marked by this annotation are meant
54+
* to be used in libraries and not application code.
55+
*
56+
* This was put to avoid users getter into stuff
57+
* that needs more reading by accident.
58+
*
59+
* @since 2.0.0
60+
*/
61+
@RequiresOptIn(
62+
message = "This API is meant to be used to extend the functionality of graphkt",
63+
level = RequiresOptIn.Level.WARNING
64+
)
65+
annotation class AdvancedGraphktApi(
66+
/**
67+
* Optionally, the reason why the component was marked with this annotation.
68+
*/
69+
val reason: String = "This API is meant to be used to extend the functionality of graphkt"
70+
)

0 commit comments

Comments
 (0)