From e1519a2fb09bd04d1700fe715f81d4f2cd4df5c3 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 18 Nov 2021 19:58:41 +0200 Subject: [PATCH 1/2] refactor: Added util function jsonTypeRef for simplification of TypeRef creation (added to examples as well) --- .../kotlin/com/netflix/graphql/dgs/client/GraphQLResponse.kt | 4 +++- .../com/netflix/graphql/dgs/client/WebSocketGraphQLClient.kt | 4 ++-- .../com/netflix/graphql/dgs/client/GraphQLResponseTest.kt | 5 ++--- .../src/test/kotlin/OperationMessageTest.kt | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/graphql-dgs-client/src/main/kotlin/com/netflix/graphql/dgs/client/GraphQLResponse.kt b/graphql-dgs-client/src/main/kotlin/com/netflix/graphql/dgs/client/GraphQLResponse.kt index dff2a8c10..e2864841e 100644 --- a/graphql-dgs-client/src/main/kotlin/com/netflix/graphql/dgs/client/GraphQLResponse.kt +++ b/graphql-dgs-client/src/main/kotlin/com/netflix/graphql/dgs/client/GraphQLResponse.kt @@ -49,7 +49,7 @@ data class GraphQLResponse(val json: String, val headers: Map = parsed.read("data") ?: emptyMap() - val errors: List = parsed.read("errors", object : TypeRef>() {}) ?: emptyList() + val errors: List = parsed.read("errors", jsonTypeRef>() ) ?: emptyList() constructor(json: String) : this(json, emptyMap()) @@ -136,3 +136,5 @@ data class GraphQLResponse(val json: String, val headers: Map jsonTypeRef(): TypeRef = object: TypeRef() {} diff --git a/graphql-dgs-client/src/main/kotlin/com/netflix/graphql/dgs/client/WebSocketGraphQLClient.kt b/graphql-dgs-client/src/main/kotlin/com/netflix/graphql/dgs/client/WebSocketGraphQLClient.kt index 87bb59687..a03651c45 100644 --- a/graphql-dgs-client/src/main/kotlin/com/netflix/graphql/dgs/client/WebSocketGraphQLClient.kt +++ b/graphql-dgs-client/src/main/kotlin/com/netflix/graphql/dgs/client/WebSocketGraphQLClient.kt @@ -16,8 +16,8 @@ package com.netflix.graphql.dgs.client -import com.fasterxml.jackson.core.type.TypeReference 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.springframework.web.reactive.socket.WebSocketMessage @@ -263,7 +263,7 @@ class OperationMessageWebSocketClient( private fun decodeMessage(message: WebSocketMessage): OperationMessage { val messageText = message.payloadAsText - val type = object : TypeReference() {} + val type = jacksonTypeRef() return MAPPER.readValue(messageText, type) } 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 118286569..10429f3ed 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 @@ -16,7 +16,6 @@ package com.netflix.graphql.dgs.client -import com.jayway.jsonpath.TypeRef import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.springframework.http.HttpEntity @@ -184,9 +183,9 @@ class GraphQLResponseTest { emptyMap(), requestExecutor ) - val listOfSubmittedBy: List = graphQLResponse.extractValueAsObject( + val listOfSubmittedBy = graphQLResponse.extractValueAsObject( "submitReview.edges[*].node.submittedBy", - object : TypeRef>() {} + jsonTypeRef>() ) assertThat(listOfSubmittedBy).isInstanceOf(ArrayList::class.java) assertThat(listOfSubmittedBy.size).isEqualTo(2) diff --git a/graphql-dgs-subscription-types/src/test/kotlin/OperationMessageTest.kt b/graphql-dgs-subscription-types/src/test/kotlin/OperationMessageTest.kt index 7d467e8b2..566477881 100644 --- a/graphql-dgs-subscription-types/src/test/kotlin/OperationMessageTest.kt +++ b/graphql-dgs-subscription-types/src/test/kotlin/OperationMessageTest.kt @@ -14,10 +14,10 @@ * limitations under the License. */ -import com.fasterxml.jackson.core.type.TypeReference import com.fasterxml.jackson.databind.JsonMappingException import com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import com.netflix.graphql.types.subscription.* import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -76,7 +76,7 @@ class OperationMessageTest { } private fun deserialize(message: String) = - MAPPER.readValue(message, object : TypeReference() {}) + MAPPER.readValue(message, jacksonTypeRef()) companion object { val MAPPER = jacksonObjectMapper() From 9b5bf9cd921ee6a4d5977321c2cf5f9590c72bb0 Mon Sep 17 00:00:00 2001 From: Nick Papirniy Date: Wed, 24 Nov 2021 12:46:04 +0200 Subject: [PATCH 2/2] refactor: fixed linter --- .../kotlin/com/netflix/graphql/dgs/client/GraphQLResponse.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/graphql-dgs-client/src/main/kotlin/com/netflix/graphql/dgs/client/GraphQLResponse.kt b/graphql-dgs-client/src/main/kotlin/com/netflix/graphql/dgs/client/GraphQLResponse.kt index e2864841e..554143ead 100644 --- a/graphql-dgs-client/src/main/kotlin/com/netflix/graphql/dgs/client/GraphQLResponse.kt +++ b/graphql-dgs-client/src/main/kotlin/com/netflix/graphql/dgs/client/GraphQLResponse.kt @@ -49,7 +49,7 @@ data class GraphQLResponse(val json: String, val headers: Map = parsed.read("data") ?: emptyMap() - val errors: List = parsed.read("errors", jsonTypeRef>() ) ?: emptyList() + val errors: List = parsed.read("errors", jsonTypeRef>()) ?: emptyList() constructor(json: String) : this(json, emptyMap()) @@ -137,4 +137,4 @@ data class GraphQLResponse(val json: String, val headers: Map jsonTypeRef(): TypeRef = object: TypeRef() {} +inline fun jsonTypeRef(): TypeRef = object : TypeRef() {}