@@ -5,10 +5,14 @@ import com.expedia.graphql.exceptions.CouldNotCastArgumentException
55import graphql.schema.DataFetchingEnvironment
66import io.mockk.every
77import io.mockk.mockk
8+ import kotlinx.coroutines.coroutineScope
9+ import kotlinx.coroutines.delay
810import org.junit.jupiter.api.Test
11+ import java.util.concurrent.CompletableFuture
912import kotlin.test.assertEquals
1013import kotlin.test.assertFailsWith
1114import kotlin.test.assertNull
15+ import kotlin.test.assertTrue
1216
1317internal class FunctionDataFetcherTest {
1418
@@ -22,6 +26,11 @@ internal class FunctionDataFetcherTest {
2226 fun context (@GraphQLContext string : String ) = string
2327
2428 fun dataFetchingEnvironment (environment : DataFetchingEnvironment ) = environment.field.name
29+
30+ suspend fun suspendPrint (string : String ): String = coroutineScope {
31+ delay(10 )
32+ string
33+ }
2534 }
2635
2736 @Test
@@ -105,4 +114,16 @@ internal class FunctionDataFetcherTest {
105114 }
106115 assertEquals(expected = " fooBarBaz" , actual = dataFetcher.get(mockEnvironmet))
107116 }
117+
118+ @Test
119+ fun `suspend functions return value wrapped in CompletableFuture` () {
120+ val dataFetcher = FunctionDataFetcher (target = MyClass (), fn = MyClass ::suspendPrint)
121+ val mockEnvironmet: DataFetchingEnvironment = mockk()
122+ every { mockEnvironmet.arguments } returns mapOf (" string" to " hello" )
123+
124+ val result = dataFetcher.get(mockEnvironmet)
125+
126+ assertTrue(result is CompletableFuture <* >)
127+ assertEquals(expected = " hello" , actual = result.get())
128+ }
108129}
0 commit comments