11package com.apollographql.execution.processor
22
33import com.apollographql.apollo.ast.*
4+ import com.apollographql.execution.processor.codegen.KotlinSymbols.GraphQLIgnore
45import com.apollographql.execution.processor.sir.*
56import com.apollographql.execution.processor.sir.Instantiation
67import com.apollographql.execution.processor.sir.SirArgumentDefinition
@@ -19,10 +20,7 @@ import com.apollographql.execution.processor.sir.SirObjectDefinition
1920import com.apollographql.execution.processor.sir.SirType
2021import com.apollographql.execution.processor.sir.SirTypeDefinition
2122import com.apollographql.execution.processor.sir.SirUnionDefinition
22- import com.google.devtools.ksp.getAllSuperTypes
23- import com.google.devtools.ksp.getDeclaredProperties
24- import com.google.devtools.ksp.isConstructor
25- import com.google.devtools.ksp.isPublic
23+ import com.google.devtools.ksp.*
2624import com.google.devtools.ksp.processing.KSPLogger
2725import com.google.devtools.ksp.symbol.*
2826
@@ -41,7 +39,7 @@ internal fun doTraversal(
4139}
4240
4341private class TypeDefinitionContext (
44- val logger : KSPLogger ,
42+ val logger : KSPLogger
4543) {
4644 /* *
4745 * key is qualifiedName
@@ -172,11 +170,6 @@ private class TypeDefinitionContext(
172170 }
173171 usedTypeNames.add(name)
174172
175- if (declaration.typeParameters.isNotEmpty()) {
176- logger.error(" Generic classes are not supported" )
177- return null
178- }
179-
180173 if (declaration is KSTypeAlias ) {
181174 return declaration.toSirScalarDefinition(qualifiedName)
182175 }
@@ -378,10 +371,13 @@ private class TypeDefinitionContext(
378371 logger.error(" Cannot map to a GraphQL output type" , this )
379372 return null
380373 }
381-
382374 val usedNames = mutableSetOf<String >()
383375 val allFields = declarations.filter { it.isPublic() }.mapNotNull {
384376 val name = it.graphqlName()
377+ val hasIsIgnoreAnnotation = this .annotations.any {
378+ it.annotationType.resolve().declaration.qualifiedName?.asString() == " com.apollographql.execution.annotation.GraphQLIgnore"
379+ }
380+ if (hasIsIgnoreAnnotation) return @mapNotNull null
385381 if (usedNames.contains(name)) {
386382 logger.error(" Duplicate field '$name '. Either rename the declaration or use @GraphQLName." , it)
387383 return @mapNotNull null
@@ -435,7 +431,10 @@ private class TypeDefinitionContext(
435431
436432 ClassKind .INTERFACE -> {
437433 if (! modifiers.contains(Modifier .SEALED )) {
438- logger.error(" Interfaces and unions must be sealed interfaces" , this )
434+ logger.error(
435+ " Interfaces and unions must be sealed interfaces or you can use @GraphQLIgnore to ignore the interface generation" ,
436+ this
437+ )
439438 return null
440439 }
441440
@@ -503,10 +502,11 @@ private class TypeDefinitionContext(
503502 private fun KSClassDeclaration.interfaces (objectName : String? ): List <String > {
504503 return getAllSuperTypes().mapNotNull {
505504 val declaration = it.declaration
506- if (it.arguments.isNotEmpty()) {
507- logger.error(" Generic interfaces are not supported" , this )
508- null
509- } else if (declaration is KSClassDeclaration ) {
505+ val hasIsIgnoreAnnotation = this .annotations.any {
506+ it.annotationType.resolve().declaration.qualifiedName?.asString() == " com.apollographql.execution.annotation.GraphQLIgnore"
507+ }
508+ if (hasIsIgnoreAnnotation) return @mapNotNull null
509+ if (declaration is KSClassDeclaration ) {
510510 if (declaration.asClassName().asString() == " kotlin.Any" ) {
511511 // kotlin.Any is a super type of everything, just ignore it
512512 null
0 commit comments