Skip to content

CoercingSerializeException when serializing null as nullable ID.  #1604

@sparlampe

Description

@sparlampe

Library Version
'org.http4k:http4k-graphql:4.33.1.0'
'com.expediagroup:graphql-kotlin-schema-generator:6.3.0'

Describe the bug
An error occurs when serializing a null as ID?

To Reproduce

import com.expediagroup.graphql.generator.TopLevelObject
import com.expediagroup.graphql.generator.scalars.ID
import com.expediagroup.graphql.generator.toSchema
import graphql.GraphQL
import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Test

internal class GraphQlSerializationTest {
    class Query {
        fun getID(): ID? {
            return null
        }
    }
    private val topLevelObject = TopLevelObject(Query())
    private val config = SchemaGeneratorConfig(listOf())
    val schema = toSchema(config = config, queries = listOf(topLevelObject))
    private val query = """
                |    query {
                |       getID
                |    }
                |""".trimMargin()
    @Test
    fun `serializes nullable ID`() {
        val graphQLResult = GraphQL
            .newGraphQL(schema)
            .build()
            .execute(query)
        graphQLResult.getData<Map<String,Any?>>()["getID"] shouldBe null
        graphQLResult.errors shouldBe null
    }
}

The above test fails as the second assertion fails with the following error.

Expected null but actual was [SerializationError{path=[getID], exception=graphql.schema.CoercingSerializeException: Expected type 'ID' but was 'ID'.}]

Expected behavior
GraphQL response should not contain serialization errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions