graphql.kickstart.tools.directive.SchemaDirectiveWiringEnvironmentImpl.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.directive
import graphql.language.NamedNode
import graphql.language.NodeParentTree
import graphql.schema.*
import graphql.schema.idl.RuntimeWiring
import graphql.schema.idl.SchemaDirectiveWiringEnvironment
import graphql.schema.idl.TypeDefinitionRegistry
class SchemaDirectiveWiringEnvironmentImpl(
private val element: T,
directives: List,
appliedDirectives: List,
private val registeredDirective: GraphQLDirective?,
private val registeredAppliedDirective: GraphQLAppliedDirective?,
parameters: Parameters
) : SchemaDirectiveWiringEnvironment {
private val directives: Map
private val appliedDirectives: Map
private val nodeParentTree: NodeParentTree>?
private val typeDefinitionRegistry: TypeDefinitionRegistry?
private val context: Map?
private val codeRegistry: GraphQLCodeRegistry.Builder
private val elementParentTree: GraphqlElementParentTree?
private val fieldsContainer: GraphQLFieldsContainer?
private val fieldDefinition: GraphQLFieldDefinition?
init {
typeDefinitionRegistry = parameters.typeRegistry
this.directives = directives.associateBy { it.name }
this.appliedDirectives = appliedDirectives.associateBy { it.name }
context = parameters.context
codeRegistry = parameters.codeRegistry
nodeParentTree = parameters.nodeParentTree
elementParentTree = parameters.elementParentTree
fieldsContainer = parameters.fieldsContainer
fieldDefinition = parameters.fieldsDefinition
}
override fun getElement(): T = element
override fun getDirective(): GraphQLDirective? = registeredDirective
override fun getAppliedDirective(): GraphQLAppliedDirective? = registeredAppliedDirective
override fun getDirectives(): Map = LinkedHashMap(directives)
override fun getDirective(directiveName: String): GraphQLDirective = directives[directiveName]!!
override fun getAppliedDirectives(): Map = appliedDirectives
override fun getAppliedDirective(directiveName: String): GraphQLAppliedDirective = appliedDirectives[directiveName]!!
override fun containsDirective(directiveName: String): Boolean = directives.containsKey(directiveName)
override fun getNodeParentTree(): NodeParentTree>? = nodeParentTree
override fun getRegistry(): TypeDefinitionRegistry? = typeDefinitionRegistry
override fun getBuildContext(): Map? = context
override fun getCodeRegistry(): GraphQLCodeRegistry.Builder = codeRegistry
override fun getFieldsContainer(): GraphQLFieldsContainer? = fieldsContainer
override fun getElementParentTree(): GraphqlElementParentTree? = elementParentTree
override fun getFieldDefinition(): GraphQLFieldDefinition? = fieldDefinition
override fun getFieldDataFetcher(): DataFetcher<*> {
checkNotNull(fieldDefinition) { "An output field must be in context to call this method" }
checkNotNull(fieldsContainer) { "An output field container must be in context to call this method" }
return codeRegistry.getDataFetcher(fieldsContainer, fieldDefinition)
}
override fun setFieldDataFetcher(newDataFetcher: DataFetcher<*>?): GraphQLFieldDefinition {
checkNotNull(fieldDefinition) { "An output field must be in context to call this method" }
checkNotNull(fieldsContainer) { "An output field container must be in context to call this method" }
val coordinates = FieldCoordinates.coordinates(fieldsContainer, fieldDefinition)
codeRegistry.dataFetcher(coordinates, newDataFetcher)
return fieldDefinition
}
data class Parameters @JvmOverloads constructor(
val runtimeWiring: RuntimeWiring,
val codeRegistry: GraphQLCodeRegistry.Builder,
val typeRegistry: TypeDefinitionRegistry? = null,
val context: Map? = null,
val nodeParentTree: NodeParentTree>? = null,
val elementParentTree: GraphqlElementParentTree? = null,
val fieldsContainer: GraphQLFieldsContainer? = null,
val fieldsDefinition: GraphQLFieldDefinition? = null
) {
fun newParams(fieldsContainer: GraphQLFieldsContainer, nodeParentTree: NodeParentTree>, elementParentTree: GraphqlElementParentTree): Parameters =
Parameters(runtimeWiring, codeRegistry, typeRegistry, context, nodeParentTree, elementParentTree, fieldsContainer, fieldsDefinition)
fun newParams(fieldDefinition: GraphQLFieldDefinition?, fieldsContainer: GraphQLFieldsContainer?, nodeParentTree: NodeParentTree>, elementParentTree: GraphqlElementParentTree): Parameters =
Parameters(runtimeWiring, codeRegistry, typeRegistry, context, nodeParentTree, elementParentTree, fieldsContainer, fieldDefinition)
fun newParams(nodeParentTree: NodeParentTree>, elementParentTree: GraphqlElementParentTree): Parameters =
Parameters(runtimeWiring, codeRegistry, typeRegistry, context, nodeParentTree, elementParentTree, fieldsContainer, fieldsDefinition)
}
}