Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support built-in ID type serialization in GraphQLServerRequest #1958

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading