jvmMain.definitions.RaptorGraphDefinitionDsl.kt Maven / Gradle / Ivy
The newest version!
package io.fluidsonic.raptor
import io.fluidsonic.raptor.graphql.internal.*
import io.fluidsonic.stdlib.*
import kotlin.reflect.*
// TODO Allow nested definitions in structured definitions & reuse in RaptorGraphOperationBuilder.
// TODO Can also improve automatic name generation.
@RaptorDsl
public inline fun graphAliasDefinition(
@BuilderInference noinline configure: RaptorAliasGraphDefinitionBuilder.() -> Unit,
): RaptorGraphDefinition =
graphAliasDefinition(
type = typeOf(),
referencedType = typeOf(),
configure = configure
)
@RaptorDsl
public fun graphAliasDefinition(
type: KType,
referencedType: KType,
configure: RaptorAliasGraphDefinitionBuilder.() -> Unit,
): RaptorGraphDefinition =
RaptorAliasGraphDefinitionBuilder(
isId = false,
kotlinType = KotlinType.of(
type = type,
containingType = null,
allowMaybe = false,
allowNull = false,
allowedVariance = KVariance.OUT, // TODO prb. wrong
requireSpecialization = false
),
referencedKotlinType = KotlinType.of(
type = referencedType,
containingType = null,
allowMaybe = false,
allowNull = false,
allowedVariance = KVariance.OUT, // TODO prb. wrong
requireSpecialization = false
),
stackTrace = stackTrace(skipCount = 1),
)
.apply(configure)
.build()
@RaptorDsl
public inline fun > graphEnumDefinition(
name: String = RaptorGraphDefinition.defaultName,
@BuilderInference noinline configure: RaptorEnumGraphDefinitionBuilder.() -> Unit = {},
): RaptorGraphDefinition =
graphEnumDefinition(
name = name,
type = typeOf(),
values = enumValues().toList(),
configure = configure
)
@RaptorDsl
public fun > graphEnumDefinition(
name: String = RaptorGraphDefinition.defaultName,
type: KType,
values: List, // TODO validate
configure: RaptorEnumGraphDefinitionBuilder.() -> Unit = {},
): RaptorGraphDefinition =
RaptorEnumGraphDefinitionBuilder(
kotlinType = KotlinType.of(
type = type,
containingType = null,
allowMaybe = false,
allowNull = false,
allowedVariance = KVariance.OUT, // TODO prb. wrong
requireSpecialization = true
),
name = RaptorGraphDefinition.resolveName(name, type = type),
stackTrace = stackTrace(skipCount = 1),
values = values
)
.apply(configure)
.build()
@RaptorDsl
public inline fun graphIdAliasDefinition(
@BuilderInference noinline configure: RaptorAliasGraphDefinitionBuilder.() -> Unit,
): RaptorGraphDefinition =
graphIdAliasDefinition(
type = typeOf(),
configure = configure
)
@RaptorDsl
public fun graphIdAliasDefinition(
type: KType,
configure: RaptorAliasGraphDefinitionBuilder.() -> Unit,
): RaptorGraphDefinition =
RaptorAliasGraphDefinitionBuilder(
isId = true,
kotlinType = KotlinType.of(
type = type,
containingType = null,
allowMaybe = false,
allowNull = false,
allowedVariance = KVariance.OUT, // TODO prb. wrong
requireSpecialization = false
),
referencedKotlinType = KotlinType.of(
type = typeOf(),
containingType = null,
allowMaybe = false,
allowNull = false,
allowedVariance = KVariance.OUT, // TODO prb. wrong
requireSpecialization = false
),
stackTrace = stackTrace(skipCount = 1)
)
.apply(configure)
.build()
@RaptorDsl
public inline fun graphInputObjectDefinition(
name: String = RaptorGraphDefinition.defaultName,
@BuilderInference noinline configure: RaptorInputObjectGraphDefinitionBuilder.() -> Unit,
): RaptorGraphDefinition =
graphInputObjectDefinition(
name = name,
type = typeOf(),
configure = configure
)
@RaptorDsl
public fun graphInputObjectDefinition(
name: String = RaptorGraphDefinition.defaultName,
type: KType,
configure: RaptorInputObjectGraphDefinitionBuilder.() -> Unit,
): RaptorGraphDefinition =
RaptorInputObjectGraphDefinitionBuilder(
kotlinType = KotlinType.of(
type = type,
containingType = null,
allowMaybe = false,
allowNull = false,
allowedVariance = KVariance.OUT, // TODO prb. wrong
requireSpecialization = false
),
name = RaptorGraphDefinition.resolveName(name, type = type),
stackTrace = stackTrace(skipCount = 1)
)
.apply(configure)
.build()
@RaptorDsl
public inline fun graphInterfaceDefinition(
name: String = RaptorGraphDefinition.defaultName,
noinline configure: RaptorInterfaceGraphDefinitionBuilder.() -> Unit,
): RaptorGraphDefinition =
graphInterfaceDefinition(
name = name,
type = typeOf(),
configure = configure
)
@RaptorDsl
public fun graphInterfaceDefinition(
name: String = RaptorGraphDefinition.defaultName,
type: KType,
configure: RaptorInterfaceGraphDefinitionBuilder.() -> Unit,
): RaptorGraphDefinition =
RaptorInterfaceGraphDefinitionBuilder(
kotlinType = KotlinType.of(
type = type,
containingType = null,
allowMaybe = false,
allowNull = false,
allowedVariance = KVariance.OUT, // TODO prb. wrong
requireSpecialization = false
),
name = RaptorGraphDefinition.resolveName(name, type = type),
stackTrace = stackTrace(skipCount = 1)
)
.apply(configure)
.build()
@RaptorDsl
public inline fun graphInterfaceExtensionDefinition(
@BuilderInference noinline configure: RaptorInterfaceExtensionGraphDefinitionBuilder.() -> Unit,
): RaptorGraphDefinition =
graphInterfaceExtensionDefinition(
type = typeOf(),
configure = configure
)
@RaptorDsl
public fun graphInterfaceExtensionDefinition(
type: KType,
configure: RaptorInterfaceExtensionGraphDefinitionBuilder.() -> Unit,
): RaptorGraphDefinition =
RaptorInterfaceExtensionGraphDefinitionBuilder(
kotlinType = KotlinType.of(
type = type,
containingType = null,
allowMaybe = false,
allowNull = false,
allowedVariance = KVariance.OUT, // TODO prb. wrong
requireSpecialization = false
),
stackTrace = stackTrace(skipCount = 1)
)
.apply(configure)
.build()
// TODO put all dsl behind an object for grouping & reuse in nested{} blocks
@RaptorDsl
public inline fun graphObjectDefinition(
name: String = RaptorGraphDefinition.defaultName,
@BuilderInference noinline configure: RaptorObjectGraphDefinitionBuilder.() -> Unit = {},
): RaptorGraphDefinition =
graphObjectDefinition(
name = name,
type = typeOf(),
configure = configure
)
@RaptorDsl
public fun graphObjectDefinition(
name: String = RaptorGraphDefinition.defaultName,
type: KType,
configure: RaptorObjectGraphDefinitionBuilder.() -> Unit = {},
): RaptorGraphDefinition =
RaptorObjectGraphDefinitionBuilder(
kotlinType = KotlinType.of(
type = type,
containingType = null,
allowMaybe = false,
allowNull = false,
allowedVariance = KVariance.OUT, // TODO prb. wrong
requireSpecialization = false
),
name = RaptorGraphDefinition.resolveName(name, type = type),
stackTrace = stackTrace(skipCount = 1)
)
.apply(configure)
.build()
@RaptorDsl
public inline fun graphObjectExtensionDefinition(
@BuilderInference noinline configure: RaptorObjectExtensionGraphDefinitionBuilder.() -> Unit,
): RaptorGraphDefinition =
graphObjectExtensionDefinition(
type = typeOf(),
configure = configure
)
@RaptorDsl
public fun graphObjectExtensionDefinition(
type: KType,
configure: RaptorObjectExtensionGraphDefinitionBuilder.() -> Unit,
): RaptorGraphDefinition =
RaptorObjectExtensionGraphDefinitionBuilder(
kotlinType = KotlinType.of(
type = type,
containingType = null,
allowMaybe = false,
allowNull = false,
allowedVariance = KVariance.OUT, // TODO prb. wrong
requireSpecialization = false
),
stackTrace = stackTrace(skipCount = 1)
)
.apply(configure)
.build()
@RaptorDsl
public inline fun graphOperationDefinition(
name: String,
operationType: RaptorGraphOperationType,
@BuilderInference noinline configure: RaptorGraphOperationDefinitionBuilder.() -> Unit,
): RaptorGraphDefinition =
graphOperationDefinition(
name = name,
operationType = operationType,
type = typeOf(),
configure = configure
)
@RaptorDsl
public fun graphOperationDefinition(
name: String,
type: KType,
operationType: RaptorGraphOperationType,
configure: RaptorGraphOperationDefinitionBuilder.() -> Unit,
): RaptorGraphDefinition =
RaptorGraphOperationDefinitionBuilder(
additionalDefinitions = emptyList(),
kotlinType = KotlinType.of(
type = type,
containingType = null,
allowMaybe = false,
allowNull = true,
allowedVariance = KVariance.OUT,
requireSpecialization = true
),
name = name,
operationType = operationType,
stackTrace = stackTrace(skipCount = 1)
)
.apply(configure)
.build()
@RaptorDsl
public inline fun graphScalarDefinition(
name: String = RaptorGraphDefinition.defaultName,
@BuilderInference noinline configure: RaptorScalarGraphDefinitionBuilder.() -> Unit,
): RaptorGraphDefinition =
graphScalarDefinition(
name = name,
type = typeOf(),
configure = configure
)
@RaptorDsl
public fun graphScalarDefinition(
name: String = RaptorGraphDefinition.defaultName,
type: KType,
configure: RaptorScalarGraphDefinitionBuilder.() -> Unit,
): RaptorGraphDefinition =
RaptorScalarGraphDefinitionBuilder(
kotlinType = KotlinType.of(
type = type,
containingType = null,
allowMaybe = false,
allowNull = false,
allowedVariance = KVariance.OUT, // TODO prb. wrong
requireSpecialization = false
),
name = RaptorGraphDefinition.resolveName(name, type = type),
stackTrace = stackTrace(skipCount = 1)
)
.apply(configure)
.build()
@RaptorDsl
public inline fun graphUnionDefinition(
name: String = RaptorGraphDefinition.defaultName,
@BuilderInference noinline configure: RaptorUnionGraphDefinitionBuilder.() -> Unit = {},
): RaptorGraphDefinition =
graphUnionDefinition(
name = name,
type = typeOf(),
configure = configure
)
@RaptorDsl
public fun graphUnionDefinition(
name: String = RaptorGraphDefinition.defaultName,
type: KType,
configure: RaptorUnionGraphDefinitionBuilder.() -> Unit = {},
): RaptorGraphDefinition =
RaptorUnionGraphDefinitionBuilder(
kotlinType = KotlinType.of(
type = type,
containingType = null,
allowMaybe = false,
allowNull = false,
allowedVariance = KVariance.OUT, // TODO prb. wrong
requireSpecialization = false
),
name = RaptorGraphDefinition.resolveName(name, type = type),
stackTrace = stackTrace(skipCount = 1)
)
.apply(configure)
.build()