Skip to content

Commit

Permalink
[build] update to Kotlin 1.4, Spring Boot 2.4.1 and Ktor 1.5
Browse files Browse the repository at this point in the history
JaCoCo branch coverage dropped because of jacoco/jacoco#1126, once new version of Jacoco is released we can bump it up again.
  • Loading branch information
dariuszkuc authored and Dariusz Kuc committed Jan 14, 2021
1 parent 2b64aed commit 7c9f4ff
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 43 deletions.
Expand Up @@ -28,19 +28,19 @@ import com.github.tomakehurst.wiremock.core.WireMockConfiguration
import com.github.tomakehurst.wiremock.matching.EqualToPattern
import io.netty.channel.ChannelOption
import io.netty.handler.timeout.ReadTimeoutException
import io.netty.handler.timeout.ReadTimeoutHandler
import io.netty.handler.timeout.WriteTimeoutHandler
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.springframework.http.client.reactive.ClientHttpConnector
import org.springframework.http.client.reactive.ReactorClientHttpConnector
import org.springframework.web.reactive.function.client.WebClient
import org.springframework.web.reactive.function.client.WebClientRequestException
import org.springframework.web.reactive.function.client.WebClientResponseException
import reactor.netty.http.client.HttpClient
import java.util.concurrent.TimeUnit
import java.time.Duration
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertNotNull
Expand Down Expand Up @@ -104,13 +104,8 @@ class GraphQLWebClientTest {
WireMock.stubFor(stubResponse(response = expectedResponse, delayMillis = 50))

val httpClient: HttpClient = HttpClient.create()
.tcpConfiguration { client ->
client.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10)
.doOnConnected { conn ->
conn.addHandlerLast(ReadTimeoutHandler(10, TimeUnit.MILLISECONDS))
conn.addHandlerLast(WriteTimeoutHandler(10, TimeUnit.MILLISECONDS))
}
}
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10)
.responseTimeout(Duration.ofMillis(10))
val connector: ClientHttpConnector = ReactorClientHttpConnector(httpClient.wiretap(true))
val webClientBuilder = WebClient.builder()
.clientConnector(connector)
Expand All @@ -120,12 +115,13 @@ class GraphQLWebClientTest {
builder = webClientBuilder
)
runBlocking {
assertFailsWith(ReadTimeoutException::class) {
val exception = assertFailsWith(WebClientRequestException::class) {
client.execute<GraphQLResponse<HelloWorldResult>>(
query = "query HelloWorldQuery { helloWorld }",
operationName = "HelloWorldQuery"
)
}
assertTrue(exception.cause is ReadTimeoutException)
}
}

Expand Down
9 changes: 2 additions & 7 deletions docs/client/client-customization.md
Expand Up @@ -81,13 +81,8 @@ Example below configures `GraphQLWebClient` with custom timeouts and adds a defa

```kotlin
val httpClient: HttpClient = HttpClient.create()
.tcpConfiguration { client ->
client.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10_000)
.doOnConnected { conn ->
conn.addHandlerLast(ReadTimeoutHandler(60_000, TimeUnit.MILLISECONDS))
conn.addHandlerLast(WriteTimeoutHandler(60_000, TimeUnit.MILLISECONDS))
}
}
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10_000)
.responseTimeout(Duration.ofMillis(10_000))
val connector: ClientHttpConnector = ReactorClientHttpConnector(httpClient.wiretap(true))
val webClientBuilder = WebClient.builder()
.clientConnector(connector)
Expand Down
2 changes: 1 addition & 1 deletion generator/graphql-kotlin-federation/build.gradle.kts
Expand Up @@ -19,7 +19,7 @@ tasks {
limit {
counter = "BRANCH"
value = "COVEREDRATIO"
minimum = "0.94".toBigDecimal()
minimum = "0.93".toBigDecimal()
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion generator/graphql-kotlin-schema-generator/build.gradle.kts
Expand Up @@ -28,7 +28,7 @@ tasks {
limit {
counter = "BRANCH"
value = "COVEREDRATIO"
minimum = "0.95".toBigDecimal()
minimum = "0.94".toBigDecimal()
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions gradle.properties
Expand Up @@ -15,23 +15,23 @@ org.gradle.jvmargs=-Xmx2g -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError

# dependencies
kotlinJvmVersion = 1.8
kotlinVersion = 1.3.72
kotlinCoroutinesVersion = 1.3.8
kotlinVersion = 1.4.21
kotlinCoroutinesVersion = 1.4.2

classGraphVersion = 4.8.87
classGraphVersion = 4.8.98
graphQLJavaVersion = 16.1
jacksonVersion = 2.11.3
kotlinPoetVersion = 1.6.0
ktorVersion = 1.3.1
reactorVersion = 3.3.10.RELEASE
reactorExtensionsVersion = 1.0.2.RELEASE
ktorVersion = 1.5.0
reactorVersion = 3.4.1
reactorExtensionsVersion = 1.1.1
slf4jVersion = 1.7.30
springBootVersion = 2.3.4.RELEASE
springVersion = 5.2.9.RELEASE
springBootVersion = 2.4.1
springVersion = 5.3.2

# test dependency versions
junitVersion = 5.6.2
mockkVersion = 1.10.0
junitVersion = 5.7.0
mockkVersion = 1.10.4
mustacheVersion = 0.9.6
rxjavaVersion = 3.0.4
wireMockVersion = 2.26.3
Expand Down
2 changes: 1 addition & 1 deletion servers/graphql-kotlin-spring-server/build.gradle.kts
Expand Up @@ -35,7 +35,7 @@ tasks {
limit {
counter = "BRANCH"
value = "COVEREDRATIO"
minimum = "0.85".toBigDecimal()
minimum = "0.74".toBigDecimal()
}
}
}
Expand Down
Expand Up @@ -27,23 +27,21 @@ import graphql.ExecutionResult
import graphql.GraphQL
import org.reactivestreams.Publisher
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono
import reactor.kotlin.core.publisher.toFlux

/**
* Default Spring implementation of GraphQL subscription handler.
*/
open class SpringGraphQLSubscriptionHandler(private val graphQL: GraphQL) {

fun executeSubscription(graphQLRequest: GraphQLRequest, graphQLContext: GraphQLContext?): Flux<GraphQLResponse<*>> = Mono.subscriberContext()
.flatMapMany {
graphQL.execute(graphQLRequest.toExecutionInput(graphQLContext))
.getData<Publisher<ExecutionResult>>()
.toFlux()
.map { result -> result.toGraphQLResponse() }
.onErrorResume { throwable ->
val error = KotlinGraphQLError(throwable).toGraphQLKotlinType()
Flux.just(GraphQLResponse<Any>(errors = listOf(error)))
}
}
fun executeSubscription(graphQLRequest: GraphQLRequest, graphQLContext: GraphQLContext?): Flux<GraphQLResponse<*>> = Flux.deferContextual {
graphQL.execute(graphQLRequest.toExecutionInput(graphQLContext))
.getData<Publisher<ExecutionResult>>()
.toFlux()
.map { result -> result.toGraphQLResponse() }
.onErrorResume { throwable ->
val error = KotlinGraphQLError(throwable).toGraphQLKotlinType()
Flux.just(GraphQLResponse<Any>(errors = listOf(error)))
}
}
}

0 comments on commit 7c9f4ff

Please sign in to comment.