Skip to content

Commit fccb5f1

Browse files
authored
move generation of additional types to an iterative approach (ExpediaGroup#619)
1 parent 4aa7872 commit fccb5f1

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

graphql-kotlin-schema-generator/src/main/kotlin/com/expediagroup/graphql/generator/SchemaGenerator.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,15 @@ open class SchemaGenerator(internal val config: SchemaGeneratorConfig) {
9090
* This function is recursive because while generating the additionalTypes it is possible to create additional types that need to be processed.
9191
*/
9292
protected open fun generateAdditionalTypes(): Set<GraphQLType> {
93-
val currentlyProcessedTypes = this.additionalTypes.toSet()
94-
this.additionalTypes.clear()
95-
val graphqlTypes = currentlyProcessedTypes.map { generateGraphQLType(this, it) }.toSet()
93+
val currentlyProcessedTypes = mutableSetOf<KType>()
94+
val graphqlTypes = mutableSetOf<GraphQLType>()
95+
do {
96+
currentlyProcessedTypes.addAll(this.additionalTypes)
97+
this.additionalTypes.clear()
98+
graphqlTypes.addAll(currentlyProcessedTypes.map { generateGraphQLType(this, it) })
99+
currentlyProcessedTypes.clear()
100+
} while (this.additionalTypes.isNotEmpty())
96101

97-
return if (this.additionalTypes.isNotEmpty()) {
98-
graphqlTypes.plus(generateAdditionalTypes())
99-
} else {
100-
graphqlTypes
101-
}
102+
return graphqlTypes.toSet()
102103
}
103104
}

graphql-kotlin-schema-generator/src/test/kotlin/com/expediagroup/graphql/generator/SchemaGeneratorTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class SchemaGeneratorTest {
4848
val result = generator.generateCustomAdditionalTypes()
4949

5050
assertEquals(1, result.size)
51-
assertEquals("SomeObjectWithAnnotaiton!", result.first().deepName)
51+
assertEquals("SomeObjectWithAnnotation!", result.first().deepName)
5252
}
5353

5454
class CustomSchemaGenerator(config: SchemaGeneratorConfig) : SchemaGenerator(config) {
@@ -61,5 +61,5 @@ class SchemaGeneratorTest {
6161
annotation class MyOtherCustomAnnotation
6262

6363
@MyCustomAnnotation
64-
data class SomeObjectWithAnnotaiton(val name: String)
64+
data class SomeObjectWithAnnotation(val name: String)
6565
}

0 commit comments

Comments
 (0)