All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jvmMain.graphql.coercion.InputObjectCoercer.kt Maven / Gradle / Ivy

The newest version!
package io.fluidsonic.raptor.graphql.internal

import io.fluidsonic.graphql.*
import io.fluidsonic.raptor.*


internal object InputObjectCoercer : GNodeInputCoercer>, GVariableInputCoercer> {

	private fun GInputCoercerContext.coerceInput(input: Map): Any {
		val context = checkNotNull(execution.raptorContext)
		val type = type as GInputObjectType
		val definition = type.raptorType as InputObjectGraphType

		val inputScope = object : RaptorGraphInputScope, RaptorGraphScope by context { // TODO improve

			override fun invalid(details: String?): Nothing =
				[email protected](details = details)
		}

		return definition.argumentResolver.withArguments(
			argumentValues = input,
			argumentDefinitions = type.argumentDefinitions,
			context = execution
		) { definition.create(inputScope) }
	}


	override fun GNodeInputCoercerContext.coerceNodeInput(input: Map): Any =
		coerceInput(input)


	override fun GVariableInputCoercerContext.coerceVariableInput(input: Map): Any =
		coerceInput(input)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy