diff --git a/src/main/kotlin/com/github/pgutkowski/kgraphql/schema/dsl/InputValueDSL.kt b/src/main/kotlin/com/github/pgutkowski/kgraphql/schema/dsl/InputValueDSL.kt index ed64cb2b..0f278a3d 100644 --- a/src/main/kotlin/com/github/pgutkowski/kgraphql/schema/dsl/InputValueDSL.kt +++ b/src/main/kotlin/com/github/pgutkowski/kgraphql/schema/dsl/InputValueDSL.kt @@ -15,6 +15,11 @@ class InputValueDSL(val kClass: KClass, block : InputValueDSL.() var defaultValue : T? = null fun toKQLInputValue() : InputValueDef = InputValueDef( - kClass, name, defaultValue, isDeprecated, deprecationReason, description + kClass = kClass, + name = name, + defaultValue = defaultValue, + isDeprecated = isDeprecated, + description = description, + deprecationReason = deprecationReason ) } \ No newline at end of file diff --git a/src/main/kotlin/com/github/pgutkowski/kgraphql/schema/dsl/KotlinPropertyDSL.kt b/src/main/kotlin/com/github/pgutkowski/kgraphql/schema/dsl/KotlinPropertyDSL.kt index daa23a39..b86b8416 100644 --- a/src/main/kotlin/com/github/pgutkowski/kgraphql/schema/dsl/KotlinPropertyDSL.kt +++ b/src/main/kotlin/com/github/pgutkowski/kgraphql/schema/dsl/KotlinPropertyDSL.kt @@ -12,7 +12,11 @@ class KotlinPropertyDSL(val kProperty: KProperty1, block : KotlinProper block() } - fun toKQLProperty(): PropertyDef.Kotlin { - return PropertyDef.Kotlin(kProperty, description, isDeprecated, deprecationReason, ignore) - } + fun toKQLProperty() = PropertyDef.Kotlin ( + kProperty = kProperty, + description = description, + isDeprecated = isDeprecated, + deprecationReason = deprecationReason, + isIgnored = ignore + ) } \ No newline at end of file diff --git a/src/main/kotlin/com/github/pgutkowski/kgraphql/schema/dsl/PropertyDSL.kt b/src/main/kotlin/com/github/pgutkowski/kgraphql/schema/dsl/PropertyDSL.kt index c3dd2242..d9f9a502 100644 --- a/src/main/kotlin/com/github/pgutkowski/kgraphql/schema/dsl/PropertyDSL.kt +++ b/src/main/kotlin/com/github/pgutkowski/kgraphql/schema/dsl/PropertyDSL.kt @@ -28,16 +28,14 @@ class PropertyDSL(val name : String, block : PropertyDSL.() -> U fun resolver(function: (T, E, W, Q) -> R) = resolver(FunctionWrapper.on(function, true)) - fun toKQL(): PropertyDef.Function { - 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>) { this.inputValues.addAll(inputValues) diff --git a/src/main/kotlin/com/github/pgutkowski/kgraphql/schema/dsl/QueryOrMutationDSL.kt b/src/main/kotlin/com/github/pgutkowski/kgraphql/schema/dsl/QueryOrMutationDSL.kt index bac74b16..327a7227 100644 --- a/src/main/kotlin/com/github/pgutkowski/kgraphql/schema/dsl/QueryOrMutationDSL.kt +++ b/src/main/kotlin/com/github/pgutkowski/kgraphql/schema/dsl/QueryOrMutationDSL.kt @@ -36,11 +36,21 @@ class QueryOrMutationDSL(val name : String, block : QueryOrMutationDSL.() -> Uni this.inputValues.addAll(inputValues) } - internal fun toKQLQuery(): QueryDef { - return QueryDef(name, functionWrapper, description, isDeprecated, deprecationReason, inputValues) - } - - internal fun toKQLMutation(): MutationDef { - 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 + ) } \ No newline at end of file diff --git a/src/main/kotlin/com/github/pgutkowski/kgraphql/schema/dsl/SchemaBuilder.kt b/src/main/kotlin/com/github/pgutkowski/kgraphql/schema/dsl/SchemaBuilder.kt index b422635d..2bc1dd89 100644 --- a/src/main/kotlin/com/github/pgutkowski/kgraphql/schema/dsl/SchemaBuilder.kt +++ b/src/main/kotlin/com/github/pgutkowski/kgraphql/schema/dsl/SchemaBuilder.kt @@ -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) } diff --git a/src/main/kotlin/com/github/pgutkowski/kgraphql/schema/dsl/TypeDSL.kt b/src/main/kotlin/com/github/pgutkowski/kgraphql/schema/dsl/TypeDSL.kt index 16664813..89617ed2 100644 --- a/src/main/kotlin/com/github/pgutkowski/kgraphql/schema/dsl/TypeDSL.kt +++ b/src/main/kotlin/com/github/pgutkowski/kgraphql/schema/dsl/TypeDSL.kt @@ -41,7 +41,7 @@ open class TypeDSL(private val supportedUnions: Collection property(name : String, block : PropertyDSL.() -> Unit){ val dsl = PropertyDSL(name, block) - extensionProperties.add(dsl.toKQL()) + extensionProperties.add(dsl.toKQLProperty()) } fun KProperty1.configure(block : KotlinPropertyDSL.() -> Unit){ @@ -57,7 +57,7 @@ open class TypeDSL(private val supportedUnions: Collection(val name : String, block: UnionPropertyDSL.() -> Un fun 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>) { this.inputValues.addAll(inputValues) diff --git a/src/test/kotlin/com/github/pgutkowski/kgraphql/schema/SchemaBuilderTest.kt b/src/test/kotlin/com/github/pgutkowski/kgraphql/schema/SchemaBuilderTest.kt index 7d0eddf6..67962185 100644 --- a/src/test/kotlin/com/github/pgutkowski/kgraphql/schema/SchemaBuilderTest.kt +++ b/src/test/kotlin/com/github/pgutkowski/kgraphql/schema/SchemaBuilderTest.kt @@ -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 { name = "int"; defaultValue = 33 } + arg { 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("data/data"), equalTo(33)) + + val introspection = deserialize(schema.execute("{__schema{queryType{fields{name, args{name, description, defaultValue}}}}}")) + assertThat(introspection.extract("data/__schema/queryType/fields[0]/args[0]/description"), equalTo(expectedDescription)) } @Test