graphql.kickstart.tools.SchemaParserDictionary.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 graphql.kickstart.tools.util.BiMap
import kotlin.reflect.KClass
class SchemaParserDictionary {
private val dictionary: BiMap> = BiMap.create()
fun getDictionary(): BiMap> = BiMap.unmodifiableBiMap(dictionary)
/**
* Add arbitrary classes to the parser's dictionary, overriding the generated type name.
*/
fun add(name: String, clazz: Class<*>) = this.apply {
this.dictionary.put(name, clazz)
}
/**
* Add arbitrary classes to the parser's dictionary, overriding the generated type name.
*/
fun add(name: String, clazz: KClass<*>) = this.apply {
this.dictionary.put(name, clazz.java)
}
/**
* Add arbitrary classes to the parser's dictionary, overriding the generated type name.
*/
fun add(dictionary: Map>) = this.apply {
this.dictionary.putAll(dictionary)
}
/**
* Add arbitrary classes to the parser's dictionary.
*/
fun add(clazz: Class<*>) = this.apply {
this.add(clazz.simpleName, clazz)
}
/**
* Add arbitrary classes to the parser's dictionary.
*/
fun add(clazz: KClass<*>) = this.apply {
this.add(clazz.java.simpleName, clazz)
}
/**
* Add arbitrary classes to the parser's dictionary.
*/
fun add(vararg dictionary: Class<*>) = this.apply {
dictionary.forEach { this.add(it) }
}
/**
* Add arbitrary classes to the parser's dictionary.
*/
fun add(vararg dictionary: KClass<*>) = this.apply {
dictionary.forEach { this.add(it) }
}
/**
* Add arbitrary classes to the parser's dictionary.
*/
fun add(dictionary: Collection>) = this.apply {
dictionary.forEach { this.add(it) }
}
}