Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -394,14 +394,30 @@ class CodeGen(private val config: CodeGenConfig) {
return CodeGenResult()
}

val interfaceCodeGen = if (config.generateInterfaces) {
definitions.asSequence()
.filterIsInstance<ObjectTypeDefinition>()
.excludeSchemaTypeExtension()
.filter { it.name != "Query" && it.name != "Mutation" && it.name != "RelayPageInfo" }
.map { definition ->
val interfaceGenerator = KotlinInterfaceTypeGenerator(config, document)
val interfaceTypeDefinition =
InterfaceTypeDefinition.newInterfaceTypeDefinition().name("I" + definition.name)
.definitions(definition.fieldDefinitions()).build()
interfaceGenerator.generate(interfaceTypeDefinition, emptyList())
}
.fold(CodeGenResult()) { t: CodeGenResult, u: CodeGenResult -> t.merge(u) }
}
else CodeGenResult()

return definitions.asSequence()
.filterIsInstance<InterfaceTypeDefinition>()
.excludeSchemaTypeExtension()
.map {
val extensions = findInterfaceExtensions(it.name, definitions)
KotlinInterfaceTypeGenerator(config, document).generate(it, extensions)
}
.fold(CodeGenResult()) { t: CodeGenResult, u: CodeGenResult -> t.merge(u) }
.fold(interfaceCodeGen) { t: CodeGenResult, u: CodeGenResult -> t.merge(u) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ class KotlinDataTypeGenerator(config: CodeGenConfig, document: Document) :
extensions.flatMap { it.fieldDefinitions }
.filterSkipped()
.map { Field(it.name, typeUtils.findReturnType(it.type), typeUtils.isNullable(it.type), null, it.description) }
val interfaces = definition.implements
val interfaces = when (config.generateInterfaces) {
true -> definition.implements + TypeName.newTypeName("I" + definition.name).build()
else -> definition.implements
}

return generate(definition.name, fields, interfaces, document, definition.description)
}

Expand Down Expand Up @@ -211,7 +215,7 @@ abstract class AbstractKotlinDataTypeGenerator(
.map { it.name }
.toSet()

if (field.name in interfaceFields) {
if (field.name in interfaceFields || config.generateInterfaces) {
// Properties are the syntactical element that will allow us to override things, they are the spec on
// which we should add the override modifier.
propertySpecBuilder.addModifiers(KModifier.OVERRIDE)
Expand Down
Loading