Skip to content

Commit

Permalink
Support built-in ID type serialization in GraphQLServerRequest (#…
Browse files Browse the repository at this point in the history
…1958)

Backport of #1952 to
v7

Co-authored-by: Tasuku Nakagawa <[email protected]>
  • Loading branch information
samuelAndalon and T45K authored Apr 16, 2024
1 parent 90398d7 commit 27d7be0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.expediagroup.graphql.server.types.serializers

import com.expediagroup.graphql.generator.scalars.ID
import kotlinx.serialization.KSerializer
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.descriptors.buildClassSerialDescriptor
Expand Down Expand Up @@ -41,6 +42,7 @@ object AnyNullableKSerializer : KSerializer<Any?> {
is Number -> JsonPrimitive(value)
is Boolean -> JsonPrimitive(value)
is String -> JsonPrimitive(value)
is ID -> JsonPrimitive(value.value)
else -> JsonNull
}

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

package com.expediagroup.graphql.server.types

import com.expediagroup.graphql.generator.scalars.ID
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -51,6 +52,20 @@ class GraphQLServerRequestTest {
assertEquals(expectedJson, Json.encodeToString(request))
}

@Test
fun `verify complete serialization including ID`() {
val request = GraphQLRequest(
query = "query FooQuery(\$input: ID) { foo(\$input) }",
operationName = "FooQuery",
variables = mapOf("input" to ID("1"))
)

val expectedJson =
"""{"query":"query FooQuery(${'$'}input: ID) { foo(${'$'}input) }","operationName":"FooQuery","variables":{"input":"1"}}"""

assertEquals(expectedJson, Json.encodeToString(request))
}

@Test
fun `verify batch request serialization`() {
val request = GraphQLBatchRequest(
Expand Down

0 comments on commit 27d7be0

Please sign in to comment.