diff --git a/build.gradle b/build.gradle index 753d643c..bef250c3 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'com.github.pgutkowski' -version '0.3.0' +version '0.3.1' buildscript { ext.kotlin_version = '1.3.0' 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 b9bbbd3d..7c6740bd 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 @@ -4,7 +4,6 @@ import com.github.pgutkowski.kgraphql.Context import com.github.pgutkowski.kgraphql.schema.model.FunctionWrapper import com.github.pgutkowski.kgraphql.schema.model.InputValueDef import com.github.pgutkowski.kgraphql.schema.model.PropertyDef -import java.lang.IllegalArgumentException class PropertyDSL(val name : String, block : PropertyDSL.() -> Unit) : LimitedAccessItemDSL(), ResolverDSL.Target { @@ -40,6 +39,24 @@ class PropertyDSL(val name : String, block : PropertyDSL.() -> fun resolver(function: (T, E, W, Q, A, S) -> R) = resolver(FunctionWrapper.on(function, true)) + fun suspendResolver(function: suspend (T) -> R) + = resolver(FunctionWrapper.onSuspend(function, true)) + + fun suspendResolver(function: suspend (T, E) -> R) + = resolver(FunctionWrapper.onSuspend(function, true)) + + fun suspendResolver(function: suspend (T, E, W) -> R) + = resolver(FunctionWrapper.onSuspend(function, true)) + + fun suspendResolver(function: suspend (T, E, W, Q) -> R) = + resolver(FunctionWrapper.onSuspend(function, true)) + + fun suspendResolver(function: suspend (T, E, W, Q, A) -> R) = + resolver(FunctionWrapper.onSuspend(function, true)) + + fun suspendResolver(function: suspend (T, E, W, Q, A, S) -> R) = + resolver(FunctionWrapper.onSuspend(function, true)) + fun accessRule(rule: (T, Context) -> Exception?){ val accessRuleAdapter: (T?, Context) -> Exception? = { parent, ctx -> diff --git a/src/test/kotlin/com/github/pgutkowski/kgraphql/specification/language/ArgumentsSpecificationTest.kt b/src/test/kotlin/com/github/pgutkowski/kgraphql/specification/language/ArgumentsSpecificationTest.kt index bab1585e..810cedc6 100644 --- a/src/test/kotlin/com/github/pgutkowski/kgraphql/specification/language/ArgumentsSpecificationTest.kt +++ b/src/test/kotlin/com/github/pgutkowski/kgraphql/specification/language/ArgumentsSpecificationTest.kt @@ -1,10 +1,7 @@ package com.github.pgutkowski.kgraphql.specification.language -import com.github.pgutkowski.kgraphql.Actor -import com.github.pgutkowski.kgraphql.Specification -import com.github.pgutkowski.kgraphql.defaultSchema -import com.github.pgutkowski.kgraphql.deserialize -import com.github.pgutkowski.kgraphql.executeEqualQueries +import com.github.pgutkowski.kgraphql.* +import kotlinx.coroutines.delay import org.hamcrest.CoreMatchers.equalTo import org.hamcrest.MatcherAssert.assertThat import org.junit.Test @@ -30,6 +27,14 @@ class ArgumentsSpecificationTest { }.take(size) } } + repeat(1000) { num -> + property("automated-$num") { + suspendResolver { + delay(3) + num + } + } + } } } @@ -50,5 +55,17 @@ class ArgumentsSpecificationTest { ) } + @Test + fun `suspendable resolvers`() { + val query = "{ actor { " + (0..999).joinToString(", ") { "automated-$it" } + " } }" + + val map = deserialize(schema.execute(query)) + assertThat(map.extract("data/actor/automated-0"), equalTo(0)) + assertThat(map.extract("data/actor/automated-271"), equalTo(271)) + assertThat(map.extract("data/actor/automated-314"), equalTo(314)) + assertThat(map.extract("data/actor/automated-500"), equalTo(500)) + assertThat(map.extract("data/actor/automated-999"), equalTo(999)) + } + }