@@ -41,10 +41,10 @@ import kotlin.reflect.full.createType
4141 */
4242open class SchemaGenerator (internal val config : SchemaGeneratorConfig ) {
4343
44+ internal val additionalTypes = mutableSetOf<KType >()
4445 internal val classScanner = ClassScanner (config.supportedPackages)
4546 internal val cache = TypesCache (config.supportedPackages)
4647 internal val codeRegistry = GraphQLCodeRegistry .newCodeRegistry()
47- internal val additionalTypes = mutableSetOf<KType >()
4848 internal val directives = ConcurrentHashMap <String , GraphQLDirective >()
4949
5050 /* *
@@ -53,17 +53,18 @@ open class SchemaGenerator(internal val config: SchemaGeneratorConfig) {
5353 open fun generateSchema (
5454 queries : List <TopLevelObject >,
5555 mutations : List <TopLevelObject > = emptyList(),
56- subscriptions : List <TopLevelObject > = emptyList()
56+ subscriptions : List <TopLevelObject > = emptyList(),
57+ additionalTypes : Set <KType > = emptySet()
5758 ): GraphQLSchema {
5859
60+ this .additionalTypes.addAll(additionalTypes)
5961 val builder = GraphQLSchema .newSchema()
6062 builder.query(generateQueries(this , queries))
6163 builder.mutation(generateMutations(this , mutations))
6264 builder.subscription(generateSubscriptions(this , subscriptions))
6365 builder.additionalTypes(generateAdditionalTypes())
6466 builder.additionalDirectives(directives.values.toSet())
6567 builder.codeRegistry(codeRegistry.build())
66-
6768 val schema = config.hooks.willBuildSchema(builder).build()
6869
6970 classScanner.close()
@@ -85,11 +86,11 @@ open class SchemaGenerator(internal val config: SchemaGeneratorConfig) {
8586 /* *
8687 * Generate the GraphQL type for all the `additionalTypes`. They are generated as non-inputs and not as IDs.
8788 * If you need to provide more custom additional types that were not picked up from reflection of the schema objects,
88- * you can modify the set of `additionalTypes` before you call this method .
89+ * you can provide more types to be added through [generateSchema] .
8990 *
90- * This function is recursive because while generating the additionalTypes it is possible to create additional types that need to be processed.
91+ * This function loops because while generating the additionalTypes it is possible to create more additional types that need to be processed.
9192 */
92- protected open fun generateAdditionalTypes (): Set <GraphQLType > {
93+ protected fun generateAdditionalTypes (): Set <GraphQLType > {
9394 val graphqlTypes = mutableSetOf<GraphQLType >()
9495 while (this .additionalTypes.isNotEmpty()) {
9596 val currentlyProcessedTypes = LinkedHashSet (this .additionalTypes)
0 commit comments