diff --git a/graphql-dgs-spring-webflux-autoconfigure/src/main/kotlin/com/netflix/graphql/dgs/webflux/handlers/DefaultDgsWebfluxHttpHandler.kt b/graphql-dgs-spring-webflux-autoconfigure/src/main/kotlin/com/netflix/graphql/dgs/webflux/handlers/DefaultDgsWebfluxHttpHandler.kt index 2af9cae3ab..e43181e974 100644 --- a/graphql-dgs-spring-webflux-autoconfigure/src/main/kotlin/com/netflix/graphql/dgs/webflux/handlers/DefaultDgsWebfluxHttpHandler.kt +++ b/graphql-dgs-spring-webflux-autoconfigure/src/main/kotlin/com/netflix/graphql/dgs/webflux/handlers/DefaultDgsWebfluxHttpHandler.kt @@ -20,6 +20,7 @@ import com.fasterxml.jackson.core.JsonParseException import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.exc.MismatchedInputException import com.fasterxml.jackson.module.kotlin.readValue +import com.netflix.graphql.dgs.internal.DgsExecutionResult import com.netflix.graphql.dgs.reactive.DgsReactiveQueryExecutor import graphql.ExecutionResult import org.slf4j.Logger @@ -74,9 +75,15 @@ class DefaultDgsWebfluxHttpHandler( } return executionResult.flatMap { result -> + val dgsExecutionResult = when (result) { + is DgsExecutionResult -> result + else -> DgsExecutionResult(result) + } + ServerResponse - .ok() - .bodyValue(result.toSpecification()) + .status(dgsExecutionResult.status) + .headers { it.addAll(dgsExecutionResult.headers) } + .bodyValue(dgsExecutionResult.toSpecification()) }.onErrorResume { ex -> when (ex) { is JsonParseException -> diff --git a/graphql-dgs-spring-webflux-autoconfigure/src/test/kotlin/com/netflix/graphql/dgs/webflux/MalformedQueryContentTest.kt b/graphql-dgs-spring-webflux-autoconfigure/src/test/kotlin/com/netflix/graphql/dgs/webflux/MalformedQueryContentTest.kt index 9382e4e4c0..e948f1569d 100644 --- a/graphql-dgs-spring-webflux-autoconfigure/src/test/kotlin/com/netflix/graphql/dgs/webflux/MalformedQueryContentTest.kt +++ b/graphql-dgs-spring-webflux-autoconfigure/src/test/kotlin/com/netflix/graphql/dgs/webflux/MalformedQueryContentTest.kt @@ -77,7 +77,7 @@ class MalformedQueryContentTest { .bodyValue("{ }") .exchange() .expectStatus() - .isOk + .isBadRequest .expectBody() .json( """ diff --git a/graphql-dgs/src/main/kotlin/com/netflix/graphql/dgs/internal/DgsExecutionResult.kt b/graphql-dgs/src/main/kotlin/com/netflix/graphql/dgs/internal/DgsExecutionResult.kt index aa5f90b9e1..e2177c1078 100644 --- a/graphql-dgs/src/main/kotlin/com/netflix/graphql/dgs/internal/DgsExecutionResult.kt +++ b/graphql-dgs/src/main/kotlin/com/netflix/graphql/dgs/internal/DgsExecutionResult.kt @@ -120,9 +120,10 @@ class DgsExecutionResult @JvmOverloads constructor( // overridden for compatibility with https://github.com/Netflix/dgs-framework/pull/1261. override fun toSpecification(): MutableMap { val spec = executionResult.toSpecification() - val extensions = spec["extensions"] as Map<*, *> - if (extensions.containsKey(DGS_RESPONSE_HEADERS_KEY)) { + if (spec["extensions"] != null && extensions.containsKey(DGS_RESPONSE_HEADERS_KEY)) { + val extensions = spec["extensions"] as Map<*, *> + if (extensions.size != 1) { spec["extensions"] = extensions.minus(DGS_RESPONSE_HEADERS_KEY) } else {