From 253b142d548df3ad793e11fce2e7d3e6641bac40 Mon Sep 17 00:00:00 2001 From: Patrick Strawderman Date: Tue, 23 Jan 2024 16:07:03 -0800 Subject: [PATCH] Fix classification type in GraphQLErrorExtensions GraphQLErrorExtensions' classification property had a type of String, but in practice an ErrorClassification may be mapped to any JSON serializable type; this is actually the case in practice when using libraries such as graphql-java-extended-validation, which may return a Map for its ErrorClassification. Switch the type to Any, so that such responses can be deserialized, and add a simple test case. --- .../graphql/dgs/client/GraphQLError.kt | 2 +- .../graphql/dgs/client/GraphQLResponseTest.kt | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/graphql-dgs-client/src/main/kotlin/com/netflix/graphql/dgs/client/GraphQLError.kt b/graphql-dgs-client/src/main/kotlin/com/netflix/graphql/dgs/client/GraphQLError.kt index 77a92ad56..88edb36f5 100644 --- a/graphql-dgs-client/src/main/kotlin/com/netflix/graphql/dgs/client/GraphQLError.kt +++ b/graphql-dgs-client/src/main/kotlin/com/netflix/graphql/dgs/client/GraphQLError.kt @@ -41,7 +41,7 @@ data class GraphQLErrorExtensions( @JsonProperty val errorDetail: String? = null, @JsonProperty val origin: String = "", @JsonProperty val debugInfo: GraphQLErrorDebugInfo = GraphQLErrorDebugInfo(), - @JsonProperty val classification: String = "" + @JsonProperty val classification: Any = "" ) data class GraphQLErrorDebugInfo( diff --git a/graphql-dgs-client/src/test/kotlin/com/netflix/graphql/dgs/client/GraphQLResponseTest.kt b/graphql-dgs-client/src/test/kotlin/com/netflix/graphql/dgs/client/GraphQLResponseTest.kt index 552c15162..2b49684cc 100644 --- a/graphql-dgs-client/src/test/kotlin/com/netflix/graphql/dgs/client/GraphQLResponseTest.kt +++ b/graphql-dgs-client/src/test/kotlin/com/netflix/graphql/dgs/client/GraphQLResponseTest.kt @@ -19,6 +19,7 @@ package com.netflix.graphql.dgs.client import org.assertj.core.api.Assertions.assertThat +import org.assertj.core.api.Assertions.fail import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import org.junit.jupiter.params.ParameterizedTest @@ -257,4 +258,32 @@ class GraphQLResponseTest { val result = response.dataAsObject(Response::class.java) assertEquals(Response(submitReview = mapOf("submittedBy" to "abc@netflix.com")), result) } + + @Test + fun testObjectErrorClassification() { + val response = GraphQLResponse( + """{ + "data": null, + "errors": [{ + "message": "Validation failed", + "path": ["shows", 12], + "extensions": { + "errorType": "INTERNAL", + "classification": { + "type": "ExtendedValidationError", + "validatedPath": ["shows", "title"] + } + } + }] + } + """.trimIndent() + ) + val error = response.errors.singleOrNull() ?: fail("Expected single error on response: $response") + assertThat(error.message).isEqualTo("Validation failed") + assertThat(error.path).isEqualTo(listOf("shows", 12)) + + val extensions = error.extensions ?: fail("Expected non-null extensions on error: $error") + assertThat(extensions.errorType).isEqualTo(ErrorType.INTERNAL) + assertThat(extensions.classification).isEqualTo(mapOf("type" to "ExtendedValidationError", "validatedPath" to listOf("shows", "title"))) + } }