in graphql-dgs-codegen-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/generators/kotlin/KotlinPoetUtils.kt [312:354]
fun customAnnotation(
annotationArgumentMap: MutableMap<String, Value<Value<*>>>,
config: CodeGenConfig,
): AnnotationSpec {
if (annotationArgumentMap.isEmpty() ||
!annotationArgumentMap.containsKey(ParserConstants.NAME) ||
annotationArgumentMap[ParserConstants.NAME] is NullValue ||
(annotationArgumentMap[ParserConstants.NAME] as StringValue).value.isEmpty()
) {
throw IllegalArgumentException("Invalid annotate directive")
}
val (packageName, simpleName) =
PackageParserUtil.getAnnotationPackage(
config,
(annotationArgumentMap[ParserConstants.NAME] as StringValue).value,
if (annotationArgumentMap.containsKey(ParserConstants.TYPE) &&
annotationArgumentMap[ParserConstants.TYPE] !is NullValue
) {
(annotationArgumentMap[ParserConstants.TYPE] as StringValue).value
} else {
null
},
)
val className = ClassName(packageName = packageName, simpleNames = listOf(simpleName))
val annotation: AnnotationSpec.Builder = AnnotationSpec.builder(className)
if (annotationArgumentMap.containsKey(ParserConstants.SITE_TARGET)) {
annotation.useSiteTarget(
AnnotationSpec.UseSiteTarget.valueOf((annotationArgumentMap[ParserConstants.SITE_TARGET] as StringValue).value.uppercase()),
)
}
if (annotationArgumentMap.containsKey(ParserConstants.INPUTS)) {
val codeBlocks: List<CodeBlock> =
parseInputs(
config,
annotationArgumentMap[ParserConstants.INPUTS] as ObjectValue,
(annotationArgumentMap[ParserConstants.NAME] as StringValue).value,
)
codeBlocks.forEach { codeBlock ->
annotation.addMember(codeBlock)
}
}
return annotation.build()
}