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

jvmMain.definitions.RaptorInputObjectGraphDefinitionBuilder.kt Maven / Gradle / Ivy

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

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


@RaptorDsl
public class RaptorInputObjectGraphDefinitionBuilder internal constructor(
	kotlinType: KotlinType,
	name: String,
	private val stackTrace: List,
	private val argumentContainer: RaptorGraphArgumentDefinitionBuilder.ContainerImpl = RaptorGraphArgumentDefinitionBuilder.ContainerImpl(
		factoryName = "factory",
		parentKotlinType = kotlinType
	),
) :
	RaptorStructuredGraphTypeDefinitionBuilder(
		kotlinType = kotlinType,
		name = name
	),
	RaptorGraphArgumentDefinitionBuilder.Container by argumentContainer {

	private var create: (RaptorGraphInputScope.() -> Any)? = null


	override fun build(description: String?, additionalDefinitions: Collection) =
		InputObjectGraphDefinition(
			additionalDefinitions = additionalDefinitions,
			argumentDefinitions = argumentContainer.argumentDefinitions.ifEmpty { null }
				?: error("At least one argument must be defined: argument<…>(…) { … }"),
			argumentResolver = argumentContainer.resolver,
			create = checkNotNull(create) { "The factory must be defined: factory { … }" },
			description = description,
			kotlinType = kotlinType,
			name = name,
			stackTrace = stackTrace
		)


	// TODO rn
	@RaptorDsl
	public fun factory(create: RaptorGraphInputScope.() -> Type) {
		check(this.create === null) { "Cannot define multiple factories." }

		this.create = create
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy