-
Notifications
You must be signed in to change notification settings - Fork 327
Open
Labels
Description
with old DefaultGraphQLClient, we can add headers dynamically while a request comes. This is designed this way because we only know some specific headers when client send a request to service.
Now we are migrating from DefaultGraphQLClient to CustomGraphQLClient, but unfortunately the RequestExecutor is only provided during CustomGraphQLClient creation. This means all headers has to be predefined and known beforehand.
is there a way to achieve dynamic headers attaching as below old implementation?
Old code:
@Bean(name = [CORE_PRODUCT_GRAPHQL_CLIENT])
fun coreGraphQLClient(): GraphQLClient {
return DefaultGraphQLClient(url)
}
fun executeQuery(query: String, graphQLHeaders: GraphqlHeaderMaps? = null): GraphQLResponse {
return graphQLClient.executeQuery(query, HashMap<String, List<String>>()) { url, headers, body ->
val requestHeaders = HttpHeaders()
headers.forEach(requestHeaders::put)
graphQLHeaders?.forEach(requestHeaders::put)
val exchange: ResponseEntity<String> = restTemplate.exchange(
url, HttpMethod.POST, HttpEntity<Any?>(body, requestHeaders),
String::class.java
)
HttpResponse(exchange.statusCodeValue, exchange.body)
}
}