Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added createWithWebClient factory method that takes header consumer #669

Merged
merged 1 commit into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -19,10 +19,12 @@ package com.netflix.graphql.dgs.client
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.KotlinModule
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
import org.springframework.http.HttpHeaders
import org.springframework.util.ClassUtils
import org.springframework.web.reactive.function.client.WebClient
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono
import java.util.function.Consumer

/**
* GraphQL client interface for blocking clients.
Expand Down Expand Up @@ -129,6 +131,8 @@ interface MonoGraphQLClient {
fun createCustomReactive(url: String, requestExecutor: MonoRequestExecutor) = CustomMonoGraphQLClient(url, requestExecutor)
@JvmStatic
fun createWithWebClient(webClient: WebClient) = WebClientGraphQLClient(webClient)
@JvmStatic
fun createWithWebClient(webClient: WebClient, headersConsumer: Consumer<HttpHeaders>) = WebClientGraphQLClient(webClient, headersConsumer)
}
}

Expand Down
Expand Up @@ -47,7 +47,7 @@ class WebClientGraphQLClientTest {

@BeforeEach
fun setup() {
client = WebClientGraphQLClient(WebClient.create("http://localhost:$port/graphql"))
client = MonoGraphQLClient.createWithWebClient(WebClient.create("http://localhost:$port/graphql"))
}

@Test
Expand All @@ -61,8 +61,7 @@ class WebClientGraphQLClientTest {

@Test
fun `Extra header can be provided`() {
client = WebClientGraphQLClient(WebClient.create("http://localhost:$port/graphql")) { headers ->
println("extra")
client = MonoGraphQLClient.createWithWebClient(WebClient.create("http://localhost:$port/graphql")) { headers ->
headers.add("myheader", "test")
}
val result = client.reactiveExecuteQuery("{withHeader}").map { r -> r.extractValue<String>("withHeader") }
Expand Down