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

Do not use 'header' as a enum value name as it breaks the Kotlin compiler #4086

Merged
merged 4 commits into from May 9, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -13,7 +13,8 @@ private val JAVA_RESERVED_WORDS = arrayOf(

// Reference:
// https://kotlinlang.org/docs/enum-classes.html#working-with-enum-constants:~:text=properties%20for%20obtaining%20its%20name%20and%20position
private val KOTLIN_RESERVED_ENUM_VALUE_NAMES = arrayOf("name", "ordinal")
// "header" and "impl" are added to this list because of https://youtrack.jetbrains.com/issue/KT-52315
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😱

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR to handle this at the KotlinPoet level: square/kotlinpoet#1248

private val KOTLIN_RESERVED_ENUM_VALUE_NAMES = arrayOf("name", "ordinal", "header", "impl")

fun String.escapeJavaReservedWord() = if (this in JAVA_RESERVED_WORDS) "${this}_" else this

Expand Down
1 change: 1 addition & 0 deletions tests/enums/src/main/graphql/operation.graphql
@@ -1,4 +1,5 @@
query GetEnums {
direction
gravity
foo
}
7 changes: 7 additions & 0 deletions tests/enums/src/main/graphql/schema.graphqls
@@ -1,6 +1,7 @@
type Query {
direction: Direction
gravity: Gravity
foo: Foo
}

enum Direction {
Expand Down Expand Up @@ -29,3 +30,9 @@ enum Gravity {
name,
ordinal,
}

# See https://youtrack.jetbrains.com/issue/KT-52315
enum Foo {
header,
footer,
}