Skip to content

Commit

Permalink
impr(): Update dependencies (#8)
Browse files Browse the repository at this point in the history
* update Kotlin to 1.8.20
* update Ktor to 2.3.4
* update Gradle to 8.3
* update GraphQL-java to 21.1
* update coroutines to 1.7.3
  • Loading branch information
mbiamont authored Oct 7, 2023
1 parent 49d556e commit b36a9ae
Show file tree
Hide file tree
Showing 27 changed files with 135 additions and 112 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/default-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '8'
java-version: '17'
- name: Build with Gradle
run: ./gradlew :server:build

Expand All @@ -25,6 +25,6 @@ jobs:
- uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '8'
java-version: '17'
- name: Run server tests
run: ./gradlew :server:test
8 changes: 4 additions & 4 deletions .github/workflows/on-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '8'
java-version: '17'
- name: Build with Gradle
run: ./gradlew :server:build

Expand All @@ -25,7 +25,7 @@ jobs:
- uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '8'
java-version: '17'
- name: Run server tests
run: ./gradlew :server:test

Expand All @@ -39,7 +39,7 @@ jobs:
- uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '8'
java-version: '17'
- name: Prepare environment
env:
GRADLE_PROPERTIES: ${{secrets.GRADLE_PROPERTIES}}
Expand All @@ -58,7 +58,7 @@ jobs:
- uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '8'
java-version: '17'
- name: Prepare environment
env:
GRADLE_PROPERTIES: ${{secrets.GRADLE_PROPERTIES}}
Expand Down
10 changes: 5 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm") version "1.5.30"
kotlin("jvm") version "1.8.20"
signing
`maven-publish`
id("io.github.gradle-nexus.publish-plugin") version "1.0.0"
}

group = "com.arianegraphql"
version = "0.0.6"
version = "0.1.0"

