Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ class InputValueDSL<T : Any>(val kClass: KClass<T>, block : InputValueDSL<T>.()
var defaultValue : T? = null

fun toKQLInputValue() : InputValueDef<T> = InputValueDef(
kClass, name, defaultValue, isDeprecated, deprecationReason, description
kClass = kClass,
name = name,
defaultValue = defaultValue,
isDeprecated = isDeprecated,
description = description,
deprecationReason = deprecationReason
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ class KotlinPropertyDSL<T>(val kProperty: KProperty1<T, *>, block : KotlinProper
block()
}

fun toKQLProperty(): PropertyDef.Kotlin<T, Any?> {
return PropertyDef.Kotlin(kProperty, description, isDeprecated, deprecationReason, ignore)
}
fun toKQLProperty() = PropertyDef.Kotlin (
kProperty = kProperty,
description = description,
isDeprecated = isDeprecated,
deprecationReason = deprecationReason,
isIgnored = ignore
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@ class PropertyDSL<out T, R>(val name : String, block : PropertyDSL<T, R>.() -> U

fun <E, W, Q>resolver(function: (T, E, W, Q) -> R) = resolver(FunctionWrapper.on(function, true))

fun toKQL(): PropertyDef.Function<R> {
return PropertyDef.Function(
name,
functionWrapper,
description,
isDeprecated,
deprecationReason,
inputValues
)
}
fun toKQLProperty() = PropertyDef.Function(
name = name,
resolver = functionWrapper,
description = description,
isDeprecated = isDeprecated,
deprecationReason = deprecationReason,
inputValues = inputValues
)

override fun addInputValues(inputValues: Collection<InputValueDef<*>>) {
this.inputValues.addAll(inputValues)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,21 @@ class QueryOrMutationDSL(val name : String, block : QueryOrMutationDSL.() -> Uni
this.inputValues.addAll(inputValues)
}

internal fun toKQLQuery(): QueryDef<out Any?> {
return QueryDef(name, functionWrapper, description, isDeprecated, deprecationReason, inputValues)
}

internal fun toKQLMutation(): MutationDef<out Any?> {
return MutationDef(name, functionWrapper, description, isDeprecated, deprecationReason, inputValues)
}
internal fun toKQLQuery() = QueryDef (
name = name,
resolver = functionWrapper,
description = description,
isDeprecated = isDeprecated,
deprecationReason = deprecationReason,
inputValues = inputValues
)

internal fun toKQLMutation() = MutationDef(
name = name,
resolver = functionWrapper,
description = description,
isDeprecated = isDeprecated,
deprecationReason = deprecationReason,
inputValues = inputValues
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ class SchemaBuilder(private val init: SchemaBuilder.() -> Unit) {

val kqlEnumValues = enumValues.map { value ->
type.valueDefinitions[value]?.let { valueDSL ->
EnumValueDef(value, valueDSL.description, valueDSL.isDeprecated, valueDSL.deprecationReason)
EnumValueDef (
value = value,
description = valueDSL.description,
isDeprecated = valueDSL.isDeprecated,
deprecationReason = valueDSL.deprecationReason
)
} ?: EnumValueDef(value)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ open class TypeDSL<T : Any>(private val supportedUnions: Collection<TypeDef.Unio

fun <R> property(name : String, block : PropertyDSL<T, R>.() -> Unit){
val dsl = PropertyDSL(name, block)
extensionProperties.add(dsl.toKQL())
extensionProperties.add(dsl.toKQLProperty())
}

fun <R> KProperty1<T, R>.configure(block : KotlinPropertyDSL<T>.() -> Unit){
Expand All @@ -57,7 +57,7 @@ open class TypeDSL<T : Any>(private val supportedUnions: Collection<TypeDef.Unio
val union = supportedUnions.find { property.returnType.typeID.equals(it.name, true) }
?: throw SchemaException("Union Type: ${property.returnType.typeID} does not exist")

unionProperties.add(property.toKQL(union))
unionProperties.add(property.toKQLProperty(union))
}

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,15 @@ class UnionPropertyDSL<T>(val name : String, block: UnionPropertyDSL<T>.() -> Un

fun <E, W, Q>resolver(function: (T, E, W, Q) -> Any?) = resolver(FunctionWrapper.on(function, true))

fun toKQL(union : TypeDef.Union): PropertyDef.Union {
return PropertyDef.Union (
name = name,
resolver = functionWrapper,
union = union,
description = description,
isDeprecated = isDeprecated,
deprecationReason = deprecationReason,
inputValues = inputValues
)
}
fun toKQLProperty(union : TypeDef.Union) = PropertyDef.Union (
name = name,
resolver = functionWrapper,
union = union,
description = description,
isDeprecated = isDeprecated,
deprecationReason = deprecationReason,
inputValues = inputValues
)

override fun addInputValues(inputValues: Collection<InputValueDef<*>>) {
this.inputValues.addAll(inputValues)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,20 +251,26 @@ class SchemaBuilderTest {
}

@Test
fun `input value default value can be specified`(){
fun `input value default value and description can be specified`(){
val expectedDescription = "Int Argument"
val expectedDefaultValue = 33
val schema = defaultSchema {
query("data"){
resolver { int: Int -> int }.withArgs {
arg <Int> { name = "int"; defaultValue = 33 }
arg <Int> { name = "int"; defaultValue = expectedDefaultValue; description = expectedDescription }
}
}
}

val intArg = schema.queryType.fields?.find { it.name == "data" }?.args?.find { it.name == "int" }
assertThat(intArg?.defaultValue, equalTo("33"))
assertThat(intArg?.defaultValue, equalTo(expectedDefaultValue.toString()))
assertThat(intArg?.description, equalTo(expectedDescription))

val response = deserialize(schema.execute("{data}"))
assertThat(response.extract<Int>("data/data"), equalTo(33))

val introspection = deserialize(schema.execute("{__schema{queryType{fields{name, args{name, description, defaultValue}}}}}"))
assertThat(introspection.extract<String>("data/__schema/queryType/fields[0]/args[0]/description"), equalTo(expectedDescription))
}

@Test
Expand Down