Skip to content

Generated GQL client causes kotlinx.serialization compiler recursion error #1625

Open
@holzerch

Description

@holzerch

Library Version
Kotlin Version: 1.8.0 (also tested 1.7.20)

id("com.expediagroup.graphql") version "6.3.3"

...

implementation("com.expediagroup:graphql-kotlin-spring-client:6.3.3") {
        exclude("com.expediagroup", "graphql-kotlin-client-jackson")
    }
implementation("com.expediagroup:graphql-kotlin-client-serialization:6.3.3")

Describe the bug
After switching from Jackson to kotlinx.serialization the generated code no longer compiles. It fails in the step kotlinCompile with the exception.

org.jetbrains.kotlin.util.KotlinFrontEndException: Front-end Internal error: Failed to analyze declaration Variables
File being compiled: (30,3) in /Users/christian/dev/doms-ecom-integration/build/generated/source/graphql/main/test/CreateFulfilmentOption.kt
The root cause java.lang.AssertionError was thrown at: org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassDescriptor.getModality(LazyClassDescriptor.java:584)
	at org.jetbrains.kotlin.resolve.ExceptionWrappingKtVisitorVoid.visitDeclaration(ExceptionWrappingKtVisitorVoid.kt:43)
	at org.jetbrains.kotlin.psi.KtVisitorVoid.visitDeclaration(KtVisitorVoid.java:461)
	at org.jetbrains.kotlin.psi.KtVisitorVoid.visitDeclaration(KtVisitorVoid.java:21)
	at org.jetbrains.kotlin.psi.KtVisitor.visitNamedDeclaration(KtVisitor.java:406)

...

Caused by: java.lang.AssertionError: Recursion detected in a lazy value under LockBasedStorageManager@756f0f2d (TopDownAnalyzer for JVM)
	at org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassDescriptor.getModality(LazyClassDescriptor.java:584)
	at org.jetbrains.kotlinx.serialization.compiler.resolve.KSerializationUtilKt.getShouldHaveGeneratedSerializer(KSerializationUtil.kt:138)
	at org.jetbrains.kotlinx.serialization.compiler.extensions.SerializationResolveExtension.generateSyntheticClasses(SerializationResolveExtension.kt:78)

The generated code looks like this

@Generated
@Serializable
public class CreateFulfilmentOption(
  public override val variables: CreateFulfilmentOption.Variables,
) : GraphQLClientRequest<CreateFulfilmentOption.Result> {
  @Required
  public override val query: String = CREATE_FULFILMENT_OPTION

  @Required
  public override val operationName: String = "CreateFulfilmentOption"

  public override fun responseType(): KClass<CreateFulfilmentOption.Result> =
      CreateFulfilmentOption.Result::class

  @Generated
  @Serializable
  public data class Variables(
    public val input: CreateFulfilmentOptionInput,
    public val executionMode: ExecutionMode? = null,
  )

  @Generated
  @Serializable
  public data class Result(
    public val createFulfilmentOption: FulfilmentOption? = null,
  )
}

The problem seems to be related to the nested class Result. After moving it outside of CreateFulfilmentOption the error is gone

To Reproduce
Generate client code with kotlinx serialiser and try to compile with the described version.

Expected behavior
The generated code compiles

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