Skip to content

Commit

Permalink
Ensure reserved words are escaped in generated inputs (#604)
Browse files Browse the repository at this point in the history
* Ensure reserved words are escaped in generated inputs

* Address linting
  • Loading branch information
mbossenbroek authored Sep 28, 2023
1 parent f967747 commit 81b7cc7
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.netflix.graphql.dgs.codegen.cases.inputWithReservedWord.expected

public object DgsClient
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.netflix.graphql.dgs.codegen.cases.inputWithReservedWord.expected

import kotlin.String

public object DgsConstants {
public object SAMPLEINPUT {
public const val TYPE_NAME: String = "SampleInput"

public const val Return: String = "return"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.netflix.graphql.dgs.codegen.cases.inputWithReservedWord.expected.types

import com.netflix.graphql.dgs.codegen.GraphQLInput
import kotlin.Any
import kotlin.Pair
import kotlin.String
import kotlin.collections.List

public class SampleInput(
public val `return`: String,
) : GraphQLInput() {
public override fun fields(): List<Pair<String, Any?>> = listOf("return" to `return`)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
input SampleInput {
return: String!
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.netflix.graphql.dgs.codegen.generators.shared.SchemaExtensionsUtils.f
import com.netflix.graphql.dgs.codegen.generators.shared.excludeSchemaTypeExtension
import com.netflix.graphql.dgs.codegen.shouldSkip
import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.CodeBlock
import com.squareup.kotlinpoet.FileSpec
import com.squareup.kotlinpoet.FunSpec
import com.squareup.kotlinpoet.KModifier
Expand Down Expand Up @@ -120,10 +121,12 @@ fun generateKotlin2InputTypes(
)
)
)
.addStatement(
"return listOf(${
fields.joinToString(", ") { """"${it.name}" to ${it.name}""" }
})"
.addCode(
fields.let { fs ->
val builder = CodeBlock.builder().add("return listOf(")
fs.forEachIndexed { i, f -> builder.add("%S to %N%L", f.name, f.name, if (i < fs.size.dec()) ", " else "") }
builder.add(")").build()
}
)
.build()
)
Expand Down

0 comments on commit 81b7cc7

Please sign in to comment.