@@ -5,10 +5,14 @@ import com.expedia.graphql.exceptions.CouldNotCastArgumentException
5
5
import graphql.schema.DataFetchingEnvironment
6
6
import io.mockk.every
7
7
import io.mockk.mockk
8
+ import kotlinx.coroutines.coroutineScope
9
+ import kotlinx.coroutines.delay
8
10
import org.junit.jupiter.api.Test
11
+ import java.util.concurrent.CompletableFuture
9
12
import kotlin.test.assertEquals
10
13
import kotlin.test.assertFailsWith
11
14
import kotlin.test.assertNull
15
+ import kotlin.test.assertTrue
12
16
13
17
internal class FunctionDataFetcherTest {
14
18
@@ -22,6 +26,11 @@ internal class FunctionDataFetcherTest {
22
26
fun context (@GraphQLContext string : String ) = string
23
27
24
28
fun dataFetchingEnvironment (environment : DataFetchingEnvironment ) = environment.field.name
29
+
30
+ suspend fun suspendPrint (string : String ): String = coroutineScope {
31
+ delay(10 )
32
+ string
33
+ }
25
34
}
26
35
27
36
@Test
@@ -105,4 +114,16 @@ internal class FunctionDataFetcherTest {
105
114
}
106
115
assertEquals(expected = " fooBarBaz" , actual = dataFetcher.get(mockEnvironmet))
107
116
}
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
+ }
108
129
}
0 commit comments