repositories {
mavenCentral()
Expand All @@ -17,9 +17,9 @@ repositories {
subprojects {
tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
languageVersion = "1.5"
apiVersion = "1.5"
jvmTarget = "17"
languageVersion = "1.8"
apiVersion = "1.8"
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
19 changes: 10 additions & 9 deletions sample/src/main/kotlin/com/arianegraphql/sample/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.arianegraphql.server.listener.ServerListener
import com.arianegraphql.server.listener.SubscriptionListener
import com.arianegraphql.server.request.HttpRequest
import graphql.ExecutionInput
import graphql.GraphQLContext
import io.ktor.application.*
import io.ktor.features.*
import io.ktor.server.engine.*
Expand Down Expand Up @@ -74,40 +75,40 @@ fun main() {
println("[$sessionId] onNewConnection()")
}

override fun onConnected(sessionId: String, context: Any?) {
override fun onConnected(sessionId: String, context: GraphQLContext) {
println("[$sessionId] onConnected()")
}

override fun onStartSubscription(sessionId: String, context: Any?, operationId: String, graphQLRequest: GraphQLRequest) {
override fun onStartSubscription(sessionId: String, context: GraphQLContext, operationId: String, graphQLRequest: GraphQLRequest) {
println("[$sessionId] onStartSubscription($operationId, ${graphQLRequest.operationName})")
}

override fun onStopSubscription(sessionId: String, context: Any?, operationId: String) {
override fun onStopSubscription(sessionId: String, context: GraphQLContext, operationId: String) {
println("[$sessionId] onStopSubscription($operationId)")
}

override fun onCloseConnection(sessionId: String, context: Any?) {
override fun onCloseConnection(sessionId: String, context: GraphQLContext) {
println("[$sessionId] onCloseConnection()")
}
}

resolvers {
Query {
resolve("movies") { _, _: Any?, _: Any?, _ ->
resolve("movies") { _, _: Any?, _: GraphQLContext, _ ->
movies
}

resolve("directors") { _, _: Any?, _: Any?, _ ->
resolve("directors") { _, _: Any?, _: GraphQLContext, _ ->
movies.map { it.director }.distinctBy { it.name }
}

resolve("movie") { args, _: Any?, _: Any?, _ ->
resolve("movie") { args, _: Any?, _: GraphQLContext, _ ->
movies.find { it.title == args["title"] }
}
}

Mutation {
resolve("addMovie") { args, parent: Any?, context: Any?, info ->
resolve("addMovie") { args, parent: Any?, context: GraphQLContext, info ->
val movie = Movie(args["title"], Director(args["director"]))
movies.add(movie)

Expand All @@ -117,7 +118,7 @@ fun main() {
}

type("Director") {
resolve("movies") { args: Any, parent: Director, context: Any?, info ->
resolve("movies") { args: Any, parent: Director, context: GraphQLContext, info ->
movies.filter { it.director.name == parent.name }
}
}
Expand Down
7 changes: 4 additions & 3 deletions server-ktor/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
group = project.rootProject.group
version = project.rootProject.version

val ktorVersion = "1.6.3"
val ktorVersion = "2.3.4"

dependencies {
implementation(project(":server"))
implementation("io.ktor:ktor-server-cio:$ktorVersion")
implementation("io.ktor:ktor-websockets:$ktorVersion")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.12.5")
implementation("io.ktor:ktor-server-websockets:$ktorVersion")
implementation("io.ktor:ktor-server-cors:$ktorVersion")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.15.2")
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import com.arianegraphql.ktx.GraphQLSchemaDslMarker
import com.arianegraphql.ktx.makeExecutableSchema
import com.arianegraphql.server.dsl.ArianeServerBuilder
import graphql.GraphQL
import io.ktor.application.*
import java.lang.IllegalStateException
import io.ktor.server.application.Application

@GraphQLSchemaDslMarker
class ArianeKtorServerBuilder : ArianeServerBuilder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ArianeKtorServerConfiguration(
path: String,
isPlaygroundEnabled: Boolean,
enableCORS: Boolean,
contextResolver: ContextResolver<*>,
contextResolver: ContextResolver,
serverListener: ServerListener?,
requestListener: RequestListener?,
subscriptionListener: SubscriptionListener?,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.arianegraphql.server.ktor.dsl

import io.ktor.application.*
import io.ktor.server.application.Application

interface KtorPlugin{
fun invoke(application: Application)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package com.arianegraphql.server.ktor

import com.arianegraphql.server.ArianeServer
import com.arianegraphql.server.request.HttpRequest
import io.ktor.application.*
import io.ktor.server.application.*
import io.ktor.http.*
import io.ktor.request.*
import io.ktor.response.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.util.*
import io.ktor.util.pipeline.*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package com.arianegraphql.server.ktor

import com.arianegraphql.server.ArianeServer
import com.arianegraphql.server.request.WebSocketRequest
import io.ktor.http.cio.websocket.*
import io.ktor.server.websocket.*
import io.ktor.util.*
import io.ktor.websocket.*
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import java.lang.Exception
import java.util.*

suspend fun WebSocketServerSession.handleGraphQLSubscription(arianeServer: ArianeServer) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.arianegraphql.server.ktor

import com.arianegraphql.server.config.ArianeServerConfiguration
import com.arianegraphql.server.config.newArianeServer
import com.arianegraphql.server.dsl.ArianeServerBuilder
import com.arianegraphql.server.ktor.dsl.ArianeKtorServerConfiguration
import com.arianegraphql.server.ktor.dsl.arianeServer
import io.ktor.application.*
import io.ktor.features.*
import io.ktor.routing.*
import io.ktor.server.cio.*
import io.ktor.server.engine.*
import io.ktor.websocket.*
import io.ktor.server.application.*
import io.ktor.server.routing.*
import io.ktor.server.websocket.*
import io.ktor.server.plugins.cors.routing.CORS

fun ArianeKtorServerConfiguration.launch(wait: Boolean = true) {
val arianeServer = newArianeServer(JacksonSerializer)
Expand Down
10 changes: 5 additions & 5 deletions server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ group = project.rootProject.group
version = project.rootProject.version

dependencies {
api("com.graphql-java:graphql-java:17.2")
api("org.slf4j:slf4j-api:1.7.32")
api( "ch.qos.logback:logback-classic:1.2.5")
api("com.graphql-java:graphql-java:21.1")
api("org.slf4j:slf4j-api:2.0.9")
api("ch.qos.logback:logback-classic:1.4.11")

implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactive:1.5.1")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactive:1.7.3")
}
18 changes: 10 additions & 8 deletions server/src/main/kotlin/com/arianegraphql/ktx/Resolver.kt
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
package com.arianegraphql.ktx

import graphql.GraphQLContext
import graphql.schema.DataFetcher
import kotlinx.coroutines.runBlocking

interface Resolver<S, C> {
suspend fun resolve(arguments: Argument, source: S, context: C?, info: Info): Any?
interface Resolver<S> {
suspend fun resolve(arguments: Argument, source: S, context: GraphQLContext, info: Info): Any?
}

@JvmInline value class FunctionalResolver<S, C>(
private val lambda: suspend (arguments: Argument, source: S, context: C?, info: Info) -> Any?
) : Resolver<S, C> {
@JvmInline value class FunctionalResolver<S>(
private val lambda: suspend (arguments: Argument, source: S, context: GraphQLContext, info: Info) -> Any?
) : Resolver<S> {

override suspend fun resolve(
arguments: Argument,
source: S,
context: C?,
context: GraphQLContext,
info: Info
) = lambda(arguments, source, context, info)
}

internal fun <S, C> Resolver<S, C>.toDataFetcher(): DataFetcher<Any?> = DataFetcher { env ->
internal fun <S> Resolver<S>.toDataFetcher(): DataFetcher<Any?> = DataFetcher { env ->
runBlocking {
resolve(DataFetchingArgument(env), env.getSource(), env.getContext(), env)
env.graphQlContext
resolve(DataFetchingArgument(env), env.getSource(), env.graphQlContext, env)
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package com.arianegraphql.ktx

interface SubscriptionFilter<T, S, C> {
import graphql.GraphQLContext

suspend fun test(arguments: Argument, source: S, context: C?, info: Info, item: T): Boolean
interface SubscriptionFilter<T, S> {

suspend fun test(arguments: Argument, source: S, context: GraphQLContext, info: Info, item: T): Boolean
}

@JvmInline
value class FunctionalSubscriptionFilter<T, S, C>(
private val lambda: suspend (arguments: Argument, source: S, context: C?, info: Info, item: T) -> Boolean
) : SubscriptionFilter<T, S, C> {
value class FunctionalSubscriptionFilter<T, S>(
private val lambda: suspend (arguments: Argument, source: S, context: GraphQLContext, info: Info, item: T) -> Boolean
) : SubscriptionFilter<T, S> {

override suspend fun test(
arguments: Argument,
source: S,
context: C?,
context: GraphQLContext,
info: Info,
item: T
) = lambda(arguments, source, context, info, item)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.arianegraphql.ktx

import graphql.GraphQLContext
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.reactive.asPublisher
Expand All @@ -12,8 +13,8 @@ class SubscriptionTypeResolverBuilder : TypeResolverBuilder() {

fun <T : Any> resolve(field: String, flow: Flow<T>) = resolve(field, flow.asPublisher())

fun <T : Any, S, C> resolve(field: String, flow: Flow<T>, predicate: SubscriptionFilter<T, S, C>) =
resolve(field) { arguments: Argument, source: S, context: C?, info: Info ->
fun <T : Any, S> resolve(field: String, flow: Flow<T>, predicate: SubscriptionFilter<T, S>) =
resolve(field) { arguments: Argument, source: S, context: GraphQLContext, info: Info ->
flow.filter {
predicate.test(arguments, source, context, info, it)
}.asPublisher()
Expand All @@ -22,6 +23,6 @@ class SubscriptionTypeResolverBuilder : TypeResolverBuilder() {
fun <T : Any, S, C> resolve(
field: String,
flow: Flow<T>,
predicate: suspend (arguments: Argument, source: S, context: C?, info: Info, item: T) -> Boolean
predicate: suspend (arguments: Argument, source: S, context: GraphQLContext, info: Info, item: T) -> Boolean
) = resolve(field, flow, FunctionalSubscriptionFilter(predicate))
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package com.arianegraphql.ktx

import graphql.GraphQLContext
import graphql.schema.idl.TypeRuntimeWiring

@GraphQLSchemaDslMarker
open class TypeResolverBuilder {

internal val typeResolver = mutableMapOf<String, Resolver<*, *>>()
internal val typeResolver = mutableMapOf<String, Resolver<*>>()

fun <S, C> resolve(field: String, resolver: Resolver<S, C>) {
fun <S> resolve(field: String, resolver: Resolver<S>) {
typeResolver[field] = resolver
}

fun <S, C> resolve(field: String, resolver: suspend (arguments: Argument, source: S, context: C?, info: Info) -> Any?) {
fun <S> resolve(field: String, resolver: suspend (arguments: Argument, source: S, context: GraphQLContext, info: Info) -> Any?) {
typeResolver[field] = FunctionalResolver(resolver)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import kotlinx.coroutines.flow.*
class ArianeServerImpl(
private val schema: GraphQL,
private val isPlaygroundEnabled: Boolean,
private val contextResolver: ContextResolver<*>,
private val contextResolver: ContextResolver,
private val requestListener: RequestListener?,
private val subscriptionListener: SubscriptionListener?,
jsonSerializer: JsonSerializer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.arianegraphql.server.request.WebSocketRequest
import kotlinx.coroutines.flow.Flow

interface SubscriptionHandler {
suspend fun initSubscription(wsRequest: WebSocketRequest, contextResolver: ContextResolver<*>): Flow<String>
suspend fun initSubscription(wsRequest: WebSocketRequest, contextResolver: ContextResolver): Flow<String>

suspend fun startSubscription(wsRequest: WebSocketRequest, wsPayload: WebSocketPayload, ): Flow<String>

Expand Down
Loading

0 comments on commit b36a9ae

Please sign in to comment.