Skip to content

Instantly share code, notes, and snippets.

@amitgupta1202
Last active April 24, 2021 04:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amitgupta1202/c0649cc41395fc4cda12912a0832b871 to your computer and use it in GitHub Desktop.
Save amitgupta1202/c0649cc41395fc4cda12912a0832b871 to your computer and use it in GitHub Desktop.
Temporary fix patchfile for Extended scalar types on DGS Framework
Index: graphql-dgs-client/src/main/kotlin/com/netflix/graphql/dgs/client/codegen/GraphQLQueryRequest.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/graphql-dgs-client/src/main/kotlin/com/netflix/graphql/dgs/client/codegen/GraphQLQueryRequest.kt b/graphql-dgs-client/src/main/kotlin/com/netflix/graphql/dgs/client/codegen/GraphQLQueryRequest.kt
--- a/graphql-dgs-client/src/main/kotlin/com/netflix/graphql/dgs/client/codegen/GraphQLQueryRequest.kt (revision 1fbc781dfd97b0c4170c95182d83094605ac1958)
+++ b/graphql-dgs-client/src/main/kotlin/com/netflix/graphql/dgs/client/codegen/GraphQLQueryRequest.kt (revision 7b264a6732f2590796bbefc42f8f994669106f53)
@@ -16,6 +16,11 @@
package com.netflix.graphql.dgs.client.codegen
+import java.time.LocalDate
+import java.time.OffsetDateTime
+import java.time.OffsetTime
+import java.util.*
+
class GraphQLQueryRequest(private val query: GraphQLQuery, private val projection: BaseProjectionNode?) {
constructor(query: GraphQLQuery) : this(query, null)
@@ -36,21 +41,27 @@
if (value != null) {
builder.append(key)
builder.append(": ")
- if (value is String) {
- builder.append("\"")
- builder.append(value.toString())
- builder.append("\"")
- } else if (value is List<*>) {
- if (value.isNotEmpty() && value[0] is String) {
- builder.append("[")
- val result = value.joinToString(separator = "\", \"", prefix = "\"", postfix = "\"")
- builder.append(result)
- builder.append("]")
- } else {
- builder.append(value.toString())
- }
- } else {
- builder.append(value.toString())
+ when (value) {
+ is String,
+ is OffsetDateTime,
+ is OffsetTime,
+ is LocalDate,
+ is Locale -> {
+ builder.append("\"")
+ builder.append(value.toString())
+ builder.append("\"")
+ }
+ is List<*> -> {
+ if (value.isNotEmpty() && value[0] is String) {
+ builder.append("[")
+ val result = value.joinToString(separator = "\", \"", prefix = "\"", postfix = "\"")
+ builder.append(result)
+ builder.append("]")
+ } else {
+ builder.append(value.toString())
+ }
+ }
+ else -> builder.append(value.toString())
}
}
if (inputEntryIterator.hasNext()) {
Index: graphql-dgs-client/src/test/kotlin/com/netflix/graphql/dgs/client/GraphQLQueryRequestTest.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/graphql-dgs-client/src/test/kotlin/com/netflix/graphql/dgs/client/GraphQLQueryRequestTest.kt b/graphql-dgs-client/src/test/kotlin/com/netflix/graphql/dgs/client/GraphQLQueryRequestTest.kt
--- a/graphql-dgs-client/src/test/kotlin/com/netflix/graphql/dgs/client/GraphQLQueryRequestTest.kt (revision 1fbc781dfd97b0c4170c95182d83094605ac1958)
+++ b/graphql-dgs-client/src/test/kotlin/com/netflix/graphql/dgs/client/GraphQLQueryRequestTest.kt (revision 7b264a6732f2590796bbefc42f8f994669106f53)
@@ -21,6 +21,9 @@
import com.netflix.graphql.dgs.client.codegen.GraphQLQueryRequest
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
+import java.time.*
+import java.time.ZoneOffset.UTC
+import java.util.*
class GraphQLQueryRequestTest {
@Test
@@ -94,6 +97,46 @@
val result = request.serialize()
assertThat(result).isEqualTo("query TestNamedQuery {test(movie: {movieId:123, name:\"greatMovie\" }){ name movieId } }")
}
+
+ @Test
+ fun testSerializeInputClassOffsetDateTime() {
+ val query = TestGraphQLQuery().apply {
+ input["dateTime"] = OffsetDateTime.ofInstant(Instant.EPOCH, ZoneId.from(UTC))
+ }
+ val request = GraphQLQueryRequest(query)
+ val result = request.serialize()
+ assertThat(result).isEqualTo("query {test(dateTime: \"1970-01-01T00:00Z\") }")
+ }
+
+ @Test
+ fun testSerializeInputClassOffsetTime() {
+ val query = TestGraphQLQuery().apply {
+ input["time"] = OffsetTime.MIN
+ }
+ val request = GraphQLQueryRequest(query)
+ val result = request.serialize()
+ assertThat(result).isEqualTo("query {test(time: \"00:00+18:00\") }")
+ }
+
+ @Test
+ fun testSerializeInputClassLocalDate() {
+ val query = TestGraphQLQuery().apply {
+ input["date"] = LocalDate.of(2021, Month.APRIL, 1)
+ }
+ val request = GraphQLQueryRequest(query)
+ val result = request.serialize()
+ assertThat(result).isEqualTo("query {test(date: \"2021-04-01\") }")
+ }
+
+ @Test
+ fun testSerializeInputClassLocale() {
+ val query = TestGraphQLQuery().apply {
+ input["locale"] = Locale.UK
+ }
+ val request = GraphQLQueryRequest(query)
+ val result = request.serialize()
+ assertThat(result).isEqualTo("query {test(locale: \"en_GB\") }")
+ }
}
class TestGraphQLQuery : GraphQLQuery() {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment