in graphql-dgs-codegen-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/generators/java/JavaPoetUtils.kt [174:213]
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.get(packageName, simpleName)
val annotation: AnnotationSpec.Builder = AnnotationSpec.builder(className)
if (annotationArgumentMap.containsKey(ParserConstants.INPUTS)) {
val objectFields: List<ObjectField> = (annotationArgumentMap[ParserConstants.INPUTS] as ObjectValue).objectFields
for (objectField in objectFields) {
val codeBlock: CodeBlock =
generateCode(
config,
objectField.value,
(annotationArgumentMap[ParserConstants.NAME] as StringValue).value,
objectField.name,
)
annotation.addMember(objectField.name, codeBlock)
}
}
return annotation.build()
}