Skip to content

Commit

Permalink
Merge branch 'master' into entity-representation-mappers
Browse files Browse the repository at this point in the history
  • Loading branch information
wbaldoumas authored Oct 19, 2023
2 parents 71cd387 + 3c4bf47 commit f3154ad
Show file tree
Hide file tree
Showing 22 changed files with 79 additions and 54 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
*/

object Versions {
const val KOTLIN_VERSION = "1.7.20"
const val KOTLIN_VERSION = "1.9.10"
}
5 changes: 4 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ kotlin.code.style=official
org.gradle.caching = true
# org.gradle.parallel = true
# org.gradle.configureondemand = true
org.gradle.jvmargs=-Xmx2G
org.gradle.jvmargs=-Xmx2000m
kotlin.daemon.useFallbackStrategy=false
kotlin.compiler.execution.strategy=in-process

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.intellij.lang.annotations.Language
* For a more convenient option, use [WebClientGraphQLClient] instead.
*/
class CustomGraphQLClient(private val url: String, private val requestExecutor: RequestExecutor) : GraphQLClient {
override fun executeQuery(query: String): GraphQLResponse {
override fun executeQuery(@Language("graphql") query: String): GraphQLResponse {
return executeQuery(query, emptyMap(), null)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.netflix.graphql.dgs.client

import org.intellij.lang.annotations.Language
import reactor.core.publisher.Mono

/**
Expand Down Expand Up @@ -55,7 +56,7 @@ class DefaultGraphQLClient(private val url: String) : GraphQLClient, MonoGraphQL
*/
@Deprecated("The RequestExecutor should be provided while creating the implementation. Use CustomGraphQLClient/CustomMonoGraphQLClient instead.")
override fun executeQuery(
query: String,
@Language("graphql") query: String,
variables: Map<String, Any>,
operationName: String?,
requestExecutor: RequestExecutor
Expand All @@ -65,15 +66,15 @@ class DefaultGraphQLClient(private val url: String) : GraphQLClient, MonoGraphQL
return GraphQLClients.handleResponse(response, serializedRequest, url)
}

override fun executeQuery(query: String): GraphQLResponse {
override fun executeQuery(@Language("graphql") query: String): GraphQLResponse {
throw UnsupportedOperationException("Please move to [BlockingGraphQLClient] to use this method")
}

override fun executeQuery(query: String, variables: Map<String, Any>): GraphQLResponse {
override fun executeQuery(@Language("graphql") query: String, variables: Map<String, Any>): GraphQLResponse {
throw UnsupportedOperationException("Please move to [BlockingGraphQLClient] to use this method")
}

override fun executeQuery(query: String, variables: Map<String, Any>, operationName: String?): GraphQLResponse {
override fun executeQuery(@Language("graphql") query: String, variables: Map<String, Any>, operationName: String?): GraphQLResponse {
throw UnsupportedOperationException("Please move to [BlockingGraphQLClient] to use this method")
}

Expand All @@ -90,24 +91,24 @@ class DefaultGraphQLClient(private val url: String) : GraphQLClient, MonoGraphQL
*/
@Deprecated("The RequestExecutor should be provided while creating the implementation. Use CustomGraphQLClient/CustomMonoGraphQLClient instead.")
override fun executeQuery(
query: String,
@Language("graphql") query: String,
variables: Map<String, Any>,
requestExecutor: RequestExecutor
): GraphQLResponse {
@Suppress("deprecation")
return executeQuery(query, variables, null, requestExecutor)
}

override fun reactiveExecuteQuery(query: String): Mono<GraphQLResponse> {
override fun reactiveExecuteQuery(@Language("graphql") query: String): Mono<GraphQLResponse> {
throw UnsupportedOperationException("Please move to [CustomGraphQLClient] to use this method")
}

override fun reactiveExecuteQuery(query: String, variables: Map<String, Any>): Mono<GraphQLResponse> {
override fun reactiveExecuteQuery(@Language("graphql") query: String, variables: Map<String, Any>): Mono<GraphQLResponse> {
throw UnsupportedOperationException("Please move to [CustomGraphQLClient] to use this method")
}

override fun reactiveExecuteQuery(
query: String,
@Language("graphql") query: String,
variables: Map<String, Any>,
operationName: String?
): Mono<GraphQLResponse> {
Expand All @@ -127,7 +128,7 @@ class DefaultGraphQLClient(private val url: String) : GraphQLClient, MonoGraphQL
*/
@Deprecated("The RequestExecutor should be provided while creating the implementation. Use CustomGraphQLClient/CustomMonoGraphQLClient instead.")
override fun reactiveExecuteQuery(
query: String,
@Language("graphql") query: String,
variables: Map<String, Any>,
requestExecutor: MonoRequestExecutor
): Mono<GraphQLResponse> {
Expand All @@ -149,7 +150,7 @@ class DefaultGraphQLClient(private val url: String) : GraphQLClient, MonoGraphQL
*/
@Deprecated("The RequestExecutor should be provided while creating the implementation. Use CustomGraphQLClient/CustomMonoGraphQLClient instead.")
override fun reactiveExecuteQuery(
query: String,
@Language("graphql") query: String,
variables: Map<String, Any>,
operationName: String?,
requestExecutor: MonoRequestExecutor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.netflix.graphql.dgs.client

import org.intellij.lang.annotations.Language

/**
* GraphQL client interface for blocking clients.
*/
Expand All @@ -25,15 +27,15 @@ interface GraphQLClient {
* @param query The query string. Note that you can use [code generation](https://netflix.github.io/dgs/generating-code-from-schema/#generating-query-apis-for-external-services) for a type safe query!
* @return [GraphQLResponse] parses the response and gives easy access to data and errors.
*/
fun executeQuery(query: String): GraphQLResponse
fun executeQuery(@Language("graphql") query: String): GraphQLResponse

/**
* A blocking call to execute a query and parse its result.
* @param query The query string. Note that you can use [code generation](https://netflix.github.io/dgs/generating-code-from-schema/#generating-query-apis-for-external-services) for a type safe query!
* @param variables A map of input variables
* @return [GraphQLResponse] parses the response and gives easy access to data and errors.
*/
fun executeQuery(query: String, variables: Map<String, Any>): GraphQLResponse
fun executeQuery(@Language("graphql") query: String, variables: Map<String, Any>): GraphQLResponse

/**
* A blocking call to execute a query and parse its result.
Expand All @@ -42,7 +44,7 @@ interface GraphQLClient {
* @param operationName Name of the operation
* @return [GraphQLResponse] parses the response and gives easy access to data and errors.
*/
fun executeQuery(query: String, variables: Map<String, Any>, operationName: String?): GraphQLResponse
fun executeQuery(@Language("graphql") query: String, variables: Map<String, Any>, operationName: String?): GraphQLResponse

@Deprecated(
"The RequestExecutor should be provided while creating the implementation. Use CustomGraphQLClient/CustomMonoGraphQLClient instead.",
Expand All @@ -55,7 +57,7 @@ interface GraphQLClient {
ReplaceWith("Example: new CustomGraphQLClient(url, requestExecutor);")
)
fun executeQuery(
query: String,
@Language("graphql") query: String,
variables: Map<String, Any>,
operationName: String?,
requestExecutor: RequestExecutor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.netflix.graphql.dgs.client

import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.netflix.graphql.types.subscription.QueryPayload
import org.intellij.lang.annotations.Language
import org.springframework.http.MediaType
import org.springframework.web.reactive.function.client.WebClient
import org.springframework.web.reactive.function.client.toEntityFlux
Expand All @@ -33,12 +34,12 @@ class GraphqlSSESubscriptionGraphQLClient(private val url: String, private val w

private val mapper = jacksonObjectMapper()

override fun reactiveExecuteQuery(query: String, variables: Map<String, Any>): Flux<GraphQLResponse> {
override fun reactiveExecuteQuery(@Language("graphql") query: String, variables: Map<String, Any>): Flux<GraphQLResponse> {
return reactiveExecuteQuery(query, variables, null)
}

override fun reactiveExecuteQuery(
query: String,
@Language("graphql") query: String,
variables: Map<String, Any>,
operationName: String?
): Flux<GraphQLResponse> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ interface MonoGraphQLClient {
ReplaceWith("Example: new CustomGraphQLClient(url, requestExecutor);")
)
fun reactiveExecuteQuery(
query: String,
@Language("graphql") query: String,
variables: Map<String, Any>,
requestExecutor: MonoRequestExecutor
): Mono<GraphQLResponse> = throw UnsupportedOperationException()
Expand All @@ -77,7 +77,7 @@ interface MonoGraphQLClient {
ReplaceWith("Example: new CustomGraphQLClient(url, requestExecutor);")
)
fun reactiveExecuteQuery(
query: String,
@Language("graphql") query: String,
variables: Map<String, Any>,
operationName: String?,
requestExecutor: MonoRequestExecutor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.netflix.graphql.dgs.client

import org.intellij.lang.annotations.Language
import reactor.core.publisher.Flux

/**
Expand All @@ -28,7 +29,7 @@ interface ReactiveGraphQLClient {
* @return A [Flux] of [GraphQLResponse]. [GraphQLResponse] parses the response and gives easy access to data and errors.
*/
fun reactiveExecuteQuery(
query: String,
@Language("graphql") query: String,
variables: Map<String, Any>
): Flux<GraphQLResponse>

Expand All @@ -39,7 +40,7 @@ interface ReactiveGraphQLClient {
* @return A [Flux] of [GraphQLResponse]. [GraphQLResponse] parses the response and gives easy access to data and errors.
*/
fun reactiveExecuteQuery(
query: String,
@Language("graphql") query: String,
variables: Map<String, Any>,
operationName: String?
): Flux<GraphQLResponse>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@

package com.netflix.graphql.dgs.client

internal data class Request(val query: String, val variables: Map<String, Any>, val operationName: String?)
import org.intellij.lang.annotations.Language

internal data class Request(@Language("graphql") val query: String, val variables: Map<String, Any>, val operationName: String?)
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.netflix.graphql.dgs.client

import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.netflix.graphql.types.subscription.QueryPayload
import org.intellij.lang.annotations.Language
import org.springframework.http.MediaType
import org.springframework.web.reactive.function.client.WebClient
import org.springframework.web.reactive.function.client.toEntityFlux
Expand All @@ -34,12 +35,12 @@ class SSESubscriptionGraphQLClient(private val url: String, private val webClien

private val mapper = jacksonObjectMapper()

override fun reactiveExecuteQuery(query: String, variables: Map<String, Any>): Flux<GraphQLResponse> {
override fun reactiveExecuteQuery(@Language("graphql") query: String, variables: Map<String, Any>): Flux<GraphQLResponse> {
return reactiveExecuteQuery(query, variables, null)
}

override fun reactiveExecuteQuery(
query: String,
@Language("graphql") query: String,
variables: Map<String, Any>,
operationName: String?
): Flux<GraphQLResponse> {
Expand All @@ -60,7 +61,7 @@ class SSESubscriptionGraphQLClient(private val url: String, private val webClien
.publishOn(Schedulers.single())
}

private fun encodeQuery(query: String): String? {
private fun encodeQuery(@Language("graphql") query: String): String? {
return Base64.getEncoder().encodeToString(query.toByteArray(StandardCharsets.UTF_8))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonTypeRef
import com.netflix.graphql.types.subscription.*
import graphql.GraphQLException
import org.intellij.lang.annotations.Language
import org.springframework.web.reactive.socket.WebSocketHandler
import org.springframework.web.reactive.socket.WebSocketMessage
import org.springframework.web.reactive.socket.WebSocketSession
Expand Down Expand Up @@ -87,14 +88,14 @@ class WebSocketGraphQLClient(
}

override fun reactiveExecuteQuery(
query: String,
@Language("graphql") query: String,
variables: Map<String, Any>
): Flux<GraphQLResponse> {
return reactiveExecuteQuery(query, variables, null)
}

override fun reactiveExecuteQuery(
query: String,
@Language("graphql") query: String,
variables: Map<String, Any>,
operationName: String?
): Flux<GraphQLResponse> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import graphql.execution.NonNullableFieldWasNullError
import graphql.execution.instrumentation.Instrumentation
import graphql.execution.preparsed.PreparsedDocumentProvider
import graphql.schema.GraphQLSchema
import org.intellij.lang.annotations.Language
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.http.HttpHeaders
Expand All @@ -60,7 +61,7 @@ class DefaultDgsReactiveQueryExecutor(
private val schema = AtomicReference(defaultSchema)

override fun execute(
query: String?,
@Language("graphql") query: String?,
variables: Map<String, Any>?,
extensions: Map<String, Any>?,
headers: HttpHeaders?,
Expand Down Expand Up @@ -104,7 +105,7 @@ class DefaultDgsReactiveQueryExecutor(
}

override fun <T : Any> executeAndExtractJsonPath(
query: String,
@Language("graphql") query: String,
jsonPath: String,
variables: Map<String, Any>?,
serverRequest: ServerRequest?
Expand All @@ -113,14 +114,14 @@ class DefaultDgsReactiveQueryExecutor(
}

override fun executeAndGetDocumentContext(
query: String,
@Language("graphql") query: String,
variables: Map<String, Any>
): Mono<DocumentContext> {
return getJsonResult(query, variables, null).map(BaseDgsQueryExecutor.parseContext::parse)
}

override fun <T : Any?> executeAndExtractJsonPathAsObject(
query: String,
@Language("graphql") query: String,
jsonPath: String,
variables: Map<String, Any>,
clazz: Class<T>
Expand All @@ -137,7 +138,7 @@ class DefaultDgsReactiveQueryExecutor(
}

override fun <T : Any?> executeAndExtractJsonPathAsObject(
query: String,
@Language("graphql") query: String,
jsonPath: String,
variables: Map<String, Any>,
typeRef: TypeRef<T>
Expand All @@ -153,7 +154,7 @@ class DefaultDgsReactiveQueryExecutor(
}
}

private fun getJsonResult(query: String, variables: Map<String, Any>?, serverRequest: ServerRequest?): Mono<String> {
private fun getJsonResult(@Language("graphql") query: String, variables: Map<String, Any>?, serverRequest: ServerRequest?): Mono<String> {
val httpHeaders = serverRequest?.headers()?.asHttpHeaders()
return execute(query, variables, null, httpHeaders, null, serverRequest).map { executionResult ->
if (executionResult.errors.size > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import graphql.language.AstPrinter
import graphql.language.AstSignature
import graphql.language.Document
import org.apache.commons.codec.digest.DigestUtils
import org.intellij.lang.annotations.Language
import java.util.*

/**
Expand All @@ -42,7 +43,7 @@ import java.util.*
fun interface QuerySignatureRepository {

companion object {
internal fun queryHash(query: String): String = DigestUtils.sha256Hex(query)
internal fun queryHash(@Language("graphql") query: String): String = DigestUtils.sha256Hex(query)

internal fun computeSignature(
document: Document,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.fasterxml.jackson.module.kotlin.readValue
import com.netflix.graphql.dgs.DgsExecutionResult
import com.netflix.graphql.dgs.reactive.DgsReactiveQueryExecutor
import graphql.ExecutionResult
import org.intellij.lang.annotations.Language
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.web.reactive.function.server.ServerRequest
Expand Down Expand Up @@ -105,7 +106,7 @@ class DefaultDgsWebfluxHttpHandler(
}

private data class QueryInput(
val query: String?,
@Language("graphql") val query: String?,
val queryVariables: Map<String, Any> = emptyMap(),
val extensions: Map<String, Any> = emptyMap(),
val operationName: String = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.netflix.graphql.dgs.internal.utils.MultipartVariableMapper
import com.netflix.graphql.dgs.internal.utils.TimeTracer
import com.netflix.graphql.dgs.internal.utils.VariableMappingException
import graphql.execution.reactive.SubscriptionPublisher
import org.intellij.lang.annotations.Language
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.http.HttpHeaders
Expand Down Expand Up @@ -82,7 +83,7 @@ open class DgsRestController(

@JsonIgnoreProperties(ignoreUnknown = true)
private data class InputQuery(
val query: String?,
@Language("graphql") val query: String?,
val operationName: String? = null,
val variables: Map<String, Any>? = mapOf(),
val extensions: Map<String, Any>? = mapOf()
Expand Down
Loading

0 comments on commit f3154ad

Please sign in to comment.