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

jvmMain.graphql.GraphSystem.kt Maven / Gradle / Ivy

There is a newer version: 0.26.0
Show newest version
package io.fluidsonic.raptor

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


internal class GraphSystem(
	val schema: GSchema,
	val typeSystem: GraphTypeSystem,
) {

	private val executor = GExecutor.default(
		exceptionHandler = ExceptionHandler(), // TODO improve
		schema = schema,
		nodeInputCoercer = NodeInputCoercer,
		variableInputCoercer = VariableInputCoercer
	)


	suspend fun execute(
		documentSource: GDocumentSource.Parsable,
		operationName: String? = null,
		variableValues: Map = emptyMap(),
		context: RaptorGraphContext,
	): Map =
		GDocument.parse(documentSource)
			.flatMapValue { document ->
				val errors = document.validate(schema)
				when {
					errors.isNotEmpty() -> GResult.failure(errors)
					else -> GResult.success(document)
				}
			}
			.flatMapValue { document ->
				executor.execute(
					document = document,
					operationName = operationName,
					variableValues = variableValues,
					extensions = GExecutorContextExtensionSet {
						raptorContext = context
					}
				)
			}
			.let { executor.serializeResult(it) }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy