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

Issue of code generation when using type field reservation word field #622

Open
jongyunha opened this issue Nov 27, 2023 · 2 comments
Open

Comments

@jongyunha
Copy link

jongyunha commented Nov 27, 2023

If the field in the input schema is a reserved word, the Pair value of the fields method of the generated code is missing a backup (`) resulting in a compilation error.

Is there any way to solve the above issue?

used codegen version: 6.0.3

Example Type

type SampleType {
  return: String!
}

Generated Class

@JsonTypeInfo(use = JsonTypeInfo.Id.NONE)
@JsonDeserialize(builder = SampleType.Builder::class)
public class SampleType(
  `return`: () -> String = returnDefault,
) {
  private val _return: () -> String = return // error

  @get:JvmName("getReturn")
  public val `return`: String
    get() = _return.invoke()

  public companion object {
    private val returnDefault: () -> String = 
        { throw IllegalStateException("Field `return` was not requested") }

  }

  @JsonPOJOBuilder
  @JsonIgnoreProperties("__typename")
  public class Builder {
    private var `return`: () -> String = returnDefault

    @JsonProperty("return")
    public fun withReturn(`return`: String): Builder = this.apply {
      this.return = { return } // error
    }

    public fun build() = SampleType(
      return = return, // error
    )
  }
}

gradle

tasks.withType<com.netflix.graphql.dgs.codegen.gradle.GenerateJavaTask> {
    generateClient = true
    generateDataTypes = true
    snakeCaseConstantNames = true
    generateKotlinClosureProjections = true
    generateKotlinNullableClasses = true
    language = "kotlin"
}

Parameters are created with backup, but assignments are not made with backup

@srinivasankavitha
Copy link
Contributor

@mbossenbroek - could you please take a look when you get a chance?

@mbossenbroek
Copy link
Contributor

Fixed here (pending build/merge/release): #623

I'm still unsure how these reserved word issues regressed, but now we have tests to lock in the behavior

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants