graphql.kickstart.tools.JavassistProxyHandler.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of graphql-java-tools Show documentation
Show all versions of graphql-java-tools Show documentation
Tools to help map a GraphQL schema to existing Java objects.
package graphql.kickstart.tools
import javassist.util.proxy.ProxyFactory
/**
* @author Marcus Thiesen
*/
class JavassistProxyHandler : ProxyHandler {
private val isEnabled: Boolean =
try {
Class.forName("javassist.util.proxy.ProxyFactory")
true
} catch (_: ClassNotFoundException) {
false
}
override fun canHandle(resolver: GraphQLResolver<*>?): Boolean {
return isEnabled && ProxyFactory.isProxyClass(resolver?.javaClass)
}
override fun getTargetClass(resolver: GraphQLResolver<*>?): Class<*> = resolver!!.javaClass.superclass
}