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

fix(kotlin): Enum names must not contain typesPrefix or typesSuffix #606

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/curly-brooms-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-codegen/kotlin': patch
---

fix(kotlin) Omit typesSuffix in enum names.
1 change: 1 addition & 0 deletions packages/plugins/java/kotlin/src/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export class KotlinResolversVisitor extends BaseVisitor<
return indent(
`${this.convertName(node, {
useTypesPrefix: false,
useTypesSuffix: false,
transformUnderscore: true,
})}("${this.getEnumValue(enumName, node.name.value)}")`,
);
Expand Down
46 changes: 46 additions & 0 deletions packages/plugins/java/kotlin/tests/kotlin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('Kotlin', () => {
username: String
email: String
name: String
role: UserRole = USER
sort: ResultSort
metadata: MetadataSearch
}
Expand Down Expand Up @@ -154,6 +155,49 @@ describe('Kotlin', () => {
}
}`);
});

it('Should omit typesPrefix/typesSuffix in enum names if the option is set', async () => {
const result = await plugin(
schema,
[],
{ typesPrefix: 'Graphql', typesSuffix: 'Type' },
{ outputFile: OUTPUT_FILE },
);

// language=kotlin
expect(result).toBeSimilarStringTo(` enum class GraphqlUserRoleType(val label: String) {
Admin("ADMIN"),
User("USER"),
Editor("EDITOR");

companion object {
@JvmStatic
fun valueOfLabel(label: String): GraphqlUserRoleType? {
return values().find { it.label == label }
}
}
}`);

// language=kotlin
expect(result).toBeSimilarStringTo(`data class GraphqlSearchUserTypeInput(
val username: String? = null,
val email: String? = null,
val name: String? = null,
val role: GraphqlUserRoleType? = GraphqlUserRoleType.USER,
val sort: GraphqlResultSortType? = null,
val metadata: GraphqlMetadataSearchTypeInput? = null
) {
@Suppress("UNCHECKED_CAST")
constructor(args: Map<String, Any>) : this(
args["username"] as String?,
args["email"] as String?,
args["name"] as String?,
args["role"] as GraphqlUserRoleType? ?: GraphqlUserRoleType.USER,
args["sort"] as GraphqlResultSortType?,
args["metadata"]?.let { GraphqlMetadataSearchTypeInput(it as Map<String, Any>) }
)
}`);
});
});

describe('Input Types / Arguments', () => {
Expand Down Expand Up @@ -243,6 +287,7 @@ describe('Kotlin', () => {
val username: String? = null,
val email: String? = null,
val name: String? = null,
val role: UserRole? = UserRole.USER,
val sort: ResultSort? = null,
val metadata: MetadataSearchInput? = null
) {
Expand All @@ -251,6 +296,7 @@ describe('Kotlin', () => {
args["username"] as String?,
args["email"] as String?,
args["name"] as String?,
args["role"] as UserRole? ?: UserRole.USER,
args["sort"] as ResultSort?,
args["metadata"]?.let { MetadataSearchInput(it as Map<String, Any>) }
)
Expand Down
Loading