Skip to content

Commit 2739b28

Browse files
authored
fix: class consolidation with enum child types (#65)
1 parent a28b568 commit 2739b28

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

src/helpers/input-type-has-matching-output-type.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ function typesAreEquivalent(
3030
): boolean {
3131
const typeNode = schema.getType(typeName);
3232
const inputNode = schema.getType(inputName);
33-
if (!typeNode?.astNode && !inputNode?.astNode) {
33+
34+
if (
35+
!isObjectType(typeNode) &&
36+
!isInputObjectType(inputNode) &&
37+
typeNode?.astNode?.kind === inputNode?.astNode?.kind
38+
) {
3439
return true;
3540
}
3641
if (

test/unit/should_consolidate_input_and_output_types/expected.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,25 @@ data class MySuperSetTypeInput(
106106
val field2: String? = null,
107107
val field3: Int? = null
108108
)
109+
110+
data class MyTypeWithEnums(
111+
val field1: List<Enum1>? = null,
112+
val field2: List<Enum2>? = null
113+
)
114+
115+
enum class Enum1 {
116+
This,
117+
That;
118+
119+
companion object {
120+
fun findByName(name: String, ignoreCase: Boolean = false): Enum1? = values().find { it.name.equals(name, ignoreCase = ignoreCase) }
121+
}
122+
}
123+
124+
enum class Enum2 {
125+
The_Other;
126+
127+
companion object {
128+
fun findByName(name: String, ignoreCase: Boolean = false): Enum2? = values().find { it.name.equals(name, ignoreCase = ignoreCase) }
129+
}
130+
}

test/unit/should_consolidate_input_and_output_types/schema.graphql

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,22 @@ input MySuperSetTypeInput {
130130
field2: String
131131
field3: Int
132132
}
133+
134+
type MyTypeWithEnums {
135+
field1: [Enum1!]
136+
field2: [Enum2!]
137+
}
138+
139+
input MyTypeWithEnumsInput {
140+
field1: [Enum1!]
141+
field2: [Enum2!]
142+
}
143+
144+
enum Enum1 {
145+
THIS
146+
THAT
147+
}
148+
149+
enum Enum2 {
150+
THE_OTHER
151+
}

0 commit comments

Comments
 (0)