@@ -41,10 +41,10 @@ import kotlin.reflect.full.createType
41
41
*/
42
42
open class SchemaGenerator (internal val config : SchemaGeneratorConfig ) {
43
43
44
+ internal val additionalTypes = mutableSetOf<KType >()
44
45
internal val classScanner = ClassScanner (config.supportedPackages)
45
46
internal val cache = TypesCache (config.supportedPackages)
46
47
internal val codeRegistry = GraphQLCodeRegistry .newCodeRegistry()
47
- internal val additionalTypes = mutableSetOf<KType >()
48
48
internal val directives = ConcurrentHashMap <String , GraphQLDirective >()
49
49
50
50
/* *
@@ -53,17 +53,18 @@ open class SchemaGenerator(internal val config: SchemaGeneratorConfig) {
53
53
open fun generateSchema (
54
54
queries : List <TopLevelObject >,
55
55
mutations : List <TopLevelObject > = emptyList(),
56
- subscriptions : List <TopLevelObject > = emptyList()
56
+ subscriptions : List <TopLevelObject > = emptyList(),
57
+ additionalTypes : Set <KType > = emptySet()
57
58
): GraphQLSchema {
58
59
60
+ this .additionalTypes.addAll(additionalTypes)
59
61
val builder = GraphQLSchema .newSchema()
60
62
builder.query(generateQueries(this , queries))
61
63
builder.mutation(generateMutations(this , mutations))
62
64
builder.subscription(generateSubscriptions(this , subscriptions))
63
65
builder.additionalTypes(generateAdditionalTypes())
64
66
builder.additionalDirectives(directives.values.toSet())
65
67
builder.codeRegistry(codeRegistry.build())
66
-
67
68
val schema = config.hooks.willBuildSchema(builder).build()
68
69
69
70
classScanner.close()
@@ -85,11 +86,11 @@ open class SchemaGenerator(internal val config: SchemaGeneratorConfig) {
85
86
/* *
86
87
* Generate the GraphQL type for all the `additionalTypes`. They are generated as non-inputs and not as IDs.
87
88
* 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] .
89
90
*
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.
91
92
*/
92
- protected open fun generateAdditionalTypes (): Set <GraphQLType > {
93
+ protected fun generateAdditionalTypes (): Set <GraphQLType > {
93
94
val graphqlTypes = mutableSetOf<GraphQLType >()
94
95
while (this .additionalTypes.isNotEmpty()) {
95
96
val currentlyProcessedTypes = LinkedHashSet (this .additionalTypes)
0 commit comments